Finding bugs and quality issues as you code in your favorite IDE with SonarLint

Everyone like a good code with as less bugs as possible, right?

We programmers are hired to solve problems, not to create more(bugs, vulnerabilities, etc…). In addition, because of this we have to worry about potential problems as we code.

Having Continuous Integration (Jenkins, Travis, etc..) and Continuous Code Quality (SonarQube, etc..) are very important to maintain a high standard of quality. But with SonarQube for example, you only see the potential code issues( Bugs, Vulnerabilities, Code Smells) after with you send the changes to the platform.

In the ideal world, we should worry and see the potential issues as we write the code, not after it. And that’s where SonarLint( from SonarQube) enters.

It helps showing the issues on-the-fly, meaning that right after you type the code, SonarLint can warn you.

Source: SonarLint

SonarLint lists issues found in all the files that you added and updated.

Source: SonarLint

In addition, it also provides help on the issues, indicating how to fix them.

Source: SonarLint

 

SonarLint has plugins for most commons IDEs: IntelliJ IDEA, Eclipse, Visual Studio, VS Code and Atom.

You can check it here: https://www.sonarlint.org/

How to Install SonarLint Plugin on IntelliJ IDEA

I will show you how to setup and get started. I will do this using SonarLint for IntelliJ IDEA as I have used it with Android Studio.

Install the Plugin

The setup process is very easy. you just have to install the SonarLint Plugin and get started. I will describe the steps for you:

Go to File -> Settings(in Android Studio for Windows)

GetImage (1)
Settings

Go to Plugins(1) -> Search for SonarLint(2, 3) -> click in Install(4).

GetImage.png
Installing SonarLint Plugin

After installing the plugin, you will be asked to restart Android Studio. After the restart, you will be able to start using it.

 

Using SonarLint

The nicest thing about it is that it works as Android Lint. It warns you directly on the code as type it.

GetImage (3)
On-the-fly example

A tab will also be added to your bottom toolbar. When you open, it will open the Current File Analysis.

GetImage (2)
Botton bar tab

The analysis by default automatic but you can re-run it anytime clicking in the green run button.

 

When selecting an issue, in the right part of the tab will be shown more information on the issue, like the rule it’s breaking, the Noncompliant code example and the Complaint Code Example.

GetImage (4)
Detail of the issue
GetImage (5)
Noncompliant Code Example
GetImage (6)
Compliant Solution

This is very similar(or equals) with what you will see on the SonarQube server, but the good part is that it points directly to your code.

 

Connecting to your SonarQube Server.

You can also connect to your SonarQube Server to be able to use the same rules and other configurations from the server.

To do that, go again in the Settings Screen-> SonarLint General Setting and Click in the Add button

Untitled picture
Adding Server Link

Now you have two options. SonarCloud or SonarQube. I will show with SonarQube.

Untitled picture1
Defining Server Details

Just select SonarQube and type your server Address. Wait for the synchronization.

Go to SonarLint Project Settings and select your project.

Untitled picture2
Selecting the project in the server

 

That’s it! Enjoy coding with more quality 😉

 

Disclaimer: I have no relations with SonarLint. I just use it and find it very nice and useful.

Source: SonarLint

Cheers,

João Luiz Vieira

 

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

w

Connecting to %s

Create a website or blog at WordPress.com

Up ↑

%d bloggers like this: