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 keysonar.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.tsfrontend/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"?