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

[Fix #6511] Fix an incorrect auto-correct for `Style/EmptyCaseCondition` #6513

Merged
merged 2 commits into from Nov 24, 2018

Conversation

Projects
None yet
2 participants
@koic
Member

koic commented Nov 22, 2018

Fixes #6511.

This issue is a regression by #6257.

This PR fixes an incorrect auto-correct for Style/EmptyCaseCondition when used as an argument of a method. The following is an issue example.

# example.rb
do_some_work case
             when object.nil?
               Object.new
             else
               object
             end

The following is a reproduction step.

% rubocop -V
0.60.0 (using Parser 2.5.3.0, running on ruby 2.5.3 x86_64-darwin17)
% rubocop -a example.rb --only Style/EmptyCaseCondition
% cat example.rb
             # example.rb
             if object.nil?
               Object.new
             else
               object
             end

The above has a bug to remove method call.

This PR will make the following corrections.

% rubocop -V
0.60.0 (using Parser 2.5.3.0, running on ruby 2.5.3 x86_64-darwin17)
% rubocop -a example.rb --only Style/EmptyCaseCondition
% cat example.rb
# example.rb
do_some_work if object.nil?
               Object.new
             else
               object
             end

Before submitting the PR make sure the following are checked:

  • Wrote good commit messages.
  • Commit message starts with [Fix #issue-number] (if the related issue exists).
  • Feature branch is up-to-date with master (if not - rebase it).
  • Squashed related commits together.
  • Added tests.
  • Added an entry to the Changelog if the new code introduces user-observable changes. See changelog entry format.
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences.
  • Run bundle exec rake default. It executes all tests and RuboCop for itself, and generates the documentation.

@koic koic force-pushed the koic:fix_an_incorrect_auto_correct_for_empty_case_condition branch 2 times, most recently from 5b1f559 to 8d8f9be Nov 22, 2018

[Fix #6511] Fix an incorrect auto-correct for `Style/EmptyCaseCondition`
Fixes #6511.

This issue is a regression by #6257.

This PR fixes an incorrect auto-correct for `Style/EmptyCaseCondition` when
used as an argument of a method. The following is an issue example.

```ruby
# example.rb
do_some_work case
             when object.nil?
               Object.new
             else
               object
             end
```

The following is a reproduction step.

```console
% rubocop -V
0.60.0 (using Parser 2.5.3.0, running on ruby 2.5.3 x86_64-darwin17)
% rubocop -a example.rb --only Style/EmptyCaseCondition
% cat example.rb
             # example.rb
             if object.nil?
               Object.new
             else
               object
             end
```

The above has a bug to remove method call.

This PR will make the following corrections.

```console
% rubocop -V
0.60.0 (using Parser 2.5.3.0, running on ruby 2.5.3 x86_64-darwin17)
% rubocop -a example.rb --only Style/EmptyCaseCondition
% cat example.rb
# example.rb
do_some_work if object.nil?
               Object.new
             else
               object
             end
```

@koic koic force-pushed the koic:fix_an_incorrect_auto_correct_for_empty_case_condition branch from 8d8f9be to e039b58 Nov 23, 2018

@bbatsov bbatsov merged commit c32d968 into rubocop-hq:master Nov 24, 2018

0 of 15 checks passed

ci/circleci: cc-setup Your tests are queued behind your running builds
Details
ci/circleci: documentation-checks Your tests are queued behind your running builds
Details
ci/circleci: jruby-9.2-ascii_spec Your tests are queued behind your running builds
Details
ci/circleci: jruby-9.2-rubocop Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.2-ascii_spec Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.2-rubocop Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.3-ascii_spec Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.3-rubocop Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.4-ascii_spec Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.4-rubocop Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.5-ascii_spec Your tests are queued behind your running builds
Details
ci/circleci: ruby-2.5-rubocop Your tests are queued behind your running builds
Details
ci/circleci: ruby-head-ascii_spec Your tests are queued behind your running builds
Details
ci/circleci: ruby-head-rubocop Your tests are queued behind your running builds
Details
ci/circleci: ruby-head-rubocop-with-jit Your tests are queued behind your running builds
Details

@koic koic deleted the koic:fix_an_incorrect_auto_correct_for_empty_case_condition branch Nov 24, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment