Running an analysis
Now that you've installed SonarLint in your IDE, running an analysis is straight-forward. For the most part, new analyses are automatically triggered when you open a file, as you type, or with each file save following a change in the code. Below we've outlined other ways to trigger a SonarLint analysis.
By default, new analyses are automatically triggered as you type, following a change in the code. You can disengage automatic analysis by going to IntelliJ Settings > Tools > SonarLint; in the Settings tab, deselect Automatically trigger analysis.
There are additional ways to trigger a SonarLint analysis in IntelliJ:
- On the Fly (default): When the file is autosaved or manually saved. Issues found during the analysis are highlighted in the SonarLint view window under the Current file tab.
- On-Demand: Single files can be analyzed by right-clicking over a file in the project tree, then selecting SonarLint > Analyze with SonarLint. You can also click the green arrow in the sidebar of the SonarLInt View window or, analyze all project files by right-clicking in the explorer window and selecting Analyze with SonarLint. At any time you can use the keyboard shortcut Cmd+Shift+S/Ctrl+Shift+S on your Mac/Windows machine to analyze all project files.
- By selection: Use this method to get feedback on issues found in a set of files. Select one or more files in the Project Tree, then right-click > SonarLint > Analyze with SonarLint. The Report tab will open automatically in the SonarLint view window where you can view issues found in multiple files. Note that you can also click the Analyze All Project Files button from the Report tab, without having to select them from the Project Tree.
It is possible to trigger an analysis on demand by clicking the green arrow in the sidebar of the SonarLint view window; conversely, there is a Cancel SonarLint Analysis button shown in red. Also, the Current file tab offers a shortcut to the Project Settings and a Clear SonarLint Issues button to help manage the report of issues.
SonarLint for IntelliJ allows you to complete an analysis of all project files and an option to review issues found in other files without having to open them.
From the Report tab of the SonarLint view window, click on the Analyze VCS Changed Files button to analyze files that are not yet committed but have changed since the last commit.
In addition to right-clicking on the project folder to select SonarLint > Analyze with SonarLint, you can click on the folder icon in the left toolbar of the SonarLint view window to Analyze All Project Files. Likewise from the explorer window, entering the keyboard shortcut Cmd+Shift+S/Ctrl+Shift+S on your Mac/Windows machine will trigger an analysis on all project files and automatically open the Reports tab to view the report.
In addition, it’s possible to limit the analysis by excluding files. Go to IntelliJ Settings > Tools > SonarLint > File Exclusions to define an exclusion pattern. More details about File exclusions can be found here.
© 2015-2023, SonarSource S.A, Switzerland. Except where otherwise noted, content in this space is licensed under the GNU Lesser General Public License, Version 3.0. SONARLINT is a trademark of SonarSource SA. All other trademarks and copyrights are the property of their respective owners. See SonarSource.com for everything you need to know about the Sonar Solution.