In Python we can suppress all Sonarqube warnings at a particular line in the code by applying the # NOSONAR
comment. This is not ideal. Is there a way to suppress a specific error, instead of supressing all errors?
For example, you may have a function with two warnings:
Function "foo" has 8 parameters, which is greater than the 7 authorized.
Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed
How can you suppress the first, but not the second?
This is a workaround if you are using Jenkins, that isn't perfect. It can be used to suppress a specific warning for an entire file (instead of just one function).
In the Jenkins property file add something like:
sonar.issue.ignore.multicriteria=e1
sonar.issue.ignore.multicriteria.e1.ruleKey=python:S107
sonar.issue.ignore.multicriteria.e1.resourceKey=path/to/file.py
Where python:S107
is the rulekey for a function having more than 7 parameters, and path/to/file.py
is the file you want to suppress this specific rule for. Unfortunately it will supress it for the entire file, as opposed to the specific function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With