How to exclude folders from sonarlint scan

Hi,

I’d like to exclude some folders from sonarlint in vscode. I couldn’t figure out how to configure it. Any help?

Chaoran

Hello, welcome to the community! And thank you for your question.

As far as I can tell, this feature is completely missing from SonarLint for VSCode (although it exists in some form in other IDEs).

I moved your post to the “New features” category so that other users can vote for it and give us additional insights.

In your particular case, what kind(s) of folder(s) would you want to exclude from analysis?

Hi,

I would like to exclude the target/ folder from SonarLint, which contains code that is auto-generated by tools e.g. Protobuf and JOOQ.

Thank you for the additional details!

Are you using Maven, or maybe Gradle? I believe that in such a case, SonarLint should be able to query the project configuration from the build tool and automatically exclude the target directory.

Please also note that in recent versions of SonarLint for VSCode, and if you are using git, files matched by the .gitignore shouldn’t be analyzed either; and depending on your project context, one could consider that generated files should be ignored by the SCM anyway.

2 posts were split to a new topic: SonarLint for Visual Studio - scan all files in a folder or project

How is this feature coming along?

I want to ignore a third-party library which is not ignored by git because we need the SCM. But we don’t want to improve that codebase ourselves.

Hello @Tmiple,
adding a file/directory filter is a feature that makes sense to us for SonarLint in VSCode. We’ll probably add it at some point - but keep in mind it is not at the top of our priorities at the moment.
In the meantime, if you analyze your project with SonarQube or SonarCloud, you can exclude your third-party library folder and use SonarLint in connected mode - this way it will sync and apply your SonarQube/SonarCloud configuration including directory exclusions.

When will this feature become a priority for you? I find it quite nerving that sonarlint keeps analyzing third-party libraries. You could simply ignore all files in .gitignore. This is a quick-win solution

Bumping for another vote for this feature

And as a temporary workaround you can add the folder(s) to the excluded files for a workspace and then use the Filter button on far left of the Problems tab. It will still show the # of problems including the excluded files but the list will only be for what you care about. The potentially negative side effect is that the files will also be excluded from the sidebar and from the file selection popup dropdown.

.vscode/settings.json

{
"files.exclude": {
    "**/target/**": true
}
}

Screenshot 2023-04-05 at 10.38.05 AM

i’d need to exclude swig generated files like the wrapper files and also generated JNI Files.
This is a really needed feature for me

Hello @Vorian.Atreides85 and welcome to the Sonar Community forum!
There are decent chances we’ll manage to prioritize for the second part of this year a feature to enable SonarLint users not using SonarQube or SonarCloud to configure file/directory exclusions. I suggest you to subscribe to this card in the SonarLint roadmap page to automatically receive any updates on the topic.

I’m using Visual studio 2022, but I couldn’t manage to exclude specific folders from being analyzed. I’m not connected either to sonarqube server. is directory execlusions are not supported there also?
I tried to create sonar-project.properties file with the following configurations but with no luck

Snippet

sonar-project.properties

sonar.exclusions=/Migrations//*