1

Using SonarQube 9.6.0,

I have a file frontend/frontendUI/src/services/mock-data.ts that contains, as per its name, a lot of quick-and-dirty mock data, which does not really make any sense or confirms to particular styles.

I'd like to skip SonarQube analysis of this file - and indeed, of a few other files also named "mock-*".

To that end, I found this corresponding section of the manual:

Project level

Project Settings > General Settings > Analysis Scope > A. File Exclusions

  • Source File Exclusions: One or more wildcard patterns defining which files are filtered out from those defined by sonar.sources. This can also be set in a configuration file using the key sonar.exclusions.

On the screen, where I can do this, this is the displayed wildcard definition:

You can use the following wildcards. [...]
* Match zero or more characters
** Match zero or more directories
? Match a single character

I went ahead and tried the following variants of entry:

  • **/mock-* - This one would be ideal.
  • **/mock-data.ts
  • frontend/frontendUI/src/services/mock-data.ts - This is copied straight from a report in the file.

Each time I re-ran the analysis after saving it. But none of them work - the previously reported issues remain.

Looking into my Scanner Scope, I see that the entered values have been applied successfully, though. Here are relevant values (as far as I can tell) of my second try:

Project server settings:
- sonar.exclusions=**/mock-data.ts,frontend/frontendUI/src/services/mock-data-backend-service.ts
Project scanner properties:
- sonar.exclusions=**/*pb.go,**/dist/**
- sonar.inclusions=**/*.go,**/*.ts
- sonar.sources=gocode,frontend

... Now, I tried instead to use the configuration "Ignore Issues on Multiple Criteria":

  • Rule Key Pattern: *
  • File Path Pattern: **/mock-* (the ideal pattern from above)

This time, after rerun all previous reports in that file (and the others starting with "mock-") have vanished as expected!

Although this presents a viable workaround, I would rather use the intended tool.

How do I correctly use "Source File Exclusions"?

Zsar
  • 233
  • Unfortunately I had to select one tag, but did not find any one that seemed to match. If someone with more Rep could please create a "SonarQube" tag? There are several SonarQube-specific questions on this page, so it might be the most fitting. Any other tag correction/suggestion also welcome. – Zsar Oct 07 '22 at 11:52

0 Answers0