How to get the most out of SonarLint?
You just need Java 8 (JRE). Install SonarLint like any other extension, directly in your IDE, from the Eclipse Marketplace or from SonarLint for Eclipse Repository. You can also download it directly from here. Once installed, SonarLint is enabled by default.
Analyze your code
There’s nothing to do! Analysis is automatically triggered when you open a file and when you save an updated piece of code. Issues are highlighted in the editor as well as listed in the “SonarLint On-the-fly” view.
We think the best way to improve the quality of your code is to fix issues as you add / update the code. Nevertheless, if you want to disable on-the-fly analysis, right click on the Eclipse project, open project properties, select “SonarLint” and uncheck “Run SonarLint automatically”.
You can manually run an analysis on a single file, all the files you’ve modified, or even all files in the project to get a first impression of the quality of your project(s). To do so, you can use the context menu at file, project or working set level.
This operation will make SonarLint use the code analyzers, quality profiles and settings defined for your project on SonarQube or SonarCloud. SonarLint will also hide in your IDE the issues that are marked as Won’t Fix / False Positive on the server. You can connect SonarLint with SonarQube server >= 5.6.
- First, configure the connection to the SonarQube server:
- In the “SonarQube Servers” view, right click and choose “New” > “Server connection”, or in the “File” menu, select “New” > “Other…” > “SonarLint” > “New Server”.
- Choose the server you want to connect to: SonarCloud or a SonarQube instance, and step through the wizard to provide your credentials and other connection details.
- Once the connection is defined, you can bind the Eclipse project to the corresponding SonarQube project:
- Right click on the Eclipse project and choose “SonarLint” > “Bind with remote SonarQube server…”
- Select your server and choose the relevant SonarQube project or use the “auto-bind” feature, which will find the best match based on the project name. If the automatic binding fails, you can manually search for a project.
That’s it, you can now code and see SonarLint issues based on your remote SonarQube configuration. You will be notified on a daily basis if the SonarQube configuration has changed. To manually trigger an update of the local configuration, right click on a server and choose “Update all project bindings”.
SonarLint supports the SonarSource code analyzers (SonarJava, SonarJS, …) as well as custom rules that extend those analyzers. SonarLint doesn’t support plugins running third-party analyzers.
When your project is connected to SonarQube, you can configure rules on the server. When the project is not connected, SonarLint uses the rules in the default quality profiles.
If you feel that a rule isn’t valuable for you, please report it in the SonarLint Google Group. We’d like to everyone to have the best out-of-the-box experience, so we might tune such a rule or disable it by default.
File and issue exclusion
When your project is connected to SonarQube, you can configure files and issues exclusions on the server. By default, all the files in an open project that are written in recognized languages are analyzed. Derived files are automatically excluded.
The way SonarLint issues are displayed can be changed in Eclipse preferences. By default, issues are reported with the info marker, but that can be changed in “SonarLint” menu, with the “Severity of SonarLint markers” drop-down. Also, the highlighting of issues and issue locations can be customized in “General” > “Editors” > “Text Editors” > “Annotations”.
The SonarLint console can be useful to understand some technical issues. You can open it from the Eclipse Console view. By default, the SonarLint console displays a few logs, but you can enable analysis logs and verbose logs.
How to contribute?
SonarLint for Eclipse is open source under the LGPL v3 license. You can fork us on GitHub, and submit Pull Requests. Feel free to fix bugs or to implement new features.