Skip
Arish's avatar

8. RuboCop Linting


RuboCop in CI

yaml
1jobs:
2  lint:
3    runs-on: ubuntu-latest
4    
5    steps:
6      - uses: actions/checkout@v4
7      
8      - uses: ruby/setup-ruby@v1
9        with:
10          ruby-version: '3.2'
11          bundler-cache: true
12      
13      - name: Run RuboCop
14        run: bundle exec rubocop --parallel

RuboCop Configuration

yaml
1# .rubocop.yml
2require:
3  - rubocop-rails
4  - rubocop-rspec
5  - rubocop-performance
6
7AllCops:
8  NewCops: enable
9  TargetRubyVersion: 3.2
10  Exclude:
11    - 'db/**/*'
12    - 'bin/**/*'
13    - 'vendor/**/*'
14    - 'node_modules/**/*'
15
16Style/Documentation:
17  Enabled: false
18
19Metrics/BlockLength:
20  Exclude:
21    - 'spec/**/*'
22    - 'config/routes.rb'

Auto-Correction

yaml
1- name: Run RuboCop with auto-correct
2  run: |
3    bundle exec rubocop -A
4    git diff --exit-code || (echo "RuboCop made changes" && exit 1)

Reviewdog Integration

yaml
1- uses: reviewdog/action-rubocop@v2
2  with:
3    github_token: ${{ secrets.GITHUB_TOKEN }}
4    reporter: github-pr-review