Rubocop:当只发现警告时,是否可以告诉 Rubocop 将 return 零作为退出代码?
Rubocop: Is it possible to tell Rubocop to return zero as exit code when only warnings are found?
问题
当只发现警告时,是否可以告诉 Rubocop return 0
作为退出代码?
先决条件
我正在使用以下命令 运行 Rubocop on Travis CI:
bundle exec rubocop
我有一个在 rubocop.yml
中配置为警告的警察:
Style/Documentation:
Severity: warning
问题
Travis CI 仅当其退出代码等于 0
.
时才会将命令视为成功命令
Rubocop returns 0
作为没有发现违规行为的退出代码,
但是当它发现至少一项违规行为时,
它 returns 1
作为退出代码,不管这个错误是错误还是警告。
因此,当 Rubocop 仅发现警告时,Travis CI 构建失败。
因此,当只发现警告时,是否可以告诉 Rubocop return 0
作为退出代码?
提前致谢。
备注
请不要建议禁用警察。
我正在使用以下方法检查退出代码:
$ bundle exec rubocop
// ...
14 files inspected, 8 offenses detected
$ echo "$?"
1
使用具有适当 severity
级别的 --fail-level
标志:
rubocop --fail-level error
您可以在 Rubocop Docs for command line flags and the severity
level in the Rubocop Docs for Generic configuration parameters 中阅读有关此标志的更多信息。
给定 foo.rb
:
# foo.rb
class Foo; end
和.rubocop.yml
:
Style/FrozenStringLiteralComment:
Severity: warning
运行 带有适当标志的 Rubocop:
rubocop --fail-level error
并得到以下输出:
Inspecting 1 file
W
Offenses:
foo.rb:1:1: W: Style/FrozenStringLiteralComment: Missing frozen string literal comment.
class Foo
^
然后获取退出码:
echo $?
0
通过修改您的 .rubocop.yml
以使用 error
而不是 warning
来验证它是否按预期工作:
Style/FrozenStringLiteralComment:
Severity: error
运行 再次得到输出:
rubocop --fail-level error
Inspecting 1 file
E
Offenses:
foo.rb:1:1: E: Style/FrozenStringLiteralComment: Missing frozen string literal comment.
class Foo
^
1 file inspected, 1 offense detected
并获取退出代码:
echo $?
1
问题
当只发现警告时,是否可以告诉 Rubocop return 0
作为退出代码?
先决条件
我正在使用以下命令 运行 Rubocop on Travis CI:
bundle exec rubocop
我有一个在
rubocop.yml
中配置为警告的警察:Style/Documentation: Severity: warning
问题
Travis CI 仅当其退出代码等于 0
.
Rubocop returns 0
作为没有发现违规行为的退出代码,
但是当它发现至少一项违规行为时,
它 returns 1
作为退出代码,不管这个错误是错误还是警告。
因此,当 Rubocop 仅发现警告时,Travis CI 构建失败。
因此,当只发现警告时,是否可以告诉 Rubocop return 0
作为退出代码?
提前致谢。
备注
请不要建议禁用警察。
我正在使用以下方法检查退出代码:
$ bundle exec rubocop // ... 14 files inspected, 8 offenses detected $ echo "$?" 1
使用具有适当 severity
级别的 --fail-level
标志:
rubocop --fail-level error
您可以在 Rubocop Docs for command line flags and the severity
level in the Rubocop Docs for Generic configuration parameters 中阅读有关此标志的更多信息。
给定 foo.rb
:
# foo.rb
class Foo; end
和.rubocop.yml
:
Style/FrozenStringLiteralComment:
Severity: warning
运行 带有适当标志的 Rubocop:
rubocop --fail-level error
并得到以下输出:
Inspecting 1 file
W
Offenses:
foo.rb:1:1: W: Style/FrozenStringLiteralComment: Missing frozen string literal comment.
class Foo
^
然后获取退出码:
echo $?
0
通过修改您的 .rubocop.yml
以使用 error
而不是 warning
来验证它是否按预期工作:
Style/FrozenStringLiteralComment:
Severity: error
运行 再次得到输出:
rubocop --fail-level error
Inspecting 1 file
E
Offenses:
foo.rb:1:1: E: Style/FrozenStringLiteralComment: Missing frozen string literal comment.
class Foo
^
1 file inspected, 1 offense detected
并获取退出代码:
echo $?
1