【问题标题】:How to change pylint message template in VS Code linter?如何在 VS Code linter 中更改 pylint 消息模板?
【发布时间】:2017-12-08 11:09:55
【问题描述】:

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

[pylint] C0303:尾随空格

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

[pylint] 尾随空格(trailing-whitespace)

这是我迄今为止尝试过的一些没有奏效的方法。

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

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

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

我的更改反映在通过 VS Code 之外的单独终端运行 pylint 时,但在 VS Code 中没有。我也尝试重新加载 VS Code 窗口,但没有效果。

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

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

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

确保使用正确的 pylint

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

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

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

【问题讨论】:

    标签: python visual-studio-code pylint vscode-settings


    【解决方案1】:

    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 而非默认值。

    【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-07-17
    • 2017-09-02
    • 2022-12-04
    • 1970-01-01
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 2018-10-22
    相关资源
    最近更新 更多