Real-time Code Quality Scan with SonarLint in Visual Studio Code

Dijin Augustine
4 min readFeb 4, 2022

Code Quality using SonarLint : Visual Studio Code

What is SonarLint?

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.

Instant View

Markers automatically appear on quality issues when opening a file.

SonarLint highlights code issues with markers on open files. It also provides an issues summary table for a selected component in the IDE, including the creation time of the issue.

On-the-fly Detection

Issues appear as you type code.

SonarLint offers the ability to see problems as you code, like a spell checker for text. This is done by subtly pointing out the issue without distracting the developer so that he can focus on code but is still notified of the issue.

Smart Education

Error descriptions come with issue detection.

Once SonarLint detects an issue, it also shows the associated documentation to help the developer understand the issue and why it is a problem. It gives a compliant and non compliant code example and shows how to resolve the example issue. Easy, powerful and fun to use: a good way for developers to learn.

Push Notifications

Get real-time code quality notifications in your IDE as you work. Track Quality Gate status (failed, passed, warning) or that an analysis has assigned a new issue to you.

Adding SonarLint to Visual Studio Code

Prerequisites

  • A computer that works and is connected to the Internet. (Install the SonarLint plugin)
  • A working SonarQube (6.7.4+) server.
  • A recent version of Visual Studio Code.
  • A Java Runtime (JRE) 8 or 11 installed on your computer.

Installation & Configuration

  • In Visual Studio Code, go to the Marketplace and download SonarLint
  • Restart/Reload Visual Studio Code.
  • In the Visual Studio Code Settings, search SonarLint
{
"sonarlint.connectedMode.project": {
"projectKey": "SampleAngularApp"
},
"sonarlint.ls.javaHome": "C:\\Program Files\\Java\\jre1.8.0_291",
"sonarlint.connectedMode.connections.sonarqube": [
{
"serverUrl": "http://sonarqubece.abcd.com:443",
"token": "51df88dd4ea115f9f6afd7a5f457859b1d24b9f2"
}
]
}

Now hit Ctrl+Shift+P (Windows/Linux) or Shift+Command+P(Mac) to open the Command Palette, and type inSonarLint to bring up the SonarLint commands and run “SonarLint: Update all bindings to SonarQube/SonarCloud”. If any changes are made on the SonarQube server you should repeat this step.

SonarLint in Visual Studio Code 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 time needed for code checks.

Token Generation in SonarQube:

Navigate to SonarQube Dashboard page. Administration > Security > Tokens

Java JRE Path setting in Visual Studio Code:

--

--

Dijin Augustine

I have 16 years of experience in the industry and currently serves the role of a Solution Architect. I am a self taught technology enthusiast in .NET Technology