Skip to content
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

Include naming conventions #276

Open
leikingo opened this issue May 25, 2021 · 3 comments
Open

Include naming conventions #276

leikingo opened this issue May 25, 2021 · 3 comments

Comments

@leikingo
Copy link

Since I really like the idea of using one fixed and common set of rules defined by a dependency, esp. when developing spring based applications, I was wondering why naming checks are not included in the default checkstyle rule set. I know those are common sense, but esp. for new Java devs, maybe also coming from different languages like Python, it would be great to also enforce these rules:

<module name="ConstantName" />
<module name="CatchParameterName" />
<module name="ClassTypeParameterName" />
<module name="InterfaceTypeParameterName" />
<module name="LambdaParameterName" />
<module name="LocalVariableName" />
<module name="MemberName" />
<module name="MethodName" />
<module name="MethodTypeParameterName" />
<module name="RecordTypeParameterName" />
<module name="ParameterName" />
<module name="PackageName" />
<module name="TypeName" />

What do you think?

@philwebb
Copy link
Contributor

Most of these look sensible and I'd like to try them. We might need some tweaks to *ParameterName because we sometimes want to go beyond a single letter.

I'm not sure that we can apply the ConstantName rule. I think the rule is wrong for a lot of Spring Code because static final alone isn't enough to determine if something is a constant.

For example, I consider static final String[] NO_STRINGS to be a constant because it can't change.
But, static final Map<String, String> cache isn't really a constant and shouldn't be written as CACHE.

I'm also not sure about CatchParameterName. We tend to use ex for all exceptions and throwables and we already have SpringCatchCheck to enforce some rules.

@philwebb philwebb added this to the 0.0.x milestone May 25, 2021
@leikingo
Copy link
Author

Interesting take on the ConstantName. I always struggle to find the right balance there. Do you see a static final Logger as a constant? Maybe this rule can be restricted via type (primitives, arrays)? Or maybe I'm overthinking this and some things should be done in the review and cannot be enforced upfront.

Regarding the CatchParameterName, or the single letter in general. Till now, I often went with single letters like e or t but again, maybe a good way to be more expressive there. Didn't notice the SpringCatchCheck before though. I'll consider to adapt to this pattern.

@philwebb
Copy link
Contributor

We usually use static final Logger logger rather than LOGGER.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants