Daniel Scott
Daniel Scott

Reputation: 7961

Ignore SonarQube warnings in python

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.

Upvotes: 39

Views: 22354

Answers (2)

Pierre
Pierre

Reputation: 2752

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

Upvotes: 4

G. Ann - SonarSource Team
G. Ann - SonarSource Team

Reputation: 22824

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.

Upvotes: 45

Related Questions