Saturday 31 August 2019

Part - 4 Integrate SonarQube with Visual Studio using SonarLint


Part - 1 SonarQube Installation on Windows
Part - 2 Analyze code Using SonarQube
Part - 3 SonarQube Connect with SQL Server


What is SoanrLint?

SonarLint is an IDE extension that helps you detect and fix quality issues as you write code. Like a spell checker, SonarLint squiggles flaws so that they can be fixed before committing code.

SonarLint an extension you can add to an IDE such as Visual Studio that can provide developers real-time feedback on the quality of the code. It can detect issues in seconds, which can improve productivity. SonarSource describes SonarLint as a capability that can work like a spell checker for text since it detects issues in your code as you go.

In this post, we will be discussing how you can enable SonarLint in Visual Studio to get real-time feedback on the quality of your code. This project assumes that you already have a running instance of SonarQube on a server.


Installation

In Visual Studio, SonarLint is an extension that can be installed by going to the following:
Tools -> Extensions and Updates -> Online
Then in the search box, search for “SonarLint”. Once you see SonarLint, press “Download”.


You must now sign out of Visual Studio to let the changes save properly. VSIX Installer will prompt you to allow for it to modify Visual Studio. After this is completed, you can now use SonarLint for your project.

After the restart of Visual Studio, you should have a new entry in the “Analyze” menu called “Manage SonarQube Connections…”:



Using SonarLint in your project

Open the project you want to connect with SonarQube, click on the following:
Analyze -> Manage SonarQube Connections
A new entry called “SonarQube” will be shown in the Team Explorer window.



(If you don’t have an open project the connect link in the left bottom corner will be grey and inactive. Is this the case, open a project and it will turn into a link.)
Then you will need to press “Connect” to connect to your SonarQube Server. Add in the SonarQube server, username, and password information.


SonarLint will now connect to your SonarQube server and show you a list of your projects:


Now you can tell SonarLint to which SonarQube project your current solution belongs. With that link created, SonarLint can now fetch the project-specific rules from SonarQube. This is the reason we do all that linking and connecting. From now on your changes in the rule set in SonarQube will be synchronised to Visual Studio.
This synchronisation ensures that your Visual Studio only checks what needs to be checked and nothing else.

Analyse your code

You can now analyze your code. You can do this with the following:
Right click solution -> Analysis -> Run Code Analysis
If there are any errors or issue with your code, you will see it in the “Error List” box built into Visual Studio. Moreover, you will be able to see the UI line items directly in Visual Studio. Normally, you would need to log into the SonarQube web application directly to get this information.
Another benefit of SonarLint in Visual Studio is that you will see a helper notify you with errors or warnings as you write code. This allows you to fix code right away in real-time. This can drastically improve efficiency for developers and it will help reduce the time needed for code checks.

Improving code quality

You can write the code as you did before. But now you get a new helper that can warn you while you work.

This doesn’t look like a big improvement, but give it a try. The integration is neat and simple and helps you when you want to listen. Should you want to ignore it you simply close the window – your build server can remind you later on that you should improve that piece of code you just wrote.



No comments:

Post a Comment

Sitecore Publishing Service 7.0 Installation Guide

  About the Publishing Service module The Publishing Service module is an optional replacement for the existing Sitecore publishing methods....