How to use SonarLint and Sonar Qube to lint only staged files locally before creating a Pull Request

How to use SonarLint and Sonar Qube to lint only staged files locally before creating a Pull Request.

I need to be able to run SonarLint on all my staged files before creating a PR.
I’m using IntelliJ and the SonarPlugin. We have sonarcloud configured with our rules.

Hello Timothy,

In SonarLint for IntelliJ, I don’t think this exact feature - analysis of staged files only - will be supported. However, I see 2 options that can help with your use case:

  • In the “SonarLint” tool window, on the “Report” tab, you should find the “Analyze VCS Changed Files” action, which will let you analyze all files changed since last commit (both staged and unstaged)
    SL-analyze-VCS
  • If you use IntelliJ’s VCS integration, the “Commit” window has a checkbox in the “Before Commit” section to trigger a SonarLint analysis before the commit is actually saved
    SL-commit-analysis

Hope this helps, happy hacking!