2

My goal is to change the pylint message template for the linter messages in VS Code. I'm using the standard "Python" extension for VS Code from Don Jayamanne, that is now maintained directly by Microsoft. By default the message format reads as follows (with a simple whitespace message as an example):

[pylint] C0303:Trailing whitespace

I would like the message instead to read with the pylint message symbol instead of the code (example "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)

Here are a few things I have tried so far that haven't worked.

Using .pylintrc file to modify the msg-template= line

I set this line in my .pylintrc file:

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

My changes were reflected when running pylint through a separate terminal outside of VS Code, but not in VS Code. I tried reloading the VS Code window, also, and this had no effect.

Specifying python.linting.pylintArgs in User Settings:

The next thing I tried was setting the option for pylint in VS Code user settings, also with no effect:

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

Ensuring the correct pylint was being used

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. 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. Thank you!

awpelican
  • 88
  • 8

1 Answers1

3

Looking at the source for vscode-python at 0.7.0, on line 30. 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. See the abstract BaseLinter class for this.

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.
Oluwafemi Sule
  • 36,144
  • 1
  • 56
  • 81
  • 1
    Thanks for the info! I did submit an issue on the repository at https://github.com/Microsoft/vscode-python/issues/382, as suggested. A pull request may be beyond me, however, as I don't know JavaScript. – awpelican Dec 09 '17 at 12:11
  • VS Code did change `--msg-template` to use the symbolic name `{symbol}` instead of `{msg_id}` now. [`--msg-template` is still hardcoded](https://github.com/microsoft/vscode-python/blob/main/src/client/linters/pylint.ts) though. – wisbucky Sep 03 '21 at 20:11