We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
if !!
Using !! isn't negation, it's conversion to Boolean. So this should be valid code:
!!
if !!my_method_or_variable "true condition" else "false condition" end # Fails with: Style/NegatedIfElseCondition: Invert the negated condition and swap the if-else branches. if !!my_method ... ^^^^^^^^^^^^^^
Don't fail when !! is used in an if/else block. i.e. this should be valid:
if !!my_method_or_variable "true condition" else "false condition" end
The Style/NegatedIfElseCondition cop fails with:
Style/NegatedIfElseCondition: Invert the negated condition and swap the if-else branches
Add an if/else such as the following to a ruby file and run the Style/NegatedIfElseCondition cop:
if !!my_method "a" else "b" end
$ rubocop -V 1.3.0 (using Parser 2.7.2.0, rubocop-ast 1.1.1, running on ruby 2.6.6 x86_64-darwin19) - rubocop-performance 1.8.1 - rubocop-rails 2.8.1 - rubocop-rake 0.5.1
The text was updated successfully, but these errors were encountered:
Style/NegatedIfElseCondition
[Fix rubocop#9050] Fix a false positive for `Style/NegatedIfElseCondi…
c5b9552
…tion` Fixes rubocop#9050. This PR fixes a false positive for `Style/NegatedIfElseCondition` when `if` with `!!` condition.
Merge pull request #9051 from koic/fix_false_negative_for_negated_if_…
ee6a72f
…else_condition [Fix #9050] Fix a false positive for `Style/NegatedIfElseCondition`
Successfully merging a pull request may close this issue.
Using
!!
isn't negation, it's conversion to Boolean. So this should be valid code:Expected behavior
Don't fail when
!!
is used in an if/else block. i.e. this should be valid:Actual behavior
The Style/NegatedIfElseCondition cop fails with:
Steps to reproduce the problem
Add an if/else such as the following to a ruby file and run the Style/NegatedIfElseCondition cop:
RuboCop version
The text was updated successfully, but these errors were encountered: