user6596162
user6596162

Reputation:

Rubocop - how to disable warnings for missing else-clause?

How do I silence Rubocop warnings for a case-statement that does not include an else-clause? I tried the following value in my .rubocop.yml file without any success:

Style/MissingElse:
  Enabled: false

My case-statement looks like this:

case value
when 4..9 then x
when 10..15 then y
when 16..22 then z
end

Since the value tested cannot fall outside the range 4 - 22, I see little point in adding an else-clause.

Upvotes: 4

Views: 4061

Answers (1)

Aleksei Matiushkin
Aleksei Matiushkin

Reputation: 121000

Don’t disable it globally, suppress it inplace:

# rubocop:disable Style/MissingElse
case value
when 4..9 then x
when 10..15 then y
when 16..22 then z
end
# rubocop:enable Style/MissingElse

Upvotes: 7

Related Questions