使用Rails 4应用程序我希望Rubocop在检查行是否为long时忽略带注释的行(只是注释或带有行尾注释的代码).有没有办法做到这一点?
vgo*_*off 172
有一种方法可以忽略每行的警察.
还有一种方法可以通过配置文件来完成.
运行rubocop --auto-gen-config并生成一个可用于禁用攻击的文件.
该命令还提示如何加载这些选项.
在每行一行上,您也可以启用和禁用警察.
# rubocop:disable RuleByName
This is a long line
# rubocop:enable RuleByName
Run Code Online (Sandbox Code Playgroud)
您还可以在代码中一次执行多个规则.
# rubocop:disable BlockComments, AsciiComments
Run Code Online (Sandbox Code Playgroud)
通过使用内联指令,该指令仅对该行有效,它看起来像这样:
# Thanks to @jnt30 for the comment!
method(argument) # rubocop:disable SomeRule, SomeOtherRule
Run Code Online (Sandbox Code Playgroud)
您可以在其官方手册中阅读更多关于RuboCop的内容.
要查找rubocop配置文件中值得查看的所有规则名称
cyberwiz说 - " rubocop -D当我需要规则名称而不是查看文档时运行." 更新:现在这是没有标志的默认行为.
GoB*_*sto 29
可以定义正则表达式模式以自动忽略某些行rubocop.yml,因此您可以选择忽略以#字符开头的所有行:
Metrics/LineLength:
Max: 80
IgnoredPatterns: ['\A#']
Run Code Online (Sandbox Code Playgroud)
这可以改进,以便"缩进"注释行(即空格后跟一个#字符)也被忽略,如果这是你想要的.
请注意,这并不考虑以注释结尾的代码行:
some_code(that_does_something) # This line would NOT be ignored by Rubocop.
Run Code Online (Sandbox Code Playgroud)
小智 21
您可以在 rubocop 中使用以下注释来忽略特定规则:
# rubocop:disable Layout/LineLength
def this_could_be_a_very_long_line_that_extends_forever_into_infinity
end
# rubocop:enable Layout/LineLength
Run Code Online (Sandbox Code Playgroud)
您还可以通过将它们添加到以下来忽略整个文件.rubocop.yml:
AllCops:
Exclude:
- path/to/file.rb
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
60630 次 |
| 最近记录: |