我如何抑制 Rubocop 约定?

How do I suppress Rubocop Conventions?

我正在查看 rubocop,但想从警告和错误开始 - 我们稍后会讨论与约定相关的警报。我的问题是:如何调用 rubocop,它会忽略与约定相关的警报并仅报告警告、错误和致命消息。

谢谢 迈克尔.

猜猜你需要一个一个地禁用它们。一般来说,我建议执行所有规则。

为方便起见,这里是我的。rubocop.yml我经常使用。这应该会抑制许多非严重警告。

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

# Customize rules
Metrics/LineLength:
  Max: 95

MethodLength:
  Max: 35

Metrics/AbcSize:
   Enabled: false

BlockLength:
  Max: 70

我经常遇到 rubocop 错误和警告。因此我发布了这个 post.

Common Rubocop Errors: Improve Your Ruby Code Quality

rubocop --only Syntax,Lint

来自https://github.com/bbatsov/rubocop/issues/2337#issuecomment-150477553

If you don't have any custom severity levels in your configuration, it's quite simple. The Synax cop reports on fatal and error level, Lint cops on warning level and all other cops on convention level.

So for only fatal and error, it's rubocop --only Syntax (which is only supported on master, not released yet), and for warningand above it's rubocop --only Lint.