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

Cop idea: AR use invalid?/ instead of !valid? or unless @valid? #914

Closed
tagliala opened this issue Jan 17, 2023 · 1 comment · Fixed by #936
Closed

Cop idea: AR use invalid?/ instead of !valid? or unless @valid? #914

tagliala opened this issue Jan 17, 2023 · 1 comment · Fixed by #936

Comments

@tagliala
Copy link
Contributor

Is your feature request related to a problem? Please describe.

A new cop to check for the usage of invalid? instead of !valid? when no conditions are given.

Describe the solution you'd like

The cop should suggest the following change:

-!@user.valid?
+@user.invalid?
-unless @user.valid?
+if @user.invalid?

Additional context

This is inspired by Rails/Blank

[Correctable] Rails/Blank: Use if @user.blank? instead of unless @user.present?
@fatkodima
Copy link
Contributor

fatkodima commented Jan 20, 2023

Wouldn't custom extending config for Style/InverseMethods be enough? - https://github.com/rubocop/rubocop/blob/ed00a87a77e3d05119f451b745dc951c5834f368/config/default.yml#L4012-L4037

koic added a commit to koic/rubocop-rails that referenced this issue Feb 19, 2023
…invalid?` methods

Fixes rubocop#914.

This commit makes `Style/InverseMethods` aware of `valid?` and `invalid?` methods.
@koic koic closed this as completed in #936 Feb 24, 2023
koic added a commit that referenced this issue Feb 24, 2023
…_valid_and_invalid

[Fix #914] Make `Style/InverseMethods` aware of `valid?` and `invalid?` methods
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 a pull request may close this issue.

2 participants