-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
Lint/MultipleComparison should not be marked safe #9349
Comments
Arg, I have screwed up my example 🤦 . It was originally meant to be parenthesized but I screwed up somewhere in working with the DSL and then got very confused by the autocorrect output and opened this issue. Due to operator precedence it should be: (date >= range.begin) & (date < range.end) so the lint did highlight something noteworthy but imo it still should not autocorrect like that. |
Thank you for your feedback. I've opened #9352.
That's interesting. Is it possible that .rubocop.yml contains |
That looks like a good improvement for reducing false positives! It does not appear to mark autocorrection as unsafe, however. It still seems to me like this should not be marked as a "safe" cop. As a very simple example if I write: 1 < 2 < 3 # => NoMethodError: undefined method `<' for true:TrueClass I (rightly) get an error. If I let rubocop autocorrect it, it outputs the item below which returns 1 < 2 && 2 < 3 # => true Unless "safe" means something different than I think it should mean there are pretty clear changes in semantics here. WDYT? |
It appears to happen because my rubocop config requires |
Sure! I update the proposal #9352. I will also investigate |
Thanks @koic that's great. :) |
Follow rubocop#9349 (comment). This PR fixes duplicate extension cop versions when `rubocop -V`. The following is an example: ```yaml # ext.yml require: - rubocop-rspec # .rubocop.yml inherit_from: ext.yml require: - rubocop-performance - rubocop-rspec ## Before If there are duplicate requires, extension cop display will also be duplicated. Duplicate requires will be displayed in duplicate. ```console % rubocop -V 1.8.0 (using Parser 3.0.0.0, rubocop-ast 1.4.0, running on ruby 2.7.2 x86_64-darwin19) - rubocop-performance 1.9.2 - rubocop-rspec 2.0.0 - rubocop-rspec 2.0.0 ``` ## After Even if there are duplicate requires, they will only be displayed once per extension cop. ```console % rubocop -V 1.8.0 (using Parser 3.0.0.0, rubocop-ast 1.4.0, running on ruby 2.7.2 x86_64-darwin19) - rubocop-performance 1.9.2 - rubocop-rspec 2.0.0 ```
Follow #9349 (comment). This PR fixes duplicate extension cop versions when `rubocop -V`. The following is an example: ```yaml # ext.yml require: - rubocop-rspec # .rubocop.yml inherit_from: ext.yml require: - rubocop-performance - rubocop-rspec ## Before If there are duplicate requires, extension cop display will also be duplicated. Duplicate requires will be displayed in duplicate. ```console % rubocop -V 1.8.0 (using Parser 3.0.0.0, rubocop-ast 1.4.0, running on ruby 2.7.2 x86_64-darwin19) - rubocop-performance 1.9.2 - rubocop-rspec 2.0.0 - rubocop-rspec 2.0.0 ``` ## After Even if there are duplicate requires, they will only be displayed once per extension cop. ```console % rubocop -V 1.8.0 (using Parser 3.0.0.0, rubocop-ast 1.4.0, running on ruby 2.7.2 x86_64-darwin19) - rubocop-performance 1.9.2 - rubocop-rspec 2.0.0 ```
Fixes rubocop#9349. This PR fixes a false positive for `Lint/MultipleComparison` when using `&`, `|`, and `^` set operation operators in multiple comparison. e.g. `x < y & y < z` I think that the cop can probably allow using these operators by default.
Fixes #9349. This PR fixes a false positive for `Lint/MultipleComparison` when using `&`, `|`, and `^` set operation operators in multiple comparison. e.g. `x < y & y < z` I think that the cop can probably allow using these operators by default.
I am using a SQL query dsl with code like this:
rubocop autocorrects this to:
which has different semantics.
(see follow-up comment for my original error here^^ 🤦)
Expected behavior
This cop seems to make wrong assumptions about the safety of operating on relational operators. Whatever the case may be, this should not change my code to something that could be semantically different (by default).
Actual behavior
It autocorrects to semantically different code as outlined above.
Steps to reproduce the problem
Run
rubocop -a
on source files with the snippets above.RuboCop version
Side note: that duplicate
rubocop-rspec
is not a typo, that's what the command outputs. Not sure if there's something wrong there as well or some quirk to my config^The text was updated successfully, but these errors were encountered: