如何让 rubocop 仅显示警告或更严重的严重性?
How do I get rubocop to show severities of Warning or worse only?
我有一个庞大的遗留代码库,我想开始处理警告。我怎样才能让 rubocop 只显示警告(以 W: 开头的行)甚至更糟,并禁止所有约定(以 C: 开头的行)?
我发现 rubocop 将规则分为不同的类别:Syntax
, Lint
and others:
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 warning and above it's rubocop --only Lint
.
因此,我首先需要修复 Lint
个错误。
在我的例子中,处理这个问题的最佳方法是通过 rubocop_todo.yml
自上而下地工作,可以使用以下方法创建:
rubocop --auto-gen-config
由于 rubocop_todo.yml
文件是按严重性顺序创建的,即 Syntax
位于顶部,然后是 Lint
,然后是其他文件,因此按顺序处理它们以修复警告首先.
利用--display-only-fail-level-offenses
标志并将失败级别设置为warning
:
rubocop --fail-level warning --display-only-fail-level-offenses
我有一个庞大的遗留代码库,我想开始处理警告。我怎样才能让 rubocop 只显示警告(以 W: 开头的行)甚至更糟,并禁止所有约定(以 C: 开头的行)?
我发现 rubocop 将规则分为不同的类别:Syntax
, Lint
and others:
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 warning and above it'srubocop --only Lint
.
因此,我首先需要修复 Lint
个错误。
在我的例子中,处理这个问题的最佳方法是通过 rubocop_todo.yml
自上而下地工作,可以使用以下方法创建:
rubocop --auto-gen-config
由于 rubocop_todo.yml
文件是按严重性顺序创建的,即 Syntax
位于顶部,然后是 Lint
,然后是其他文件,因此按顺序处理它们以修复警告首先.
利用--display-only-fail-level-offenses
标志并将失败级别设置为warning
:
rubocop --fail-level warning --display-only-fail-level-offenses