【问题标题】:RuboCop - [AllCops -> Exclude] not working in GitHub ActionsRuboCop - [AllCops -> Exclude] 在 GitHub Actions 中不起作用
【发布时间】:2022-08-10 06:15:06
【问题描述】:

RuboCop AllCops->Exclude 规则在使用 GitHub Actions 时不起作用。

它似乎进入了一个递归循环

我有一个简单的 GEM,它使用带有基本配置的 RuboCop。

AllCops:
  TargetRubyVersion: 2.7
  NewCops: enable

Style/StringLiterals:
  Enabled: true
  EnforcedStyle: double_quotes

Style/StringLiteralsInInterpolation:
  Enabled: true
  EnforcedStyle: double_quotes

Layout/LineLength:
  Max: 120

我需要禁用两个文件夹中的警察规则。

AllCops:
  TargetRubyVersion: 2.7
  NewCops: enable
  Exclude:
    - \".builders/**/*\"
    - \"spec/samples/**/*\"

WORKS :) 使用排除的文件在本地运行 Rubocop:

使用 GitHub 操作

工作 :) 在没有 AllCops->Exclude 的情况下运行 RuboCop

GHA k_director/runs/4909797149

失败 :( 运行 RuboCop 唱歌AllCops->Exclude

GHA k_director/runs/4909833222

我在将近 8 分钟的时候取消了工作流程

此操作似乎进入了深度树遍历并锁定了我的 GitHub 操作。

这是日志中 1800 行的一些错误

RuboCop 的 GitHub Action 工作流程

name: Build Application

on:
  push:
    branches: [ main ]

jobs:
  test:
    runs-on: ubuntu-latest
    name: Ruby ${{ matrix.ruby }}
    strategy:
      matrix:
        ruby: [\'2.7.1\']

    steps:
    - uses: actions/checkout@v2
    - name: Set up Ruby
      uses: ruby/setup-ruby@v1
      with:
        ruby-version: ${{ matrix.ruby }}
        bundler-cache: true

    - name: Run rubocop
      run: bundle exec rubocop

    标签: github-actions rubocop


    【解决方案1】:

    我首先尝试将供应商目录放入排除项。

    AllCops:
      Exclude:
        - 'vendor/**/*'
    

    我在这里找到了答案:How to Setup RuboCop in GitHub Actions

    这对我有用,但@AndyWait 将我指向文档中的一个部分,我当前的工作解决方案是添加以下内容,这会将我的新排除项与 rubocop->default.yml 中的排除项合并

    inherit_mode:
      merge:
        - Exclude
    

    此外,配置继承自“.rubocop.yml”文件,位于文件夹层次结构的上层,即父文件夹。

    如果您想避免在 rubocop 运行时包含这些配置文件,请传入配置所需的特定 .rubocop.yml 文件,并使用 inherit_from: ../.some_other_rubocop.yml 选项让它根据需要引用其他文件。

    rubocop --config .rubocop.yml
    

    【讨论】:

      【解决方案2】:

      RuboCop 默认已经排除了vendor/**/*

      https://github.com/rubocop/rubocop/blob/77b54824b74db4d36268fdadd6aed9b925ff9f11/config/default.yml#L66

      但是您的配置正在覆盖它。为避免这种情况,您可以指定您的配置应该从默认继承,并与您的添加合并:

      https://docs.rubocop.org/rubocop/configuration.html#merging-arrays-using-inherit_mode

      【讨论】:

      • 谢谢安迪,不幸的是,文档并不清楚如何从 default.yml 继承,我确实阅读了本节,将以下内容放入我的代码中,它解决了我的问题,但我发现这个解决方案(和文档)不够清晰,我'想知道它是否应该更新。继承模式:合并:- 排除
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-02
      • 2022-06-10
      • 1970-01-01
      • 2020-07-09
      • 1970-01-01
      • 2022-08-04
      • 2017-10-30
      相关资源
      最近更新 更多