【问题标题】:How to setup Rubocop in Github Actions如何在 Github Actions 中设置 Rubocop
【发布时间】:2021-11-07 08:56:44
【问题描述】:

我有项目并且目前 rubocop 检查通过(我有 rubocop_todo.yml)。我正在尝试自己在 Github Actions 中设置 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

【问题讨论】:

    标签: github-actions rubocop


    【解决方案1】:

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

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

    【讨论】:

    • 谢谢,有帮助!但排除路径应如下所示: - 'vendor/**/*'
    猜你喜欢
    • 2020-01-01
    • 2022-08-10
    • 2020-11-13
    • 2020-01-14
    • 2022-11-06
    • 2020-10-03
    • 1970-01-01
    • 1970-01-01
    • 2020-12-04
    相关资源
    最近更新 更多