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.
SonarLint lists issues found in all the files that you added and updated.
In addition, it also provides help on the issues, indicating how to fix them.
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)
Go to Plugins(1) -> Search for SonarLint(2, 3) -> click in Install(4).
After installing the plugin, you will be asked to restart Android Studio. After the restart, you will be able to start using it.
The nicest thing about it is that it works as Android Lint. It warns you directly on the code as type it.
A tab will also be added to your bottom toolbar. When you open, it will open the Current File Analysis.
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.
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
Now you have two options. SonarCloud or SonarQube. I will show with SonarQube.
Just select SonarQube and type your server Address. Wait for the synchronization.
Go to SonarLint Project Settings and select your project.
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.
João Luiz Vieira