What is Sonarlint? How to add Sonarlint in Eclipse?

By | December 11, 2023

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.

Sonarlint in Eclipse
Fig 1- Eclipse Marketplace

In the Eclipse Marketplace, we need to search for the Sonarlint plugin, and we will install it in our IDE.

Eclipse Marketplace
Fig 2- Sonarlint plugin

After we click on install, it will ask for a license review.

Fig 3- License Review

Once we finish the license review, it will ask for truthful authorities.

Sonarlint plugin
Fig 4- Trust Authorities

After we give trust to the Sonarlint plugin, our installation will gets completed and the Eclipse IDE will ask for a reboot.

Fig 5- Reboot

2. How to use Sonarlint in Eclipse

In order to use Sonarlint in Eclipse, we need to goto Project Root Directory > Sonarlint > Analyze.

How to use Sonarlint in Eclipse
Fig 6- How Sonarlint works

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.

Fig 7- Sonarlint analysis report

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.

Fig 8- Sonarlint rule description

After we click on Open, it will open a new window for the Sonarlint Rule Description.

Fig 9- Sonarlint rule description window

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.
Sonarlint Rule Description
Fig 10- Sonarlint Rule Description

We can switch between different tabs to see the issue, fix it, and get more information related to the issue.

Leave a Reply

Your email address will not be published. Required fields are marked *