java custom rule for complexity

37 views
Skip to first unread message

anand sudhan

unread,
Feb 20, 2017, 2:55:32 PM2/20/17
to SonarQube

Hi ,

I have custom plugin for Java(and other languages) that primarily deals with customizing cyclomatic complexity - by way of skipping switch cases.
The way to do that was to make changes to ComplexityVisitor class and skip CASE_LABEL nodes.

Since now with Sonarqube 5.6.3 - the primary way to write custom rules for a language plugin is by actually extending the language plugin - as per this discussion, is there a way by which:
  •  I can access/override the ComplexityVisitor class from my custom rule plugin?
  • Or would I have to make changes to the ComplexityVistitor class in the Java plugin and also have a custom rule plugin (Which is maintenance inconvenience)
Thanks,
Anand

P.S: I am aware of Cognitive Complexity and the work being done on that front, but I would still like to stick my aforementioned approach - as I have tooling that is already using it with older versions of SQ (4.5.6)

Michael Gumowski

unread,
Feb 21, 2017, 3:23:18 AM2/21/17
to anand sudhan, SonarQube
Hello Anand,

To make things clear:
  • You won't be able to feed the complexity metric from a custom-rule in a custom-rule plugin, which purpose is ONLY to add new rules, not to change the existing metrics. This approach is not supported.
  • Modifying the way cyclomatic complexity is computed by access/override the implementation of the SonarJava plugin, is not supported and we don't provide - nor plan to provide - any way to do that.
Now I agree that your only solution in order to achieve what you want to do would be to fork the SonarJava plugin, modify the ComplexityVisitor, and update it regularly with your modifications (as the development of the analyzer continue). But it's probably going to be a world of pain on the long term. If you need extra custom rules, you will also have to maintain the custom-rule plugin.

I hope this helps clarify your situation, but keep in mind that you are going in a direction that the analyzer is not supporting, and we won't provide any further support on the topic.

Michael



--
You received this message because you are subscribed to the Google Groups "SonarQube" group.
To unsubscribe from this group and stop receiving emails from it, send an email to sonarqube+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/sonarqube/4f774562-aa8d-4c74-8fd4-78efd336a0e5%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
--

Michael GUMOWSKI | SonarSource
Software Developer @ Language Team
http://sonarsource.com

anand sudhan

unread,
Feb 21, 2017, 9:04:50 AM2/21/17
to SonarQube, anand.su...@gmail.com
Thanks Michael. I appreciate your candid response. 

-Anand
Reply all
Reply to author
Forward
0 new messages