-
-
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
Fix double negative conditional bug in NegatedIf
and NegatedWhile
style rules
#3146
Fix double negative conditional bug in NegatedIf
and NegatedWhile
style rules
#3146
Conversation
cc @ivantsepp |
NegatedIf
and NegatedWhile
style rules
880752b
to
089b385
Compare
['if !!condition', | ||
' some_method', | ||
'end']) | ||
expect(cop.offenses).to be_empty |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there should also be a test for modifier if
usage (single-line if
). Refer this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated!
089b385
to
c4409a8
Compare
Please squash the commits @natalzia-paperless |
9d876cd
to
35e4ffc
Compare
@tejasbubane squashed! |
|
||
_object, method = *condition | ||
|
||
return unless method == :! && !(node.loc.respond_to?(:else) && |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems to method == :!
should be removed now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmmm I think we still need this check to see if the only operator is !
. the additions here only rule out a double negation, which wouldn't be enough to check for this rule.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, yeah. I got confused here. Still, it seems to me we can directly check that we're dealing with single instead of double negation and that would simplify the logic. Right now the structure of the methods seems a bit convoluted.
I've added a couple of remarks. |
934a2a9
to
7545baf
Compare
@bbatsov pushed some new code. how do you feel about this approach? it removed the |
7545baf
to
3478ba7
Compare
Previously this file only looked at the first operator in the line With these changes there is now a pattern match to ensure `!!` isn't flagged by these rules Add tests for double negation in while and if specs Update CHANGELOG.md
3478ba7
to
a4eca96
Compare
Yep, that's much better. |
…rubocop#3146) Previously this file only looked at the first operator in the line. With these changes there is now a pattern match to ensure `!!` isn't flagged by these rules.
Currently you receive a negated if/while error from Rubocop if you have a conditional that is double negated. Rubocop should have awareness of whether there is a single
!
or two. In the event that your line reads something akin toif !!conditional
Rubocop should only fail on the DoubleNegation rule.Before submitting the PR make sure the following are checked:
master
(if not - rebase it)and description in grammatically correct, complete sentences.