Search code examples
github-actionsrubocop

How to setup Rubocop in Github Actions


I have project and currently rubocop checks pass (I have rubocop_todo.yml). I'm trying to setup linter stage in Github Actions by myself (without third-party actions to run rubocop, that already exist) and for some reason rubocop does not pass there:

The following cops were added to RuboCop, but are not configured. Please set Enabled to either `true` or `false` in your `.rubocop.yml` file.

Please also note that you can opt-in to new cops by default by adding this to your config:
  AllCops:
    NewCops: enable
Gemspec/DateAssignment: # new in 1.10
  Enabled: true
Layout/LineEndStringConcatenationIndentation: # new in 1.18
  Enabled: true
Layout/SpaceBeforeBrackets: # new in 1.7
  Enabled: true
Lint/AmbiguousAssignment: # new in 1.7
  Enabled: true
Lint/AmbiguousOperatorPrecedence: # new in 1.21
  Enabled: true
Lint/AmbiguousRange: # new in 1.19
  Enabled: true
Performance/SortReverse: # new in 1.7
  Enabled: true
Performance/Squeeze: # new in 1.7
  Enabled: true
Performance/StringInclude: # new in 1.7
  Enabled: true
Performance/Sum: # new in 1.8
  Enabled: true
Rails/ActiveRecordCallbacksOrder: # new in 2.7
  Enabled: true
Rails/AddColumnIndex: # new in 2.11
  Enabled: true
Rails/AfterCommitOverride: # new in 2.8
  Enabled: true
Rails/AttributeDefaultBlockValue: # new in 2.9
  Enabled: true
Rails/EagerEvaluationLogMessage: # new in 2.11
  Enabled: true
Rails/ExpandedDateRange: # new in 2.11
  Enabled: true
Rails/FindById: # new in 2.7
  Enabled: true
Rails/I18nLocaleAssignment: # new in 2.11
  Enabled: true
Rails/Inquiry: # new in 2.7
  Enabled: true
Rails/MailerName: # new in 2.7
  Enabled: true
Rails/MatchRoute: # new in 2.7
  Enabled: true
Rails/NegateInclude: # new in 2.7
  Enabled: true
Rails/Pluck: # new in 2.7
  Enabled: true
Rails/PluckInWhere: # new in 2.7
  Enabled: true
Rails/RedundantTravelBack: # new in 2.12
  Enabled: true
Rails/RenderInline: # new in 2.7
  Enabled: true
Rails/RenderPlainText: # new in 2.7
  Enabled: true
Rails/ShortI18n: # new in 2.7
  Enabled: true
Rails/SquishedSQLHeredocs: # new in 2.8
  Enabled: true
Rails/TimeZoneAssignment: # new in 2.10
  Enabled: true
Rails/UnusedIgnoredColumns: # new in 2.11
  Enabled: true
Rails/WhereEquals: # new in 2.9
  Enabled: true
Rails/WhereExists: # new in 2.7
  Enabled: true
Rails/WhereNot: # new in 2.8
  Enabled: true
RSpec/ExcessiveDocstringSpacing: # new in 2.5
  Enabled: true
RSpec/IdenticalEqualityAssertion: # new in 2.4
  Enabled: true
RSpec/SubjectDeclaration: # new in 2.5
  Enabled: true
RSpec/Rails/AvoidSetupHook: # new in 2.4
  Enabled: true
For more information: https://docs.rubocop.org/rubocop/versioning.html
vendor/bundle/ruby/2.7.0/bundler/gems/cbr-42bd88bec0e7/.rubocop.yml: Metrics/LineLength has the wrong namespace - should be Layout
/home/runner/work/izi-ndfl/izi-ndfl/vendor/bundle/ruby/2.7.0/bundler/gems/cbr-42bd88bec0e7/.rubocop.yml: Warning: no department given for Documentation.
Error: obsolete parameter `RunRailsCops` (for `AllCops`) found in vendor/bundle/ruby/2.7.0/bundler/gems/cbr-42bd88bec0e7/.rubocop.yml
Use the following configuration instead:
Rails:
  Enabled: true
Error: Process completed with exit code 2.

It looks like it reads wrong config, because I have AllCops setting in my .rubocop.yml

AllCops:
  NewCops: enable

Here is my config for GA:

.github/workflows/rubocop.yml

name: Rubocop

on: [pull_request]
jobs:
  rubocop:
    runs-on: ubuntu-latest

    steps:
      - uses: actions/checkout@v2
      - name: Set up Ruby
        uses: ruby/setup-ruby@v1
        with:
          bundler-cache: true
      - name: Run rubocop
        run: |
          bundle exec rubocop

Solution

  • Looks like it's reading the .rubocop.yml from one of your gems in the vendor/ directory. Try this:

    AllCops:
      NewCops: enable
      Exclude:
      - 'vendor/'