Skip to content

Include naming conventions #276

Open

Description

@leikingo

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?

Activity

  1. philwebb commented on May 25, 2021

    @philwebb
    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.

  2. added this to the 0.0.x milestone on May 25, 2021
  3. leikingo commented on May 26, 2021

    @leikingo
    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.

  4. philwebb commented on May 26, 2021

    @philwebb
    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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions