Skip to content

[core] How to specify custom path variable and access the value in any rule? #3057

Answered by jsotuyod
uberbinge asked this question in Q&A
Discussion options

You must be logged in to vote

@Waqas716 then you don't need anything at all. The existing properties support is more than enough for your usecase.

Instead of using a constant, you define a property with a proper type and default value (for instance AvoidDeeplyNestedIfStmtsRule defines an integer property for how many are too many nested ifs). There are property types for pretty much all data types you can think of in the net.sourceforge.pmd.lang.rule.properties package.

Given that, the end user can write a custom ruleset XML including your new rule, passing proper values for the properties, for instance:

<?xml version="1.0"?>
<ruleset name="Custom Properties Java ruleset example"
    xmlns="http://pmd.sf.net/ruleset/1…

Replies: 4 comments

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Answer selected by adangel
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #218 on January 15, 2021 09:47.