Ignore SonarQube warnings in python

Question:

How can I ignore SonarQube warnings in Python code

In Java, I can use

@SuppressWarnings("squid:S1166")

Where the ID is the SonarQube rule ID. But what syntax should I use in Python?

I’ve tried

# noinspection python:S1313

but it didn’t work.

To be clear, I’m looking for a solution in python code. NOT JAVA.

Asked By: Daniel Scott

||

Answers:

I believe the only syntax supported for Python (assuming it is supported) is the NOSONAR comment, so #NOSONAR or # NOSONAR at the end of the line where you want to ignore issues.

Unfortunately, this is a global issue suppression: it kills all issues on the line, not just those from a specific rule.

If you are using a sonar.properties file, you can set it up to ignore some specific rule on a given file or set of files.

Here is an example where you ignore different rules on differents files:

# Name your criteria
sonar.issue.ignore.multicriteria=e1,e2

# python:S3776 : Cognitive Complexity of functions should not be too high
sonar.issue.ignore.multicriteria.e1.ruleKey=python:S3776
sonar.issue.ignore.multicriteria.e1.resourceKey=src/my_project/complexe.py

# python:S117 : Local variable and function parameter names should comply with a naming convention
sonar.issue.ignore.multicriteria.e2.ruleKey=python:S117
sonar.issue.ignore.multicriteria.e2.resourceKey=src/my_project/**/views.py
Answered By: PierreF
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.