Skip to content

Conversation

@ochagata
Copy link
Contributor

3 style cops remain, otherwise all metrics cops

end
end

def self.normalize_path(path)
Copy link
Contributor Author

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

@dblock
Copy link
Member

dblock commented Apr 27, 2016

Note a legit spec failure.


def uses_path_versioning?
!!(settings[:version] && settings[:version_options][:using] == :path)
(settings[:version] && settings[:version_options][:using] == :path)
Copy link
Contributor Author

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?

Copy link
Member

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 :)

@ochagata ochagata force-pushed the fix_double_negation_violations branch from 78d5fdc to 1ae8b7c Compare April 27, 2016 17:33
@ochagata
Copy link
Contributor Author

Alright, should be good once travis check finishes

.rubocop.yml Outdated
- vendor/**/*
- bin/**/*

Style/DoubleNegation:
Copy link
Member

@dblock dblock Apr 27, 2016

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.

Copy link
Contributor Author

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

Copy link
Member

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.

Copy link
Contributor Author

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

Copy link
Member

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!

@ochagata ochagata force-pushed the fix_double_negation_violations branch from 0ef64ee to dd3ee60 Compare April 27, 2016 18:49

def uses_specific_format?
!!(settings[:format] && Array(settings[:content_types]).size == 1)
if settings.key?(:format) && settings.key?(:content_types)
Copy link
Contributor Author

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

@dblock
Copy link
Member

dblock commented Apr 27, 2016

Excellent.

@dblock dblock merged commit 8d6503d into ruby-grape:master Apr 27, 2016
@ochagata ochagata deleted the fix_double_negation_violations branch April 27, 2016 19:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants