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

[Fix #6860] Prevent auto-correct confliction of Style::InverseMethods and Style::Not #6951

Conversation

hoshinotsuyoshi
Copy link
Contributor

Fix #6860.

Prevent confliction problem like below:

file:

x.select { |y| not y.z }

auto-correct:

$ bundle exec rubocop -a c.rb --only Style/InverseMethods,Style/Not
Inspecting 1 file
C

Offenses:

c.rb:1:1: C: [Corrected] Style/InverseMethods: Use reject instead of inverting select.
x.select { |y| not y.z }
^^^^^^^^^^^^^^^^^^^^^^^^
c.rb:1:1: C: [Corrected] Style/InverseMethods: Use select instead of inverting reject.
x.reject { |y| !y.z }
^^^^^^^^^^^^^^^^^^^^^
c.rb:1:16: C: [Corrected] Style/Not: Use ! instead of not.
x.select { |y| not y.z }
               ^^^

1 file inspected, 3 offenses detected, 3 offenses corrected

corrected badly:

x.select { |y| y.z }

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.

Copy link
Collaborator

@Drenmi Drenmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! 🚀

CHANGELOG.md Outdated
@@ -18,6 +18,7 @@
* [#6946](https://github.com/rubocop-hq/rubocop/pull/6946): Allow `Rails/ReflectionClassName` to use string interpolation for `class_name`. ([@r7kamura][])
* [#6778](https://github.com/rubocop-hq/rubocop/issues/6778): Fix a false positive in `Style/HashSyntax` cop when a hash key is an interpolated string and EnforcedStyle is ruby19_no_mixed_keys. ([@tatsuyafw][])
* [#6902](https://github.com/rubocop-hq/rubocop/issues/6902): Fix a bug where `Naming/RescuedExceptionsVariableName` would handle an only first rescue for multiple rescue groups. ([@tatsuyafw][])
* [#6860](https://github.com/rubocop-hq/rubocop/issues/6860): Prevent auto-correct confliction of Style::InverseMethods and Style::Not. ([@hoshinotsuyoshi][])
Copy link
Collaborator

@Drenmi Drenmi Apr 22, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor nits:

"confliction" -> "conflict"
"Style::InverseMethods" -> "Style/InverseMethods"
"Style::Not" -> "Style/Not"

🙇

@hoshinotsuyoshi hoshinotsuyoshi force-pushed the autocorrect_confliction_inverse_methods branch from e785199 to 0656f7d Compare April 22, 2019 07:09
CHANGELOG.md Outdated
@@ -18,6 +18,7 @@
* [#6946](https://github.com/rubocop-hq/rubocop/pull/6946): Allow `Rails/ReflectionClassName` to use string interpolation for `class_name`. ([@r7kamura][])
* [#6778](https://github.com/rubocop-hq/rubocop/issues/6778): Fix a false positive in `Style/HashSyntax` cop when a hash key is an interpolated string and EnforcedStyle is ruby19_no_mixed_keys. ([@tatsuyafw][])
* [#6902](https://github.com/rubocop-hq/rubocop/issues/6902): Fix a bug where `Naming/RescuedExceptionsVariableName` would handle an only first rescue for multiple rescue groups. ([@tatsuyafw][])
* [#6860](https://github.com/rubocop-hq/rubocop/issues/6860): Prevent auto-correct conflict of Style/InverseMethods and Style/Not. ([@hoshinotsuyoshi][])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cop names are preferably quoted :-)

-Prevent auto-correct conflict of Style/InverseMethods and Style/Not. ([@hoshinotsuyoshi][])
+Prevent auto-correct conflict of `Style/InverseMethods` and `Style/Not`. ([@hoshinotsuyoshi][])

…hods` and `Style/Not`.

Prevent conflict problem like below:

file:
```
x.select { |y| not y.z }
```

auto-correct:
```
$ bundle exec rubocop -a c.rb --only Style/InverseMethods,Style/Not
Inspecting 1 file
C

Offenses:

c.rb:1:1: C: [Corrected] Style/InverseMethods: Use reject instead of inverting select.
x.select { |y| not y.z }
^^^^^^^^^^^^^^^^^^^^^^^^
c.rb:1:1: C: [Corrected] Style/InverseMethods: Use select instead of inverting reject.
x.reject { |y| !y.z }
^^^^^^^^^^^^^^^^^^^^^
c.rb:1:16: C: [Corrected] Style/Not: Use ! instead of not.
x.select { |y| not y.z }
               ^^^

1 file inspected, 3 offenses detected, 3 offenses corrected
```

corrected badly:
```
x.select { |y| y.z }
```
@hoshinotsuyoshi hoshinotsuyoshi force-pushed the autocorrect_confliction_inverse_methods branch from 0656f7d to 4e2b19d Compare April 22, 2019 07:41
@bbatsov bbatsov merged commit 43755df into rubocop:master Apr 22, 2019
@bbatsov
Copy link
Collaborator

bbatsov commented Apr 22, 2019

Thanks!

@hoshinotsuyoshi hoshinotsuyoshi deleted the autocorrect_confliction_inverse_methods branch May 4, 2019 04:18
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

Successfully merging this pull request may close these issues.

autocorrect removes negation
4 participants