-
Notifications
You must be signed in to change notification settings - Fork 213
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
Don't enforce using key? and value? instead of has_key? and has_value? #161
Comments
I've tripped over this one a couple times myself. I'll admit I don't feel very strongly about it. On one hand, I always like being terse. On the other hand, we've made a bunch of decisions in other cases not to enforce a particular alias be used (as it seems kind of heavy-handed to tell people what API they're allowed to call for a style tool, if there's no technical risk that'd warrant linting) Will leave this open to see if anyone has a vote to share |
As soon as I read your reply, I realized that the "correct" choice is probably either to leave it as is or to not enforce this at all. Changing from enforcing the short versions to enforcing the long ones will just introduce noise to the tool and force people into an unnecessary code change. So I hereby change my proposal to just removing this rule, i.e. not enforcing which methods to use in this case. I'll update the title and description to reflect this. |
To me, Ruby's support of I also think a simple |
I'd vote for |
To me |
I vote for removing the rule and letting people use the API that makes sense for them. |
Long time follower, recent adoptee – I’d vote for disabling the rule entirely. |
Agree with you all. Removed and landed in 0.2.2 |
In
Hash
,key?
/has_key?
andvalue?
/has_value?
are aliases of each other. To me,has_key?
andhas_value?
are much clearer semantically, but StandardRB enforces usingkey?
andvalue?
. This is the default in RuboCop, which seems to stem from the fact that Matz prefers the short versions, and at some point even said the long versions were deprecated, although this was walked back. There is a discussion around this in rubocop/rubocop#3428, with this comment being especially relevant.I would argue that
has_key?
andhas_value?
increase readability, and so we should be allowed to use them. Originally, I suggested that the preference be changed from enforcing the short versions to the long versions. But after @searls's comment below, I realize that it would be better just to remove this rule altogether, so that people can use the alias they prefer. So my proposal is exactly that - to disable the ruleStyle/PreferredHashMethods
.This might be a lost cause at this stage, but I would argue thathas_key?
andhas_value?
increase readability, and therefore make much more sense as the standard than the short versions. I propose changing the rubocop configuration accordingly.I would be happy to provide a pull request, but since I'm guessing I'll be shot down, I'll wait until there's a verdict here. 😄
The text was updated successfully, but these errors were encountered: