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?

ReggieB
  • 8,100
  • 3
  • 38
  • 46

2 Answers2

30

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.

Nate
  • 4,561
  • 2
  • 34
  • 44
  • at first i was looking for a "better" solution - a comment on a line before, like eslint does it; but this made me realize that ruby is so nice, this is even better. – Ondřej Želazko Jan 07 '23 at 23:44
7

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

ReggieB
  • 8,100
  • 3
  • 38
  • 46
Vasiliy Ermolovich
  • 24,459
  • 5
  • 79
  • 77