我的目标是在VS Code中更改linter消息的pylint消息模板。我正在使用标准" Python" Don Jayamanne的VS Code扩展,现在由Microsoft直接维护。默认情况下,消息格式如下所示(以简单的空格消息为例):
[pylint] C0303:尾随空格
我希望使用pylint消息 symbol 而不是代码来读取消息(例如" C0303")。我更喜欢代码上的人类可读符号。在我看来,当禁用某些消息等时更容易使用。因此,这样的事情将是首选:
[pylint]尾随空格(尾随空格)
到目前为止,我已尝试过以下几项避免工作的事情。
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})'"
]
最后,我仔细检查以确保我在VS Code寻找pylint的路径上没有任何奇怪的事情发生。我没有看到任何乱序,因为我的设置没有从默认设置更改:
"python.linting.pylintPath": "pylint",
任何想法都将不胜感激。 VS Code对我来说是一个较新的编辑器,我不确定我的下一步可能是对此进行故障排除。谢谢!
答案 0 :(得分:3)
在0.7.0
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);
});
}
上查看vscode-python的来源。显式覆盖消息模板参数。
这样做的目的是为每个特定linter实现的结果保持一致的API。请参阅line 30。
using Solution.Controllers;
此处的后续步骤: