Sonarqube如何在Python中使用# NOSONAR来抑制特定警告

4
在Python中,我们可以通过应用“# NOSONAR”注释来抑制代码中特定行的所有Sonarqube警告。这并不理想。有没有一种方法可以抑制特定的错误,而不是抑制所有错误?
例如,您可能有一个带有两个警告的函数:
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

你如何抑制第一个但不抑制第二个?

如果我理解你的问题正确...你的意思是想使用"@SuppressWarnings("squid:S###")"而不是NOSONAR吗? - Ehsan
@Ehsan @SupressWarnings 在 Python 中可用吗?我认为这只允许在 Java 中使用。 - Matthew Moisen
这个回答解决了你的问题吗?忽略Python中的SonarQube警告 - agabrys
2
@agabrys 不是的,这个答案说使用“# NOSONAR”“是一个全局问题抑制:它会杀掉该行中的所有问题,而不仅仅是来自特定规则的问题。” 我正在寻找一种机制来抑制一个特定的规则,而不是所有规则。 - Matthew Moisen
1个回答

3
这是一个针对使用不完美的Jenkins的解决方法。它可以用来抑制整个文件中特定警告(而不仅仅是一个函数)。
在Jenkins属性文件中添加类似以下内容:
sonar.issue.ignore.multicriteria=e1
sonar.issue.ignore.multicriteria.e1.ruleKey=python:S107
sonar.issue.ignore.multicriteria.e1.resourceKey=path/to/file.py

python:S107是一个函数参数超过7个的规则键,path/to/file.py是要针对该特定规则抑制的文件。不幸的是,它将会抑制整个文件,而非仅针对特定函数。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接