如何禁用 Pylint 子集检查与字符串或正则表达式匹配的模块?

问题描述 投票:0回答:1

编辑:是的,对于某些文件完全禁用 pylint 很容易。这不是我的问题。

我知道如何完全禁用检查:

disable = ["missing-module-doctring", ...]

但我正在尝试做相当于此的事情:

disable = [ {name="missing-module-docstring", glob="**/*/models.py"}, ...]

一个示例: 我们的存储库中有许多 SQL Alchemy

models.py
文件。从我们的目录结构中可以明显看出每个
models.py
的用途是什么。我真的很想禁用任何模块
missing-module-docstring
x.y.z.models
。文档字符串将是多余的噪音。每个文件禁用注释大致相同。

对于其他检查和其他模块/Python 文件命名约定,我还有一些类似的场景。

我查看了配置文档,但没有找到任何东西。有没有支持这个的插件?

如果我必须采用“两遍解决方案”,我想我可以运行 pylint 一次,排除

models.py
文件。然后再次运行它,过滤掉所有内容 but
models.py

对于上下文:我在命令行、CI 和 VS Code 中运行 pylint。我在

project.toml
中配置它,但我愿意更改它。

python pylint
1个回答
2
投票

https://pylint.readthedocs.io/en/latest/user_guide/configuration/all-options.html#ignore

您可以通过使用 pylint 的

ignore-patterns
选项以正则表达式格式指定基本名称来忽略目录和文件(另请参阅
ignore
ignore-paths
ignored-modules
)。

您还可以使用指定的控制消息为特定行、函数或模块禁用 pylint https://pylint.readthedocs.io/en/latest/user_guide/messages/message_control.html#message-control

© www.soinside.com 2019 - 2024. All rights reserved.