Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

MemberName checks class names too #4616

Closed
Stephan202 opened this issue Oct 13, 2024 · 6 comments
Closed

MemberName checks class names too #4616

Stephan202 opened this issue Oct 13, 2024 · 6 comments

Comments

@Stephan202
Copy link
Contributor

As of 43ed6f3, the MemberName check also flags type names. Resolving such violations is often much more involved than renaming (private) field names, possibly even prohibitive due to compatibility requirements.

Additionally, some of the suggestions are possibly controversial:

Suggestion: perhaps this type name logic can be moved to a separate check, with a more suitable name. Otherwise, what about allowing the type name logic to be disabled using a flag?

CC @graememorgan.

@graememorgan
Copy link
Member

None of those should, in principle, be controversial inside Google. Google's Java style guide has very well-defined (and as you can tell from ASTHelpers, not always followed!) rules about camelcasing. I think all of your "before" examples would be unstylish by those standards.

Of course, though, external users are not at all bound by our style guide. Would it be useful to just disable this entire check for third-party users? The entire thing is enforcing the style guide, which really ought to be opt-in.

@Stephan202
Copy link
Contributor Author

Would it be useful to just disable this entire check for third-party users?

Hmm, that would be a shame, as for actual member names I so far have never seen it emit a suggestion I'd consider suppressing. Additionally, users who disagree with the rule as a whole can also just set it to OFF.

(While I'd still prefer one of the other suggestions made, ) I suppose the minimal change this issue advocates for would be to rename the check, as it now focusses on more than members. On our side I'll review whether we should turn the check back on and (perhaps) add selective suppressions instead.

NB: It'd be nice to see the style guide take an explicit stance of type names derived from IOException: I'd expect that most readers would find it surprising to see SomeIoException. But maybe it just takes getting used to. 🤔

@Stephan202
Copy link
Contributor Author

@graememorgan I see that MemberName was renamed to IdentifierName in 4f630fc. Should I therefore close this issue, or are there plans to e.g. implement an allowlist for cases such as IOException? (I suppose I can live with either.)

@graememorgan
Copy link
Member

I don't think we'd be too motivated to implement carved-out exemptions to the style guide. Internally, the style guide is meant to be viewed as entirely non-negotiable.

I'd be happy to accept a PR to flag class checking though.

NB: It'd be nice to see the style guide take an explicit stance of type names derived from IOException: I'd expect that most readers would find it surprising to see SomeIoException.

I think it does take a stance on it by not providing an exemption. URI is another obvious one. A field should be called something like URI fooUri; you don't get to carry forward the violation to URI fooURI. I think I share your view that classes are somehow different though, but I can't quite work out why.

@Stephan202
Copy link
Contributor Author

I'd be happy to accept a PR to flag class checking though.
[..]
I think I share your view that classes are somehow different though, but I can't quite work out why.

Tnx! Based on this "somehow different but not sure why" feeling I proposed a PR that only allows users to opt-out of initialism checking in type names: #4646. I realize that this is rather niche, but there seems value in having the check unconditionally flag type names with underscores and those not starting with a capital letter.

@Stephan202
Copy link
Contributor Author

Closing issue, as #4646 was merged. Tnx for the quick review @cushon!

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants