If a Rubocop rule is disabled in-line does it need to be re-enabled

北战南征 提交于 2020-02-24 04:54:15

问题


If you disable a Rubocop rule in-line and do not re-enable it, will the rule be disabled for all subsequence files or is an in-line disable limited to the scope of the current file?

For example, if I enter this before a couple of methods that I know break the line length rule:

# rubocop:disable Metrics/LineLength

Is this rule disable for the rest of the file, or for all subsequent files in the current scan?


回答1:


In-line config is applied to the given file only (just tested it).




回答2:


You can also disable rubocop with a comment following some code, which disables it only for that line. For example:

def update # rubocop:disable Style/EmptyMethod
end

This can be nice if you want to say "yes I know this method has too many lines" or something without needing to remember to turn the cop back on.



来源:https://stackoverflow.com/questions/37921807/if-a-rubocop-rule-is-disabled-in-line-does-it-need-to-be-re-enabled

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!