Pmd: [core] Make properties declared in Java discoverable from XML

Created on 19 Oct 2020  路  3Comments  路  Source: pmd/pmd

Affects PMD Version: 6.28.0

Description:

Properties documentation shown at https://pmd.github.io/pmd-6.28.0/pmd_rules_apex_codestyle.html#methodnamingconventions for MethodNamingConventions are missing from https://github.com/pmd/pmd/blob/master/pmd-apex/src/main/resources/category/apex/codestyle.xml#L247

Or am I missing something? We consume those files to generate documentation for those patterns, and other tools have properties information.

suggestion ruleset-xml

Most helpful comment

Those properties are declared in the java rule. Properties declared in Java do not need to be declared in the XML. Maybe this ticket is more about whether all properties should be discoverable from the XML, to help tools?

All 3 comments

Those properties are declared in the java rule. Properties declared in Java do not need to be declared in the XML. Maybe this ticket is more about whether all properties should be discoverable from the XML, to help tools?

At Codacy we're parsing the XML files to get the properties to make them configurable in our UI. Apparently not all the properties are discoverable from the XML.

I think this is useful for external tooling and I would very much like to see this implemented. The idea already popped up when we were thinking about making a ruleset editor webapp (wiki, there is also some info here, including an item called "[doc] Generate a complete rule catalog in a machine-readable format").

I see two possible options

  1. The idea in those older tickets is to provide a utility that reads a ruleset and outputs exhaustive information about all rules in a machine readable format. Possibly we could ship the output of this utility in the jars we distribute, eg, there could be a category/java/categories-info.json (or xml, or csv) in pmd-java-<version>.jar.
  2. Another route is to extend the ruleset schema so that it requires properties to be declared in XML even when they're already defined in Java. One issue with this approach is duplication of the declarations, which requires some maintenance effort to keep in sync. Also this would probably require the same effort from users who have custom java rules...

IMO option 1 would be nicer, because a schema separate from the main ruleset schema would be easier to adapt to new requirements. The requirements could evolve more independently. Also this could be done before PMD 7.

OTOH option 1 probably means that this utility runs on a JVM, so it's less easy to relocate to some platforms. But this doesn't matter too much if the catalog is pre-generated I think

Was this page helpful?
0 / 5 - 0 ratings