GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [core] Consistent implementation of enum properties · Issue #6184 · pmd/pmd

[core] Consistent implementation of enum properties #6184

New issue
Copy link
New issue
Copy link
Closed
#6233
Closed
[core] Consistent implementation of enum properties#6184
#6233
Copy link
Labels
an:enhancementAn improvement on existing features / rules
Milestone
7.21.0

Description

@adangel
adangel
opened on Oct 29, 2025
Issue body actions

Is your feature request related to a problem? Please describe.
As pointed out in #6131 rule properties based on enums are implemented in different ways. They should be implemented in a consistent way.

The Enum Property Builder uses a "labelMaker" function, that is used to convert the enum constant name into a string for usage in the ruleset xml.
Some use toString (net.sourceforge.pmd.lang.java.rule.codestyle.ConfusingTernaryRule.NullCheckBranch), some use a custom adhoc mapping (net.sourceforge.pmd.lang.java.rule.codestyle.ModifierOrderRule.TypeAnnotationPosition, net.sourceforge.pmd.lang.java.rule.documentation.CommentRequiredRule.CommentRequirement) and other use camel case conversion via CaseConvention.CAMEL_CASE (net.sourceforge.pmd.lang.java.rule.bestpractices.AvoidReassigningLoopVariablesRule.ForeachReassignOption).

Ideally, we would use the same notation for all enum properties.

Describe the solution you'd like

  • Make it programmatically impossible to do the wrong thing: have only one overloaded method net.sourceforge.pmd.properties.PropertyFactory#enumProperty
  • Other methods to create a enum property should be deprecated
  • We need a solution for backwards compatibility - we might find the old notations used in rulesets, so we should still be able to read it. Ideally issuing a deprecation warning
  • When generating the rule docs, we should generate a possible values for an enum property. This is a smaller task than [doc] Produce example configs for rule properties #4297 but would still be helpful I think.
  • The notation and convention should be
    • enum values in Java follow the usual naming convention to be SCREAMING_SNAKE_CASE
    • enum values, that are used for rule properties, should use the "camelCase" naming convention
    • the values in ruleset xml should use the same notation - no extra conversion (Enum::name() and Enum::valueOf)

Describe alternatives you've considered

  • none considered

Additional context

  • this will affect compatibility...

Activity

  1. adangel
    added
    an:enhancementAn improvement on existing features / rules
    on Oct 29, 2025
  2. adangel
    modified the milestones: 7.18.0, 7.19.0 on Oct 29, 2025
  3. adangel commented on Oct 29, 2025

    @adangel
    adangel
    on Oct 29, 2025
    MemberAuthor
    More actions

    Note that the following comment is wrong:

    pmd/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/AvoidReassigningLoopVariablesRule.java

    Line 334 in fb5d54c

    * The RuleDocGenerator uses toString() to determine the default value.

    The RuleDocGenerator uses the properties' serialization form and not toString...

    pmd/pmd-doc/src/main/java/net/sourceforge/pmd/doc/internal/RuleDocGenerator.java

    Line 602 in fb5d54c

    defaultValue = propertyDescriptor.serializer().toString(realDefaultValue);

  4. adangel commented on Nov 13, 2025

    @adangel
    adangel
    on Nov 13, 2025
    MemberAuthor
    More actions

    Currently used enum properties:

    • mapping function
      • AvoidReassigningLoopVariables
        • foreachReassign: allow, deny, firstOnly -> camelCase
        • forReassign: allow, deny, skip -> camelCase
      • ModifierOrder
        • typeAnnotations: anywhere, ondecl, ontype -> camelCase
      • CommentRequired
        • methodWithOverrideCommentRequirement: Ignored, Required, Unwanted -> PascalCase
        • note: the possible values are documented for each property in the property description.
    • toString mapping
      • ConfusingTernary
        • nullCheckBranch: Any, Else, Then -> PascalCase
    • mapping map
      • JavaLanguageProperties: xTypeInferenceLogging
        • xTypeInferenceLogging: DISABLED, SIMPLE, VERBOSE -> SCREAMING_SNAKE_CASE
    • enumList with mapping map
      • CyclomaticComplexity
        • cycloOptions: considerAssert, ignoreBooleanPaths -> camelCase
      • NcssCount
        • ncssOptions: countImports -> camelCase
      • AvoidBranchingStatementAsLastInLoop
        • checkBreakLoopTypes: do, for, while -> camelCase
      • net.sourceforge.pmd.lang.test.AbstractMetricTestRule and subclasses
    • enumList with mapping function
      • AvoidUsingHardCodedIP
        • checkAddressTypes: IPv4, IPv4 mapped IPv6, IPv6 -> space separated

    Current doc https://docs.pmd-code.org/latest/pmd_userdocs_extending_defining_properties.html suggests to use no explicit mapping (so, defaults to toString). But uses camel case in the example enum.

    Summary:

    • ⭐ camelCase: 5 rules
    • PascalCase: 2 rules
      • need to be changed:
        • CommentRequired -> methodWithOverrideCommentRequirement: ignored, required, unwanted
        • ConfusingTernary -> nullCheckBranch: any, else, then
    • space separated: 1 rule
      • needs to be changed:
        • AvoidUsingHardCodedIP -> checkAddressTypes: IPv4, IPv4MappedIPv6, IPv6
    • SCREAMING_SNAKE_CASE: once for language properties
      • we could decided to leave this as is. xTypeInferenceLogging is anyway a internal property.
  5. adangel
    modified the milestones: 7.19.0, 7.20.0 on Nov 27, 2025
  6. adangel
    added a commit that references this issue on Dec 12, 2025

    Update release notes (pmd#6184)

    85a19d9
  7. adangel
    modified the milestones: 7.20.0, 7.21.0 on Dec 30, 2025
  8. adangel
    added a commit that references this issue on Jan 7, 2026

    Update release notes (pmd#6184)

    cdf76f8
  9. adangel
    closed this as completedin 6af8c38on Jan 16, 2026
  10. adangel
    added a commit that references this issue on Jan 16, 2026

    [core] Fix pmd#6184: More consistent enum properties (pmd#6233)

    This issue will close once commit 6af8c38 is merged into the 'main' branch.
    6af8c38
  11. wener-tiobe
    added a commit that references this issue on Feb 10, 2026

    RM-37163: CPD 7.21.0 upgrade (#8)

    6a1959a
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    an:enhancementAn improvement on existing features / rules

    Type

    No type

    Projects

    No projects

      Milestone

      • 7.21.0

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.