node is not available, you have to set property
sonar.nodejs.executable to an absolute path to Node.js executable.
Supported Frameworks and Versions
- ECMAScript 5 / ECMAScript 2015 (ECMAScript 6) / ECMAScript 2016-2017-2018
- React JSX
Sonar way (default) and
Sonar way Recommended.
Sonar wayprofile is activated by default. It defines a trimmed list of high-value/low-noise rules useful in almost any JS development context.
Sonar way Recommendedcontains all rules from
Sonar way, plus more rules that mandate high code readability and long-term project evolution.
Slow or unresponsive analysis
On a big project it can happen that analyzer needs to allocate more memory to analyze the project. This would be manifested by analysis getting stuck and the following stacktrace might appear in the logs
ERROR: Failed to get response while analyzing [file].ts java.io.InterruptedIOException: timeout
You can use
8192 for big projects. This property should be set in
sonar-project.properties file or on command line for scanner (with
This feature is deprecated
As soon as the coding rule visits a node, it can navigate the tree around the node and log issues if necessary.
Create SonarQube Plugin
- Create a standard SonarQube plugin project
Add the following line in the sonar-packaging-maven-plugin configuration.
Implement the following extension points:
RulesDefinitionas an extension in the
You can implement both
CustomRulesRepository in a single class.
Implement a Rule
Create a class that will hold the implementation of the rule. It should:
- Define the rule name, key, tags, etc. with Java annotations.
- Declare this class in the
DoubleDispatchVisitor which provide a set of methods to visit specific tree nodes (these methods' names start with
visit). To explore a part of the AST, override the required method(s). For example, if you want to explore
if statement nodes, override the
DoubleDispatchVisitor#visitIfStatement method that will be called each time an
IfStatementTree node is encountered in the AST.
When overriding a visit method, you must call the
super method in order to allow the visitor to visit the rest of the tree.
SubscriptionVisitor. To explore a part of the AST, override
SubscribtionVisitor#nodesToVisit() by returning the list of the
Tree#Kind of node you want to visit. For example, if you want to explore
if statement nodes the method will return a list containing the element
Use these methods to log an issue:
PreciseIssue. In the SonarQube UI this issue will highlight all code corresponding to the tree passed as the first parameter. To add cost (effort to fix) or secondary locations provide these values to your just-created instance of
Issue. Use this method to create non-standard issues (e.g. for a file-level issue instantiate
Check context is provided by
SubscriptionVisitorCheck by calling the
To test the rule you can use
- Feature and API are deprecated.