How exclude files from analysis and include on the same folder?

javascript
scanner
csharp
exclusions
vsts

(Felipe Oriani) #1

Hey guys. It is my first time using SonarQube and I am running it from prompt and Azure DevOps (VSTS Build). Both works fine and the results are great. Our project is based on C# .Net Framework. Our front-end project, which is an asp.net mvc project, we have a following structure for javascript files:

  • Content
    • js
      • jquery (some js files inside this folder)
      • jquery.validation (some js files inside this folder)
      • kendo.ui (some js files inside this folder)
      • jquery (some js files inside this folder)
      • … (other components folders here)
      • widgets (some js files inside this folder)
      • site.js
      • app.js
      • main.js

And for css we have a similar structure.

I want to analysis with SonarQube just the folder widgets and root files on the js folder (the bold ones). We want to ignore these components folders (jquery, kendo, etc…) and evaluate just our code. To do this, I know we have sonar.exclusions and sonar.inclusions arguments we can use but I don’t know how configure them.

sonar.exclusions=**\bin\**,**\OurProject.Web\Reports\**,**\Content\js\**
sonar.inclusions=**\Content\js\*.js,**\Content\js\widgets\*.js

But it does not work. It just ignore all files inside js folder. How can I ignore the components and how can I scan the bold ones? I was thinking to add folder by folder on the sonar.exclusions but is there any easy way to do this?

I have the same structure for css files and the same solution here will be applied to the css files as well.

Versions:

  • SonarQube 7.5 Community Edition
  • SonarC# Plugin 7.10.0.7896
  • Scanner for MSBuild 4.5.0.1761-net46

(G Ann Campbell) #2

Hi,

Generally you don’t use exclusions and inclusions together. You might want to review the “Ignoring Files” section of this doc, but if all you want to analyze in this entire project are the files in widgets plus site.js, app.js, and main.js then set only inclusions, like so:

sonar.inclusions=**/Content/js/*.js,**Content/js/widgets/**/*.js

 
HTH,
Ann


(Felipe Oriani) #3

Thank you @ganncamp, you’re great.

Just a last question. If I keep the sonar.inclusions argument like this, will it analyse just theses files on inclusions and ignore all the rest of files like .css, .cs, .html, etc?

Maybe in this case I think I have to use sonar.exclusions to remove files (folder by folder).


(G Ann Campbell) #4

Hi,

It looks like you’re getting the hang of this! :wink:

If you did actually want to include all those other languages, then exclusions might be easier after all.

 
Ann