-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix double negation violations #1378
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 negation violations #1378
Conversation
| end | ||
| end | ||
|
|
||
| def self.normalize_path(path) |
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.
This method had been implemented as private before. Ruby doesn't actually allow for private class methods, so moving it above the private block and taking care of the violation doesn't change anything
|
Note a legit spec failure. |
lib/grape/path.rb
Outdated
|
|
||
| def uses_path_versioning? | ||
| !!(settings[:version] && settings[:version_options][:using] == :path) | ||
| (settings[:version] && settings[:version_options][:using] == :path) |
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.
@dblock
The error in the specs is related to this line change.
My problem is with the way ruby style-guide/rubocop addresses this violation.
# bad
!!(settings[:format] && Array(settings[:content_types]).size == 1)
#good
!(settings[:format] && Array(settings[:content_types]).size == 1).nil?
This raises the problem of if this operation returns false, it will evaluate to true, which makes it return the incorrect value.
I personally am not opposed to !! and think it is in fact better than the alternative !foo.nil?
Potentially, I could rework this PR to simply disable this check and move it to .rubocop.yml as disabled
Thoughts?
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 keeping a double-negation is fine. I also don't agree with Rubocop here :)
78d5fdc to
1ae8b7c
Compare
|
Alright, should be good once travis check finishes |
.rubocop.yml
Outdated
| - vendor/**/* | ||
| - bin/**/* | ||
|
|
||
| Style/DoubleNegation: |
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.
We often just run rubocop --auto-gen-config, can we just do that instead? It's more future-proof.
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.
Sure, but I'll have to keep this one in here so it ignores this
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.
Na, just remove it from here and let the auto-gen-config flag it as a violation. Maybe one day we'll change our mind on whether we like !! or not.
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.
Got it, I'll have this be a PR to fix the lint violation then
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.
Note that the other double-negation fixes are valuable, they just waste CPU cycles, so I am happy you did them!
0ef64ee to
dd3ee60
Compare
|
|
||
| def uses_specific_format? | ||
| !!(settings[:format] && Array(settings[:content_types]).size == 1) | ||
| if settings.key?(:format) && settings.key?(:content_types) |
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.
Figured out why it was failing here and how to implement it properly.
Added a check for the presence of the keys, if either is nil, it will simply move on to the else block
|
Excellent. |
3 style cops remain, otherwise all metrics cops