-
Notifications
You must be signed in to change notification settings - Fork 27
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
Add TypeAliasName to ensure all constants used as T.type_alias are in CamelCase #92
Conversation
Please skip the first commit as it belong to #93 🙏 |
name = node.children[1] | ||
|
||
# From https://github.com/rubocop/rubocop/blob/master/lib/rubocop/cop/naming/class_and_module_camel_case.rb | ||
return unless /_/.match?(name) |
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 this will pass happily if name
is something like "HELLO"
Should we also check for name == name.capitalize
?
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 we want to allow such things no? Like for class names: SSH
, HTTP
?
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 we'll have to compromise here. Typically, we'd expect only acronyms to be all upcase, like SSH
and HTTP
, but Hello
should be camelcase. Rails uses an inflector initializer to define which words in your app are acronyms and can be all upcase and if they're not on the list it's always considered as camelcase.
For rubocop-sorbet
that feels like too much complexity for type aliases - especially since it's not tied to Rails. I think we'll need to decide whether we prefer acronyms to be forced to be camelcase or allow folks to attach type aliases to all upcase words like HELLO
. My vote goes to force all to be camelcase.
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 hadn't thought about the acronym case, good shout @Morriar
FWIW: There's at least one type_alias in Core called ID
which would be affected by this decision. Supporting rails-style acronym convention would be consistent with Rubocop, as Alex pointed out.
My vote goes to upcase. My 0.02 dollars.
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.
Here are a few ones that are legit, yet would be rejected by a stricter rule:
ID
GraphQLVariablesType
ARObject
StatsDTag
I'm not sure I want to force renaming those as they look good. What I really want to avoid is things like VALUE_TYPE
. But I agree that in the current state this cop is too permissive and would allow TYPE
.
Not sure what's the best, I'm happy to let the votes decide.
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.
That's fair, I agree with only marking names with underscores as offenses.
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 we should lean towards giving more flexibility to the devs since we can't perfectly know what's allowed. Underscore offence seems good enough.
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.
lgtm after typo
… CamelCase Signed-off-by: Alexandre Terrasa <[email protected]>
This cop ensures all constants used as
T.type_alias
are using CamelCase: