rubocop-rails
rubocop-rails copied to clipboard
Rails 6 deprecates where.not as NOR & Rails 6.1 as NAND
Currently if you use Rails 5.2 you can do for example: Post.where.not(source_type: "Feed", source_id: 100) and if we do the same in Rails 6.0.0.rc1 shows us the warning NOT conditions will no longer behave as NOR in Rails 6.1.To continue using NOR conditions, NOT each conditions manually.
This will make the migration process to Rails 6 difficult and it will not be correct to continue using the conditions as rails 5.2 does.
Describe the solution you'd like
Create a cop prohibiting the use of where.not with two arguments. I would like to contribute by creating it
Additional context
This is the Rails pull request where it was made https://github.com/rails/rails/pull/36029 More details of the change in this article https://www.bigbinary.com/blog/rails-6-deprecates-where-not-working-as-nor-and-will-change-to-nand-in-rails-6-1
Post.where (source_type: "Feed", source_id: 100)
Did you mean to write Post.where.not(source_type: "Feed", source_id: 100)
?
An alternative way to enforce this would be to configure Rails to raise on deprecation warnings:
config.active_support.deprecation = :raise
Post.where (source_type: "Feed", source_id: 100)
Did you mean to write
Post.where.not(source_type: "Feed", source_id: 100)
?
yes, sorry, fixed!
@jsolas Do you already have started with implementing this cop or do you have time capacities in the near future for it? Otherwise I can take care about it.
@andyw8 Would you be willing to merge such a cop? I've seen you commented in https://github.com/rubocop/rails-style-guide/pull/296#issuecomment-998390640, that you consider a chained not as bad, too. So what do you expect from this cop?
@denzelem A cop would surely be nice to have. A PR is welcome.
So what do you expect from this cop?
I'd say the cop should raise an offence for multiple attributes. And tolerate chained where.not
as a configurable option.
An alternative way to enforce this would be to configure Rails to raise on deprecation warnings:
config.active_support.deprecation = :raise
It's not always feasible I suppose, e.g. if there are other deprecation warnings.