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 #319] Fix a false positive for Rails/Inquiry #321

Merged
merged 1 commit into from
Aug 9, 2020

Conversation

koic
Copy link
Member

@koic koic commented Aug 6, 2020

Fixes #319.

This PR fixes a false positive for Rails/Inquiry when #inquiry's receiver is a variable.
It should only detect when receiver is an array literal and a string literal.


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.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.
  • 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.

@@ -26,7 +26,11 @@ class Inquiry < Cop
MSG = "Prefer Ruby's comparison operators over Active Support's `inquiry`."

def on_send(node)
add_offense(node, location: :selector) if node.method?(:inquiry) && node.arguments.empty?
return unless node.method?(:inquiry) && node.arguments.empty?
return unless (receiver = node.receiver)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding a test that covers inquiry with no receiver, since that's what this line is for?

Copy link
Member Author

Choose a reason for hiding this comment

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

Sure! I added the test.

CHANGELOG.md Outdated
@@ -12,6 +12,7 @@

* [#315](https://github.com/rubocop-hq/rubocop-rails/pull/315): Allow to use frozen scope for `Rails/UniqueValidationWithoutIndex`. ([@krim][])
* [#313](https://github.com/rubocop-hq/rubocop-rails/pull/313): Fix `Rails/ActiveRecordCallbacksOrder` to preserve the original callback execution order. ([@eugeneius][])
* [#319](https://github.com/rubocop-hq/rubocop-rails/issues/319): Fix an false positive for `Rails/Inquiry` when `#inquiry`'s receiver is a variable. ([@koic][])
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
* [#319](https://github.com/rubocop-hq/rubocop-rails/issues/319): Fix an false positive for `Rails/Inquiry` when `#inquiry`'s receiver is a variable. ([@koic][])
* [#319](https://github.com/rubocop-hq/rubocop-rails/issues/319): Fix a false positive for `Rails/Inquiry` when `#inquiry`'s receiver is a variable. ([@koic][])

Copy link
Member Author

Choose a reason for hiding this comment

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

Oops! Thank you!

@koic koic force-pushed the fix_false_positive_for_rails_inquiry branch from bcf9efe to fbcda86 Compare August 9, 2020 05:28
@koic koic changed the title [Fix #319] Fix an false positive for Rails/Inquiry [Fix #319] Fix a false positive for Rails/Inquiry Aug 9, 2020
Fixes rubocop#319.

This PR fixes a false positive for `Rails/Inquiry` when
`#inquiry`'s receiver is a variable.
It should only detect when receiver is an array literal and
a string literal.
@koic koic force-pushed the fix_false_positive_for_rails_inquiry branch from fbcda86 to a36dc5b Compare August 9, 2020 07:30
@koic koic merged commit 6517653 into rubocop:master Aug 9, 2020
@koic koic deleted the fix_false_positive_for_rails_inquiry branch August 9, 2020 16:50
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.

Rails/Inquiry get triggered on variable/method with the name "inquiry"
2 participants