Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EmptyWhen should not be reported when there is an else block #3754

Closed
rpherbig opened this issue Nov 30, 2016 · 2 comments
Closed

EmptyWhen should not be reported when there is an else block #3754

rpherbig opened this issue Nov 30, 2016 · 2 comments

Comments

@rpherbig
Copy link

Rubocop should not report a warning on a case block with an "empty when" if it also has an else block. This style is useful to indicate that in some cases/whens, no action is necessary.


Expected behavior

Rubocop should not report a warning on a case block with an "empty when" if it also has an else block.

Actual behavior

Rubocop reports a warning that an "empty when" exists:

$ rubocop temp.rb
Inspecting 1 file
W

Offenses:

temp.rb:9:1: W: Avoid when branches without a body.
when 'something else'
^^^^^^^^^^^^^^^^^^^^^

1 file inspected, 1 offense detected

Steps to reproduce the problem

def handle_foo
  puts 'foo'
end

input = 'foo'
case input
when 'foo'
  handle_foo
when 'something else'
  # nothing needs to happen
else
  puts 'unexpected value!'
end

RuboCop version

Include the output of rubocop -V. Here's an example:

$ rubocop -V
0.45.0 (using Parser 2.3.3.0, running on ruby 2.0.0 i386-mingw32)
@tejasbubane
Copy link
Contributor

tejasbubane commented Dec 1, 2016

Duplicate of #3696 Can be closed.

@mrpinsky
Copy link

Bump for closing as duplicate @bbatsov

@Drenmi Drenmi closed this as completed Apr 15, 2018
koic added a commit to koic/rubocop that referenced this issue May 10, 2020
Fixes rubocop#3696 and rubocop#3754.

This PR add `AllowComments` option to `Lint/EmptyWhen` cop.
This option is enabled by default based on user feedback.
It is also the same default as the option of `Lint/SuppressedException`
set in rubocop#7805.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants