python - Sonarqube 如何使用 # NOSONAR 在 Python 中抑制特定警告
问题描述
# NOSONAR
在 Python 中,我们可以通过应用注释来抑制代码中特定行的所有 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
你怎么能压制第一个,而不是第二个?
解决方案
如果您使用的是 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
是您要抑制此特定规则的文件。不幸的是,它会抑制整个文件,而不是特定功能。
推荐阅读
- c - 使用 C 将键盘键向右移动 2 位的方法
- java - 多次打印到文件缓冲阅读器java
- ios - 使用 NSFetchedResultsController 在 UITableView 中插入/删除
- javascript - 在插入之前执行获取数据
- amazon-web-services - Terraform - 加载模块时出错 - 没有这样的文件或目录(文件夹重命名后)
- ios - 自定义 Tableview 幻灯片动作
- webdriver-io - 在 webdriverIO 中的 @Wdio 中的 Allure 报告干净
- c# - Xamarin 表单提高构建和部署速度?
- php - Alexa bot 被重定向,即使它在良好的 bot 列表中
- android - 我可以检测 Fragment 是否已经创建或调用?