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
Cop naming guidelines #7077
Comments
I was just given a great example of a bad cop name - |
Thoughts: (1) Disambiguate arguments and parameters. Spit cops if needed. Arguments are in method invocations. (2) For appropriate clustering in the documentation, I personally have found that clustering cops by their action (e.g. if they are powered by the same mixin) is better:
Than having multiple similar cops spread out:
I was also going to suggest (3) Start cop names with verbs, such that cop names could be interpreted as "this cop is going to...", but that doesn't work for cops like |
@scottmatthewman Do you plan to continue working on this? I'd really like for us to clean up shop in the next couple of months, so we can do 1.0 around Christmas as well. |
@bbatsov Yeah, I'd be happy to. |
I've gone through all our cop names, and come up with some suggestions. The biggest question is the "Indent something" vs "something indentation" question, which is pretty much limited to Layout cops. In general, layout cop names describe their area of attention (their 'beat', if you wanted to take the police analogy further) and typically have multiple options for I think the "NounAttentionType" works better for all these cops as a description of what they're looking for. In terms of grouping, an alphabetical list of cops will therefore tend to cluster cops around language elements (arrays, hashes, etc.) rather than a particular type of attention. (I get that clustering by attention type is valid too – just that both naming styles produce rational clustering). The good news is that there are fewer For non-layout cops, each cop's focus tends to be a lot tighter, and the cop names by and large reflect that well - however there are some that, if renamed, would provide additional consistency. I've got a suggested list for renaming below – although I have question marks against some:
Notes:
|
Great analysis! I agree with most of the suggestions, but I think there are a few nuanced names:
I thought this would work on the top level as well.
Maybe
I think
That's tricky indeed. I think it should be something along the lines of
Maybe
I think here the point is to highlight that the modifier doesn't do what people expect that it does, so I'm not sure about this name.
There's also the point if this pertains to variables or to all identifiers.
Totally agree. I think we had a plant to do this at some point, but maybe the implementation was going to be too complex or something like this. I think that you can go and rename the clear-cut cases and we can discuss additionally the rest. It would also be nice to add some naming practices in the docs and some internal cop that checks for cop classes that use "forbidden" words and points to the docs. |
While I initially thought that In this way, For this reason, I think the current name is actually more consistent. Indeed, I think that we'd have better consistency if we replaced |
To sum this up, what's left:
It's only for variables ( I'd go with
My voice goes for no naming change. There's a TODO (please feel free to edit):
Regarding the naming guideline itself, does the following sound good enough?
|
@scottmatthewman Would you like to cover this last mile yourself, or do you need a hand with that? |
We also need to put something in the docs on the subject and maybe introduce an internal affairs cop that checks for some naming anti-patterns. |
I'm afraid I'll have to pass at the moment, due to other pressures |
Upgrade rubocop from version 0.75.1 to version 0.77.0. The biggest breaking changes came from version 0.77.0 where many cops were re-named. I started by trying to make sense of the issue linked to in the CHANGELOG: https://github.com/rubocop/rubocop/blob/master/CHANGELOG.md#0770-2019-11-27 rubocop/rubocop#7077 But in the end I realized it was faster to just upgrade and let rubocop cop warn me of any unknown cops that needed to be re-named in version 0.77.0. I kept running this command in my local `radius-spec` repo until the errors stopped: ``` $ bin/rubocop --list --config .rubocop.yml ```
With RuboCop 1.0 closer than ever it's time for us to start doing to final cleanup leading to the 1.0 release. One aspect of the cleanup is to make sure all cops follow consistent naming patterns (and we'll enforce those down the road). Here are a few examples of inconsistencies we have today:
I hope you get the idea. The goal of this ticket is to agree on how names should use in general, document our decisions, and update all cops to match those before 1.0.
We should do the same for cop configuration keys as well.
The text was updated successfully, but these errors were encountered: