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