如何在 VS Code linter 中更改 pylint 消息模板?

How to change pylint message template in VS Code linter?

我的目标是更改 VS Code 中 linter 消息的 pylint 消息模板。我正在使用来自 Don Jayamanne 的 VS Code 标准 "Python" 扩展,它现在由 Microsoft 直接维护。默认情况下,消息格式如下(以简单的空白消息为例):

[pylint] C0303:Trailing whitespace

我希望消息使用 pylint 消息 symbol 而不是 code(示例 "C0303") .我更喜欢人类可读的符号而不是代码。在我看来,禁用某些消息等时更容易使用。因此,首选这样的东西:

[pylint] Trailing whitespace (trailing-whitespace)

这里有一些我已经尝试过但没有的方法。

使用 .pylintrc 文件修改 msg-template=

我在 .pylintrc 文件中设置了这一行:

msg-template='{msg} ({symbol})'

我的更改 当 运行 pylint 通过 VS Code 之外的单独终端而不是 VS Code 反映时。我也尝试重新加载 VS Code window,但没有效果。

在用户设置中指定 python.linting.pylintArgs

接下来我尝试在 VS Code 用户设置中设置 pylint 选项,但也没有效果:

"python.linting.pylintArgs": [
    "--msg-template='{msg} ({symbol})'"
]

确保使用了正确的 pylint

最后,我再次检查以确保我在 VS Code 寻找 pylint 的路径上没有发生任何奇怪的事情。我没有看到任何异常,因为我的设置没有从默认设置更改:

"python.linting.pylintPath": "pylint",

如有任何想法,我们将不胜感激。 VS Code 对我来说是一个较新的编辑器,我不确定我的下一步是解决这个问题。谢谢!

0.7.0line 30 查看 vscode-python 的来源。消息模板参数被显式覆盖。

这样做的目的是为了让每个特定的 linter 实现的结果保持一致 API。请参阅 the abstract BaseLinter class

public runLinter(document: TextDocument, cancellation: CancellationToken): Promise<baseLinter.ILintMessage[]> {
        ...

            this.run(pylintPath, pylintArgs.concat(['--msg-template=\'{line},{column},{category},{msg_id}:{msg}\'', '--reports=n', '--output-format=text', document.uri.fsPath]), document, this.workspaceRootPath, cancellation).then(messages => {
                messages.forEach(msg => {
                    msg.severity = this.parseMessagesSeverity(msg.type, this.pythonSettings.linting.pylintCategorySeverity);
                });

                resolve(messages);
            }, reject);
        });
    }

此处的后续步骤:

  • 在存储库上写一个问题。
  • 修复实现以在默认情况下使用 pylintArgs。