如何禁止在 VS Code 的问题框中弹出这些错误消息
正如其他人所说,您可以提供禁用参数来禁用特定消息。我想详细说明这一点。
-
以下是禁用多个消息和提供多个参数的语法,通过谷歌搜索,这对我来说并不是很明显:
"python.linting.pylintArgs": [
"--max-line-length=80",
"--disable=W0142,W0403,W0613,W0232,R0903,R0913,C0103,R0914,C0304,F0401,W0402,E1101,W0614,C0111,C0301"
]
-
您表示,一旦禁用该消息,您就开始看到更多错误。这实际上可能是有道理的文档 https://code.visualstudio.com/docs/python/linting#_pylint:
Visual Studio 代码中的 Python 默认配置为使用一组
对最大数量的 Python 友好的 linting 规则
开发商:
- 启用所有错误 (E) 和致命 (F) 消息。
- 禁用所有约定 (C) 和重构 (R) 消息。
- Disable all Warning (W) messages except the following:
- 无法访问 (W0101):无法访问代码
- 重复键 (W0109):字典中重复键 %r
- 不必要的分号(W0301):不必要的分号
- 全局变量未分配 (W0602):对 %r 使用全局但未完成分配
- 未使用的变量 (W0612):未使用的变量 %r
- 二进制操作异常 (W0711):要捕获的异常是二进制“%s”操作的结果
- 错误格式字符串 (W1302):格式字符串无效
- 字符串中的异常反斜杠 (W1401):字符串中的反斜杠异常
- bad-open-mode (W1501):“%s”不是有效的打开模式
这些规则通过传递给 Pylint 的以下默认参数来应用:
--disable=all
--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode
每当python.linting.pylintUseMinimalCheckers
被设定为true
(默认)。
如果您指定一个值pylintArgs
或使用 Pylint 配置
文件(参见下一节),然后pylintUseMinimalCheckers
是
隐式设置为false
.
换句话说,默认情况下,PyLint 在 VS Code 中相当宽松,仅向您显示错误消息和一些精心挑选的警告。但是当你手动设置的时候pylintArgs
对某事,pylintUseMinimalCheckers
被忽略,打开所有消息的闸门。这可能就是为什么禁用一条消息会导致显示更多消息的原因。再说一遍,我不确定为什么您首先会看到未使用的导入消息,因为根据文档默认情况下它应该被抑制。
-
实际上,目前这不起作用: python.linting.pylintUseMinimalCheckers": true
(对我来说,在这个特定的时刻,但希望它对你,未来的读者来说,效果很好)。为了达到同样的效果,我必须手动设置pylintArgs
到它应该自动设置的值:
"python.linting.pylintArgs": [
"--disable=all",
"--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode"
]
-
奖励:这是我使用的禁用消息列表的解释,如上面第 1 点所示。它主要取自here https://gist.github.com/xen/6334976:
# Disabled messages
# Pointless
# W0142 = *args and **kwargs support
# W0403 = Relative imports
# W0613 = Unused argument
# W0232 = Class has no __init__ method
# R0903 = Too few public methods
# R0913 = Too many arguments
# C0103 = Invalid name
# R0914 = Too many local variables
# C0304 = Final newline missing
#
# PyLint's module importation is unreliable
# F0401 = Unable to import module
# W0402 = Uses of a deprecated module
# E1101 = Module x has no y member
#
# Already an error when wildcard imports are used
# W0614 = Unused import from wildcard
#
# Stricter messages that can be disabled until everything else has been fixed
# C0111 = Missing docstring
# C0301 = Line too long
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)