简体   繁体   English

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

[英]How to change pylint message template in VS Code linter?

My goal is to change the pylint message template for the linter messages in VS Code. 我的目标是在VS Code中更改linter消息的pylint消息模板。 I'm using the standard "Python" extension for VS Code from Don Jayamanne, that is now maintained directly by Microsoft. 我正在使用Don Jayamanne的VS Code的标准“Python”扩展,现在由Microsoft直接维护。 By default the message format reads as follows (with a simple whitespace message as an example): 默认情况下,消息格式如下所示(以简单的空格消息为例):

[pylint] C0303:Trailing whitespace [pylint] C0303:尾随空格

I would like the message instead to read with the pylint message symbol instead of the code (example "C0303"). 我希望该消息改为使用pylint消息符号而不是代码 (例如“C0303”)。 I prefer the human-readable symbols over the codes. 我更喜欢代码上的人类可读符号。 In my opinion easier to work with when disabling certain messages, etc. So, something like this would be preferred: 在我看来,当禁用某些消息等时更容易使用。所以,这样的事情将是首选:

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

Here are a few things I have tried so far that haven't worked. 以下是到目前为止还没有工作,我已经尝试了几件事情。

Using .pylintrc file to modify the msg-template= line 使用.pylintrc文件修改msg-template=

I set this line in my .pylintrc file: 我在.pylintrc文件中设置了这一行:

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

My changes were reflected when running pylint through a separate terminal outside of VS Code, but not in VS Code. 通过VS代码的一个单独的终端之外的VS代码运行时pylint的,但不是我的变化反映出来。 I tried reloading the VS Code window, also, and this had no effect. 我也尝试重新加载VS Code窗口,这没有任何效果。

Specifying python.linting.pylintArgs in User Settings: 在用户设置中指定python.linting.pylintArgs

The next thing I tried was setting the option for pylint in VS Code user settings, also with no effect: 我尝试的下一件事是在VS Code用户设置中设置pylint选项,也没有效果:

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

Ensuring the correct pylint was being used 确保使用正确的pylint

Finally, I double checked to make sure I didn't have anything strange going on with the path where VS Code was looking for pylint. 最后,我仔细检查以确保我在VS Code寻找pylint的路径上没有任何奇怪的事情。 I did not see anything out of order, as my setting had not been changed from the default: 我没有看到任何乱序,因为我的设置没有从默认设置更改:

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

Any ideas would be appreciated. 任何想法,将不胜感激。 VS Code is a newer editor for me, and I wasn't sure what my next step might be in troubleshooting this. VS Code对我来说是一个较新的编辑器,我不确定我的下一步可能是对此进行故障排除。 Thank you! 谢谢!

Looking at the source for vscode-python at 0.7.0 , on line 30 . 在第30行查看vscode-python的源代码为0.7.0 The message template argument is explicitly overridden. 显式覆盖消息模板参数。

The purpose for this is to keep a consistent API for the result of every specific linter implementation. 这样做的目的是为每个特定linter实现的结果保持一致的API。 See the abstract BaseLinter class for this. 请参阅抽象BaseLinter类

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);
        });
    }

Next Steps here: 下一步:

  • Write an issue on the repository. 在存储库中写一个问题。
  • Fix the implementation to use pylintArgs over the default. 修复实现以使用pylintArgs超过默认值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM