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

NegatedIfElseCondition autocorrect leaves comments behind #9429

Closed
hlascelles opened this issue Jan 27, 2021 · 0 comments · Fixed by #9436
Closed

NegatedIfElseCondition autocorrect leaves comments behind #9429

hlascelles opened this issue Jan 27, 2021 · 0 comments · Fixed by #9436
Labels

Comments

@hlascelles
Copy link

hlascelles commented Jan 27, 2021

Autocorrect this code:

if !true
  # It wasn't true
  "Not true"
else
  "True!"
end

And you get:

if true
  # It wasn't true
  "True!"
else
  "Not true"
end

The "not true" code path "#It wasn't true" comment didn't move and is now in the "true" code path falsely marking the "True!" response as "#It wasn't true". True fact.

Rubocop 1.5.2

@koic koic added the bug label Jan 28, 2021
tejasbubane added a commit to tejasbubane/rubocop that referenced this issue Feb 21, 2021
@koic koic closed this as completed in #9436 Mar 7, 2021
koic added a commit that referenced this issue Mar 7, 2021
[Fix #9429] Fix `Style/NegatedIfElseCondition` autocorrect to keep comments in correct branch
koic added a commit that referenced this issue Mar 7, 2021
This commit fixes the following build error.

```console
% cd path/to/rubocop
% bundle exec rake
(snip)

  1) RuboCop Project Changelog future entries For
  /Users/koic/src/github.com/rubocop/rubocop/spec/../changelog/fix_comments_negated_if_else_condition_cop.md
  entry link to related issue has a valid URL
     Failure/Error: expect(issue[:url]).to match(pattern)

       expected "#9429" to
       match
       /^https:\/\/github\.com\/rubocop\/rubocop\/(?:issues|pull)\/9429$/
       Diff:
       @@ -1 +1 @@
       -/^https:\/\/github\.com\/rubocop\/rubocop\/(?:issues|pull)\/9429$/
       +"#9429"
     Shared Example Group: "has Changelog format" called from
       ./spec/project_spec.rb:261
     # ./spec/project_spec.rb:192:in `block (6 levels) in
       <top (required)>'
     # ./spec/project_spec.rb:188:in `each'
     # ./spec/project_spec.rb:188:in `block (5 levels) in
       <top (required)>'
     # tasks/spec_runner.rake:70:in `run_worker'
     # tasks/spec_runner.rake:30:in `block in run_specs'
     # tasks/spec_runner.rake:44:in `with_encoding'
     # tasks/spec_runner.rake:28:in `run_specs'
     # tasks/spec_runner.rake:116:in `block in <top (required)>'

1 deprecation logged to /tmp/test_queue_worker_27584_output
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
2 participants