Enable / Disable nodes of certain Kinds

Hello,
I am implementing a custom SonarQube rule in Java:

@Rule(key = "CustomRule", description = "Custom Rule Description")
public class CustomRule extends IssuableSubscriptionVisitor {

	@Override
	public List<Kind> nodesToVisit() {
		return Arrays.asList(Kind.MEMBER_SELECT, Kind.METHOD_REFERENCE);
	}
	
	@Override
		public void visitNode(Tree pTree) {
			
		}
}

The rule currently visits two kinds of nodes: MEMBER_SELECT and METHOD_REFERENCE. Is it possible to enable and disable certain Kinds on the SonarQube server? For example, I would like the rule only to validate nods of the kind of MEMBER_SELECT by default but as a user, I want the option to enable METHOD_REFERENCES nodes afterward e.g. in the SonarQube Server UI.

As a workaround, I could probably use “@RuleProperty” boolean variables but maybe there already is a way to easily enable and disable certain nodes to visit in SonarQube on the user’s side.

Hello @johannes_ctrl

Adding a rule parameter (with @RuleProperty as you correctly identified) seems like the correct way to go, this is in fact exactly what they are here for.

Hope it clarifies and have fun implementing Java rules!

Best,
Quentin

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.