Rubocop:如何从指标中排除文件名模式?

tec*_*raf 4 rubocop

我想*_spec.rb在 Rubocop 中全局禁用文件名匹配(Serverspec 文件)的行长度检查。

我尝试通过以下方式添加Exclude,config/default.yml但它不起作用(没有错误,检测到违规):

Metrics/LineLength:
  Max: 80
  AllowHeredoc: true
  AllowURI: true
  URISchemes:
    - http
    - https
  Exclude:
    - '*_spec.rb'
Run Code Online (Sandbox Code Playgroud)

如果可能的话,应该在哪里/如何配置?

Dre*_*nmi 5

您可以使用声明基于正则表达式来匹配文件!ruby/regexp:

Metrics/LineLength:
  Max: 80
  AllowHeredoc: true
  AllowURI: true
  URISchemes:
    - http
    - https
  Exclude:
    - !ruby/regexp /_spec\.rb$/
Run Code Online (Sandbox Code Playgroud)

RuboCop 最近添加了一本新手册,您可以在此处阅读有关包含和排除文件的信息。