You can produce easily compatible and stable codes as Sonar.js makes it easy to find smells in codes, bugs and vulnerabilities. The basic features of Sonar are as follows –
- Based on data flow analysis and control flow, there are advanced rules of around 190, including approximately 60 for bug detection
- It is compatible with ECMAScript versions from 2015 to 2017
- There are metrics of complexity, line numbers and so on
- It supports Vue.js, Flow and React JSX
- With this, you can import ESLint issues and reports of test coverage
The installation process of Sonar.js is available in three formats namely CJS from dist/sonar.js, UMD from dist/sonar.umd.js and ESM from dist/sonar.m.js. In order to write the custom rules you can add the SonarQube Plugin followed by custom rules API of SonarJS. In this way, SonarJS parses source code and creates the AST or Abstract Syntax Tree so that the visitor can see the nodes from the AST. Right after the coding rule visits the node, it will be able to navigate around the tree through the node and if there is any issue, it logs it accordingly. Know about easiest programming language.
How To Add Plugins On Sonar JS To Detect Issues?
In order to implement the rule, creating a class which will extend SubscriptionVisitorCheck and DoubleVisitorCheck and define the tags, key and rule names with Java annotations are important factors. You can declare the class in CustomRuleRepository and RulesDefinition for successful implementation.
SonarQube Plugin – How It Works?
- After checking setup guidelines thoroughly, install the SonarQube Server
- Now install the SonarQube Scanner. Make sure that you are able to call the sonar-scanner from your source code directory
- Now install the plug-in for Sonar JS.
- Run the analysis along with SonarQube Scanner. Execute the below mentioned command from root directory of your project.
Sonar-scanner –Dsonar.projectKey=xxx –Dosonar.sources=.
- Now, go to the link mentioned at the end of project analysis so that you can browse through project’s quality within user interface of SonarQube.
For further analysis, after completing the third step, you can encapsulate the analysis parameters within the root of project where you will find the sonar-project.properties file. The subsequent analysis will be run accordingly. While configuring the quality profiles, you will have two options namely Sonar Way Recommended and Sonar Way, which is a default.