2

Is there a way to disable warning from reek gem per method, per line or per block?

What we have for rubocop for example

# suppress warning Use snake_case for method names
def fooBar(baz) # rubocop:disable Naming/MethodName
  baz
end

this example will suppress warnings for rubocop, I'm looking something similar for reek tool.

def foo(bar) # reek:disable TooManyStatements
  baz = bar + bar
  # other line
  # more line
  # that produce reek warning
  baz
end  

In documentation I found that it is configurable only by config file, but that's not what I'm looking for

Andy Waite
  • 10,785
  • 4
  • 33
  • 47
zhisme
  • 2,368
  • 2
  • 19
  • 28
  • 1
    I'm not sure which documentation you were looking at; per-method disabling is mentioned [in the README](https://github.com/troessner/reek#source-code-comments). – Tom Lord Jan 27 '21 at 12:57
  • There doesn't appear to be support for disabling checks per-line or per-block, however. It only mentions per-project, per-directory, per-file, per-class and per-method. – Tom Lord Jan 27 '21 at 12:58
  • @TomLord thanks for that. Yeah somehow I didn't notice that line. This fully answers my question – zhisme Jan 27 '21 at 13:01

1 Answers1

5

https://github.com/troessner/reek/blob/master/docs/Smell-Suppression.md#how-to-disable-smell-detection

There are always the Basic Smell Options you can use in your configuration file. But in this document we would like to focus on a completely different way - via special comments.

A simple example:

# This method smells of :reek:NestedIterators
def smelly_method(foo)
  foo.each { |bar| bar.each { |baz| baz.qux } }
end

The method smelly_method will not be reported. The general pattern is to put the string :reek:, followed by the smell class, in a comment before the method or class.

zhisme
  • 2,368
  • 2
  • 19
  • 28