Sonarlint by Sonar is a free extension for our development environments that covers all the most popular programming languages. Like spell checker, Sonarlint squiggles coding issues and performs on-the-fly analysis to detect common mistakes, tricky bugs, and security vulnerabilities. Along with this, it also teaches us clean coding practices. This way, it helps us spend less time on fixes and more on our business requirements.
1. How to add Sonarlint in Eclipse
In order to use Sonarlint, we need to install the Sonarlint plugin in our Eclipse IDE. We will be using Eclipse Marketplace for downloading and installing the Sonarlint plugin.
Sonarlint Eclipse Plugin
We need to first add Sonarlint to our Eclipse IDE. For this, we will go to Eclipse > Help > Marketplace and search for Sonarlint.
In the Eclipse Marketplace, we need to search for the Sonarlint plugin, and we will install it in our IDE.
After we click on install, it will ask for a license review.
Once we finish the license review, it will ask for truthful authorities.
After we give trust to the Sonarlint plugin, our installation will gets completed and the Eclipse IDE will ask for a reboot.
2. How to use Sonarlint in Eclipse
In order to use Sonarlint in Eclipse, we need to goto Project Root Directory > Sonarlint > Analyze.
Once Sonarlint completes its analysis, it will show all the files along with the suggestions required to enhance the coding practices to meet the enterprise requirements. Below, we can see it has given suggestions to improve our codebase.
3. Sonarlint Rule Description
In the above Sonarlint Report, we can see in EmployeeController.java, Sonarlint is suggesting to “remove this field injection and use constructor injection instead.” If we want to see what the exact rule is to write those codes, we can check it out in the Sonarlint rule description. For this, we need to go to Eclipse > Windows > Show View > Other, search for Sonar, and select Sonarlint Rule Description and click on Open.
After we click on Open, it will open a new window for the Sonarlint Rule Description.
In order to use the Sonarlint rule description, we need to select any issue in the Sonarlint Report and switch to the Sonarlint Rule Description, which will show:
- Why is this an issue?
- How can I fix it?
- More Info.
We can switch between different tabs to see the issue, fix it, and get more information related to the issue.