Skip to content

empty-when

Rubysuspiciousno fixdefault: offruby/rubocop

Reports a when with no statements and no comment.

An empty when does nothing for that value, which usually means the code was never written, and it does not fall through to the next branch in Ruby.

To fix, write the body, or add a comment that says that nothing is meant to happen.

Reported
...
x
...
case x
when 1
when 2 then z
end
begin
...
ruby:
lint:
rules:
empty-when: warn # off (default), warn, error

Enabled by the presets: ruby/rubocop.

Suppress one line with sudsy-disable-next-line empty-when in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
rubocop Lint/EmptyWhen full