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

Enable checkstyle rule: ConstantName #2455

Open
ash211 opened this issue Nov 21, 2022 · 3 comments
Open

Enable checkstyle rule: ConstantName #2455

ash211 opened this issue Nov 21, 2022 · 3 comments

Comments

@ash211
Copy link
Contributor

ash211 commented Nov 21, 2022

What happened?

A code review flagged that this line should be in UPPER_SNAKE_CASE:

static final String emptyContents = "";

If we care about this, it should be enforced as a lint rule instead of comment.

What did you want to happen?

Enable https://checkstyle.sourceforge.io/config_naming.html#ConstantName in the default checkstyle file.

@ash211
Copy link
Contributor Author

ash211 commented Nov 21, 2022

Probably need to handle log/logger constants as exceptions, since those are rarely capitalized.

An internal repo has the rule enabled like this:

<module name="ConstantName">
    <property name="format" value="^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*|log|logger$"/>
</module>

@j-baker
Copy link
Contributor

j-baker commented Nov 21, 2022

@ash211
Copy link
Contributor Author

ash211 commented Nov 22, 2022

that constant vs non-constant distinction sounds very similar to immutable vs mutable. Is there a difference between constant-ness and immutability?

For programmatic enforcement of the constant naming scheme, we could look into requiring members whose types are annotated @Immutable be named according to the constant naming scheme in UPPER_SNAKE_CASE. That immutability is verified with https://errorprone.info/bugpattern/Immutable

I'm not sure this is worth the effort though, just for naming consistency.

# 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