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 #1015] Make Style/InvertibleUnlessCondition aware of Active Support methods #1097

Conversation

koic
Copy link
Member

@koic koic commented Aug 28, 2023

Resolves #1015.

This PR makes Style/InvertibleUnlessCondition aware of Active Support methods. It still inherits the default disabled.


Before submitting the PR make sure the following are checked:

  • The PR relates to only one subject with a clear title and description in grammatically correct, complete sentences.
  • 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.
  • Ran bundle exec rake default. It executes all tests and runs RuboCop on its own code.
  • Added an entry (file) to the changelog folder named {change_type}_{change_description}.md if the new code introduces user-observable changes. See changelog entry format for details.
  • If this is a new cop, consider making a corresponding update to the Rails Style Guide.

…tive Support methods

Resolves rubocop#1015.

This PR makes `Style/InvertibleUnlessCondition` aware of Active Support methods.
It still inherits the default disabled.
@koic koic merged commit d930b59 into rubocop:master Sep 4, 2023
4 checks passed
@koic koic deleted the make_style_invertible_unless_condition_aware_of_as_methods branch September 4, 2023 03:44
koic added a commit to rubocop/rubocop that referenced this pull request Sep 4, 2023
This is a change similar to ffa0c10.

It will be implemented in RuboCop Rails instead of commented out:
rubocop/rubocop-rails#1097
@davidstosik
Copy link

davidstosik commented Sep 29, 2023

@koic Hi there! 👋🏻
I'm looking at this and have a couple thoughts/questions:

  • we might be interested to only apply this cop to Ruby methods, without having to explicitly maintain a custom list of InverseMethods. Could we do that?
  • This PR does not seem to add the :valid?/:invalid? pair that was mentioned in the original "bug" report. Was this intentional?

@koic
Copy link
Member Author

koic commented Sep 29, 2023

Thank you for the feedback!

we might be interested to only apply this cop to Ruby methods, without having to explicitly maintain a custom list of InverseMethods. Could we do that?

Unfortunately, this will not be possible as it does not assume such a background. It is intended to be used only if there is some will.

  1. Style/InvertibleUnlessCondition cop is disabled by default. Must be turned on intentionally if enabled.
  2. The cop has already been marked unsafe. User should have enabled it knowing that it is unsafe.
  3. RuboCop Rails is intended to be used in Rails applications. In other words, it should provide consistency regarding Active Support methods.

This PR does not seem to add the :valid?/:invalid? pair that was mentioned in the #1015. Was this intentional?

The constructs valid? and invalid? belong to Active Model, not Active Support. I think valid? has a risk of false positives, so it might be better not to provide it by default.

I should have mentioned this point that deviate from the resolution of the original issue. 😓

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.

Cop idea: Negative #valid? method
2 participants