Not using sonar.exclusions but getting deprecation warning

When checking analysis from Azure DevOps builds (.NET + Typescript) I got that message at top right corner saying there are warnings in last analysis:

Specifying module-relative paths at project level in the property ‘sonar.exclusions’ is deprecated. To continue matching files like ‘web-client/src/app/s/p.service.spec.ts’, update this property so that patterns refer to project-relative paths.

However, such file only matches patterns provided in sonar.test.inclusions and sonar.coverage.exclusions;

In task Prepare Analysis Configuration, sonar.coverage.exclusions is set using extra properties, along others, this is the output from the build:

sonar.coverage.exclusions=**/*Migrations/**,**/*Test/**,**/*Tests/**,**/environments/environment*.ts,**/*.conf.js,**/src/main.ts,**/lib/h/*.s.ts,**/src/polyfills.ts,**/src/test.ts,**/lib/h/*.s.ts,**/lib/e/*.e.ts,**/lib/m/*.m.ts,**/e2e/src/app.e2e-spec.ts,**/e2e/src/app.po.ts,**/*.spec.ts,**/app-config.ts,**/*.interface.ts,**/a/*.s*.ts,**/C.cs,**/S.cs,**/*.t.ts
sonar.coverageReportPaths=d:\a\_temp\CodeCoverage\Merged\SonarQube.xml
sonar.exclusions=**/coverage-include-all.spec.ts,**/TestResultJunit/*.xml,no_extra_exclusion_but_a_value_is_needed_after_comma
sonar.tsql.file.suffixes=.sql,.tsql
sonar.plsql.file.suffixes=.plsql,.pkb

The .csproj containing the file mentioned in the warning is at d:\a\753\s\web-client:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
      <TargetFramework>netstandard2.0</TargetFramework>
      <DefaultItemExcludes>**/*.*</DefaultItemExcludes>
    </PropertyGroup>
    <ItemGroup>
      <None Include="d:\a\753\s\web-client\**" Exclude="d:\a\753\s\**\node_modules\**;d:\a\753\s\**\.*\**;d:\a\753\s\web-client\dist\**;d:\a\753\s\web-client\coverage\**;d:\a\753\s\web-client\TestResultJunit\**" />
      <SonarQubeSetting Include="sonar.test.inclusions">
        <Value>**/*.spec.ts,**/*.spec.js,**/*.mock.ts,**/*.mock.js,**\\web-client\\src\\app\\test-helper\\*.*</Value>
      </SonarQubeSetting>
      <SonarQubeSetting Include="sonar.tests">
        <Value>d:\a\753\s\web-client</Value>
      </SonarQubeSetting>
    </ItemGroup>          
  </Project>

MSBuild goes fine, project is correctly categorized as MAIN. It contains an angular website.

In Run Code Analysis task, I can see the warning at the beginning already:
The warning also appears in this output, but at the begining:

INFO: Organization key: orgkey
INFO: Branch name: aa, type: short-lived
INFO: Preprocessing files...
WARN: Specifying module-relative paths at project level in the property 'sonar.exclusions' is deprecated. To continue matching files like 'web-client/src/app/s/p.service.spec.ts', update this property so that patterns refer to project-relative paths.
INFO: 
INFO: 9 languages detected in 99 preprocessed files
INFO: 999 files ignored because of inclusion/exclusion patterns

And later I can then see project related output:

INFO: Indexing files of module 'WebClient'
INFO:   Base dir: D:\a\753\s\web-client
INFO:   Source paths: .editorconfig, .gitignore, .npmrc, angular.json, WebClient...
INFO:   Test paths: .
INFO:   Excluded sources: **/build-wrapper-dump.json, **/coverage-include-all.spec.ts, **/TestResultJunit/*.xml, no_extra_exclusion_but_a_value_is_needed_after_comma, **/*.spec.ts, **/*.spec.js, **/*.mock.ts, **/*.mock.js, **\\web-client\\src\\app\\test-helper\\*.*
INFO:   Included tests: **/*.spec.ts, **/*.spec.js, **/*.mock.ts, **/*.mock.js, **\\web-client\\src\\app\\test-helper\\*.*
INFO:   Excluded sources for coverage: **/*Migrations/**, **/*Test/**, **/*Tests/**, **/environments/environment*.ts, **/*.conf.js, **/src/main.ts, **/lib/h/*.s.ts, **/src/polyfills.ts, **/src/test.ts, **/lib/h/*.s.ts, **/lib/e/*.e.ts, **/lib/m/*.m.ts, **/e2e/src/app.e2e-spec.ts, **/e2e/src/app.po.ts, **/*.spec.ts, **/app-config.ts, **/*.interface.ts, **/a/*.s*.ts, **/C.cs, **/S.cs, **/*.t.ts

In it I can see test inclusions were also taken as excluded sources, what seems to trigger the warning, so such warning would not be caused by something I’m directly doing.

At the same time, the pattern matching that file is **/*.spec.ts what perfectly describes what I really want, any file with extension .spec.ts is a test file doesn’t matter where it is.

According to the warning, I should change such pattern to be project-relative, but I’m not sure what that really means, tried following but none worked completely:

  • */**/*.spec.ts - still got warning
  • src/**/*.spec.ts - still got warning
  • ./**/*.spec.ts - no warnings, but file was not considered a test file, so the pattern didn’t work
  • d:/a/753/s/web-client/**/*.spec.ts - no warnings, but file was not considered a test file, so the pattern didn’t work
  • despite not really the pattern involved in warning, I changed **\\web-client\\src\\app\\test-helper\\*.* to src/app/test-helper/*.*

Is this warning really correct in this scenario? If so what should I use as a pattern to get my test files taken as tests and no warnings?

Hi,

Thanks for this ping.

In fact, you’re correct and this is nothing you’re doing. SonarScanner for .NET is generating that configuration under the covers, and we need to get that cleaned up. I’ll flag this for team attention.

 
Ann

Hello @Luiz_Soares,

Thank you for reporting this issue.

As @ganncamp said, what you are doing is not wrong. There are things that need to be cleaned up.
I have created a ticket in our backlog to focus on this particular issue.

Although the warning mentions sonar.exclusions, your particular issue is because of the sonar.test.inclusions property used to fill the exclusions, as you guessed.

In the meantime, to remove the warning, what you can do, is to remove the sonar.test.inclusions from your csproj and add it as an extra property in your pipeline.
This should remove the warning.
Let me know if it works for you.

Have a nice day,

Thanks Sebastien.

We ended up using project specific properties, because setting that at the pipeline was causing issues with test code detection for actual .NET code/projects.

The project I shared is only used to make the angular/frontend folder/project visible to Sonarcloud running in ‘MSBuild mode’ and enable us to analyze both typescript and .NET in one go.

I don’t have the details anymore of the issues I faced when setting it up.

If there are no risks for this files stop being classified as test files, I could live with this warning for a while.

Thanks,

Luiz

~WRD0000.jpg