Line of Code limit when sonar.exclusions not working

We have a project that has a massive 3rd party library in it which eats up hundreds of files and thousands of lines of code. This 3rd party library code is in our wwwroot folder (which has subdirectories for javascript and css files).

I have tried to set the wwwroot file as excluded multiple ways.

  1. In the UI under Project > General Settings > Analysis Scope > Source File Exclusions:
    **/*MyProjName/Web/wwwroot/**/*

I have also tried other versions of this syntax: **/*MyProjName/Web/wwwroot/**/*.*
and with the key of sonar.exclusions=**/*MyProjName/Web/wwwroot/**/*

  1. I understand that there are global analysis under Administration > Configuration > General Settings > Analysis Scope and I have attempted to duplicate the syntax there under Source File Exclusions.

  2. In the Azure DevOps build definition in the sonarQube prepare task I have:

- task: SonarQubePrepare@4
  inputs:
    SonarQube: 'MyProj'
    scannerMode: 'MSBuild'
    projectKey: 'MyKey'
    projectName: 'MyProjName'
    extraProperties: 'sonar.exclusions=**/*MyProjName/Web/wwwroot/**/*, sonar.coverage.exclusions=**/*MyProjName/Web/wwwroot/**/*'

In the ANALYSIS log, I see it recognizes the exclusions:

INFO: Project configuration:
INFO:   Excluded sources: **/*MyProjName/Web/wwwroot/**/*, sonar.coverage.exclusions=**/*MyProjName/Web/wwwroot/**/*

And yet, later down the line in the analysis log, it says:

INFO: 535 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: 32 files ignored because of scm ignore settings

Which is causing me to break my license limit on the publish task.

My Project Info says I only have 9.6K lines of code.

Further, under Administration > System, I only have 61k lines of code (our license is for 500k LOC).

Lines of Code 61,433

Any idea what’s wrong with the syntax?

Hi @Josh ,

Welcome to SonarSource Community! :sonarsource:

I was able to reproduce the behavior you are seeing. Can you try setting your YAML like so?

- task: SonarQubePrepare@4
  inputs:
    SonarQube: 'MyProj'
    scannerMode: 'MSBuild'
    projectKey: 'MyKey'
    projectName: 'MyProjName'
    extraProperties: |
      sonar.exclusions=**/*MyProjName/Web/wwwroot/**/*
      sonar.coverage.exclusions=**/*MyProjName/Web/wwwroot/**/*

Notice that I created separate lines for each of my Sonar analysis parameters. You had originally concatenated 2 different parameters into one line, which will not work properly.

Let me know if that works for you or not.

Joe

Hi @Joe. Yes, I tried this but 0 files get ignored.

I did notice that other folder paths, it seems to pick up and ignore, but with the Web/wwwroot folder path, the exclude acts like it can’t see any files inside the Web folder at all.

Can you add a command line task to output the tree structure of your project? Something like this: Azure Pipelines - Is there a way to view the folder structure? - Stack Overflow

Or you can take a screenshot of your project so I understand where the folders are at. You can use a glob tool like this one to test if the exclusion finds the right folder/file path.

Solution

  • MyProject
    • Client
    • Data
    • Data.WebAPI
    • Server
    • Service
    • Shared
    • Web
      • Controllers
      • Data
      • Extensions
      • Helpers
      • Hubs
      • Pages
      • Shared
      • ViewModels
      • wwwroot
        -css
        -images
        -js
        -devExpress

I need to exclude everything in wwwroot (the DevExpress library kills our LOC limit). But the paths don’t seem to see anything in the Web folder. I should also add that this is running on a VM server with a self-hosted agent so actual paths are like D:/agent_99/work/r3/…

Please try this:

sonar.exclusions=**/wwwroot/**
INFO: Indexing files of module 'MyProject.Web'
INFO:   Base dir: D:\_agent1\_work\4\s\MyProject\Web
INFO:   Excluded sources: **/wwwroot/**
INFO: Indexing files of module 'xyzkey'
INFO:   Base dir: D:\_agent1\_work\4\s
INFO:   Excluded sources: **/wwwroot/**
INFO: 517 files indexed
INFO: 0 files ignored because of inclusion/exclusion patterns
INFO: 31 files ignored because of scm ignore settings

Can you add sonar.verbose=true and share your logs in a txt file attachment?

My company wouldn’t let me copy/paste everything, is there something in particular you’re looking for I can pull out and anonymize if necessary?

Problem solved! The exclusion should have been set for sonar.test.exclusions, not sonar.exclusions since the wwwroot/ folder was considered a test source:

    extraProperties: |
     sonar.test.exclusions=**/wwwroot/**
     sonar.verbose=true

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.