如何在 Github 动作中设置 Rubocop

How to setup Rubocop in Github Actions

我有项目,目前 rubocop 检查通过(我有 rubocop_todo.yml)。我正在尝试自己在 Github 操作中设置 linter 阶段(没有对 运行 rubocop 的第三方操作,它已经存在)并且由于某种原因 rubocop 没有通过那里:

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.

它似乎读取了错误的配置,因为我在 .rubocop.yml

中设置了 AllCops
AllCops:
  NewCops: enable

这是我的 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

看起来它正在从 vendor/ 目录中的一个 gem 中读取 .rubocop.yml。试试这个:

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