Improve Code Quality using SonarLint Eclipse IDE Plugin

While developing applications, it is essential to maintain good code quality and follow the coding best practices. Application with good quality code is easier to maintain in the future. SonarLint is an open-source code quality analyzer IDE extension that helps us maintain the code quality while writing the code on IDE. SonarLint eclipse plugin is a free plugin that we can add to our Eclipse IDE.

In this article, we will see the Advantages and how to use the SonarLint plugin on Eclipse and how to use it to analyze the quality of the code we write. Let’s first see the advantages of using code quality analyzer tools like the SonarLint plugin.

Table of Contents

Advantages of using a code quality analyzer

  • Makes sure that the developers follow the coding best practices and write in the right way.
  • Reduces the time taken for the manual code review process as the plugin guarantees the basic code quality and coding best practices.
  • Increases the code quality and productivity of the developer.
  • Forces the developer to make use of the common coding best practice. Since SonarLint provides inline suggestions, the developer can modify the code easily while writing on the IDE itself.
  • SonarLint provides suggestions for the bug/ issues/ coding best practices, along with descriptions and examples.
  • We can disable or enable the SonarLint Rules at any time. We can also enable/disable the plugin entirely at any time or for a particular project.

Adding SonarLint plugin to Eclipse IDE

We can add the SonarLint plugin to Eclipse in two ways.

By visiting the Eclipse marketplace and then by drag and drop the install button to eclipse IDE.

The second way is by navigating the following options on the Eclipse toolbar: Help > Eclipse Marketplace. We get the marketplace search window as shown below.

Under the search menu or search window, search for the SonarLint plugin. Once the SonarLint plugin appears on the search result, click on the install button.

sonarlint eclipse plugin

Analyze the code using SonarLint

We have successfully added the SonarLint plugin to our Eclipse IDE. Now we can analyze our code.

We can analyze the code on the project level or individual file level. To analyze project/ specific file, right-click on file/project > SonarLint > Analyze.

Following is a sample SonarLint result of simple Java code with an issue report, description, and suggestions.

sonar lint eclipse plugin

Disabling SonarLint for particular file of a project

We can disable/enable SonarLint from analyzing code for particular files by right-clicking on the file we want to exclude > SonarLint > Exclude.

We can also do this by right-clicking on project > Properties > Navigate to SonarLint > File Exclusions, and add the list of files to exclude.

Click on the Apply button and then the OK button to save the settings.

Deleting issues report on Eclipse

sonarLintReport

After analyzing the code, we get an issue report, as shown above.

We can clear the report by selecting issues to delete and then right-click on issues report > delete.

We can generate the report again by analyzing the file or the project again.

How to enable/disable rules on eclipse

We can choose which are the rules should apply for analyzing the file/ project.

To view the list of all the available SonarLint rules, navigate to Window > Preferences > SonarLint > Rules Configuration.

Here we can also enable/disable the rules to consider for analyzing the code.

SonarLintRulesConfig

We can also deactivate individual rules by hovering on the highlighted error warning, as shown below.

SonarLintDeactivate Rule

Conclusion

SonarLint is a good code analyzer tool that helps maintain the quality of the code. SonarLint is also available for other IDE’s like Visual Studio, IntelliJ IDEA, etc., and we can use it to analyze program languages like Java, Javascript, PHP, Python, etc.

Visit the official website and try its cool features.

In this article, we learned about the SonarLint Eclipse IDE plugin and how to use it to analyze the code quality.

Improve Code Quality using SonarLint Eclipse IDE Plugin
Scroll to top

Discover more from ASB Notebook

Subscribe now to keep reading and get access to the full archive.

Continue reading