Check Code Quality of Your Custom Component Using SonarQube

Introduction

Use of custom component is very common while working with Oracle Digital Assistant (ODA). Whenever you want to make a call to any back-end service or implement complex logic, which otherwise would require multiple dialog flow states, you would be using custom component. A custom component is build using Node.js. While building a custom component, developers often tend to overlook  checking the code quality. While there are various tools available in the market to check the code quality, this article will describe how you can use SonarQube to check code quality of your custom component.


Setup

Download and install SonarQube (https://www.sonarqube.org/downloads/) on your machine. This will downlaod a .zip file on your machine. Once downloaded, extract it at a favorable location on your machine. Navigate to "bin" folder, which in my case is C:\sonarqube-8.1.0.31237\bin, and then navigate to the folder specifying your Operating System. Refer to below Figure-1.

Figure-1. SonarQube bin Folder















From there, you need to start the SonarQube server. If you are using Microsoft Windows operating system, then navigate to "windows-x86-64" folder and then run "StartSonar.bat". Once your SonarQube server is up, you will see "SonarQube in up" message as as shown in below Figure-2.

Figure-2. Starting SonarQube Server























Note: Latest version of SonarQube will require you to have JAVA 11 or higher on your machine. In case you have more than one JAVA versions installed on your machine, then you will have to specify the JAVA 11 (or higher version) location for SoanrQube. To do this navigate to the "conf" folder inside your SonarQube installation and open "wrapper.conf" in any text editor.

Locate the line:
wrapper.java.command=java

and edit that as below:
wrapper.java.command={JAVA_LOCATION_ON_YOUR_MACHINE}/java


Now that you have SonarQube server up and running on your machine, next step is add the SonarScanner for your custom component. To do so, navigate to your custom component's root folder and execute below npm command.

npm install -D sonarqube-scanner


Once that is done, you will notice that "sonarqube-scanner": "^2.5.0" is added in "devDependencies" section inside "package.json" file of custom component. Only thing that is now left is to scan the custom component using the SonarScanner. To do that, you just need to execute

sonar-scanner

from root folder of your custom component. Refer to below Figure-3.

Figure-3. Run SonarScanner












Once the analysis is finished, you can check your result by navigating to "http://localhost:9000/about" and from there, drilling down to Projects Analyzed. Refer to below Figure-4.

Figure-4. Custom Component Analysis 

Conclusion

It is always advisable to check the code quality. The process of analyzing code would require bare-minimum time but can save you from a lot of hassle and unwanted situations in future. This article explained how you can use SoanrQube to analyze your Node.js code of your ODA custom component and figure any code issue, if exists.



Comments

Post a Comment

Popular posts from this blog

About our ODA-Book and why this weblog is here.