ruby 如何告诉 Rubocop 忽略特定目录或文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/36896279/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 06:49:18  来源:igfitidea点击:

How to tell Rubocop to ignore a specific directory or file

rubyrubocop

提问by emery

My project is extending open-source classes from a third-party gem that we don't want to hold to the same coding standards as our own code. Refactoring the gem code isn't a viable option. We just want Rubocop to ignore the copied code.

我的项目是从第三方 gem 扩展开源类,我们不想与我们自己的代码保持相同的编码标准。重构 gem 代码不是一个可行的选择。我们只希望 Rubocop 忽略复制的代码。

How can I instruct Rubocop to completely ignore a file or directory?

如何指示 Rubocop 完全忽略文件或目录?

回答by emery

As per orde's comment with the link to the manualI found .rubocop.yml and added the following:

根据orde对手册链接的评论,我找到了 .rubocop.yml 并添加了以下内容:

AllCops:
  Exclude:
    - 'path/to/excluded/file.rb'

where the path is relative to .rubocop.yml

路径相对于 .rubocop.yml

回答by Dorian

From rubocop/default.yml:

来自rubocop/default.yml

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

回答by DennyZhang

For your convenience, here is the .rubocop.yml I frequently used.

为方便起见,这里是我经常使用的 .rubocop.yml。

See formal explanation of .rubocop.yml here.

在这里查看 .rubocop.yml 的正式解释。

AllCops:
  Exclude:
    - Berksfile
    - recipes/basic.rb
    - attributes/*.rb

# Customize rules
Metrics/LineLength:
  Max: 95

MethodLength:
  Max: 35

Metrics/AbcSize:
   Enabled: false

BlockLength:
  Max: 70

I constantly bump by rubocop errors and warning. Thus I've published this post.

我经常遇到 rubocop 错误和警告。因此我发表了这篇文章。

Common Rubocop Errors: Improve Your Ruby Code Quality

常见的 Rubocop 错误:提高 Ruby 代码质量