-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Update pylint msg-template to show human-friendly error symbols. #495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Question here: do we think it's important to leave the original I would almost suggest something like this:
instead of
Unless we think it's still necessary to have the |
While I do think the numeric codes are redundant, people who use VSCode will have built up workflows around the information that was available to them, and it might be disruptive to remove that information. Specifically, I'm thinking that people will have used the numeric codes in their local Additionally, I could add a new setting to allow users to customize the non-essential part of the message template. So the new template would be
|
Yes, you're right. It's a great point and I agree. It's important to respect existing workflows. Your suggestion seems like an elegant solution to me, as it allows one to take advantage of the rich options for message control that Pylint offers. |
dbb17c0
to
d35e8dc
Compare
Two things, @jcdyer . One, thanks for the PR! Most of us just got back from vacation, but we will get to reviewing your PR at some point. Two, Travis is failing on this PR, so if you could fix that it would be great. And thanks for providing feedback, @AWPelican , on the PR. In the end @jcdyer said what I would have as to why we need to keep the message IDs. 😄 Although I would be open to changing the format to |
@jcdyer @brettcannon The CI tests are failling over as the const REGEX = '(?<line>\\d+),(?<column>\\d+),(?<type>\\w+),(?<code>\\w\\d+):(?<message>.*)\\r?(\\n|$)'; |
package.json
Outdated
"python.linting.pylintMsgTemplate": { | ||
"type": "string", | ||
"description": "Controls the message template for linting results, as a new-style python format string. The provided value will be appended to '{line},{column},{category},', which is required by VSCode. The previous message format, using numeric message codes, can be restored by setting this to '{msg_id}:{msg}'. Available fields are described at https://pylint.readthedocs.io/en/latest/user_guide/output.html.", | ||
"default": "{msg} ({symbol})", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@jcdyer My preference is to make the changes backwards compatible. You'll need to include msg_id
src/client/linters/pylint.ts
Outdated
@@ -11,7 +11,8 @@ export class Linter extends baseLinter.BaseLinter { | |||
} | |||
|
|||
protected async runLinter(document: TextDocument, cancellation: CancellationToken): Promise<baseLinter.ILintMessage[]> { | |||
const messages = await this.run(['--msg-template=\'{line},{column},{category},{msg_id}:{msg}\'', '--reports=n', '--output-format=text', document.uri.fsPath], document, cancellation); | |||
const msgTemplate = `'{line},{column},{category},${this.pythonSettings.linting.pylintMsgTemplate}'`; | |||
const messages = await this.run([`--msg-template=${msgTemplate}`, '--reports=n', '--output-format=text', document.uri.fsPath], document, cancellation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The CI tests are failling over as the msg_id
is missing.
Also, if you are going to make the format configurable, then you'll need to alter the regular expression used to parse the output. The default (named groups) regular expression is as follows (code
is what maps to msg_id
):
const REGEX = '(?<line>\\d+),(?<column>\\d+),(?<type>\\w+),(?<code>\\w\\d+):(?<message>.*)\\r?(\\n|$)';
The regex is the last paramter passed into the run
method (here isn't not passed as we're using the default regex)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Thank you. I see that "code" gets passed through to VSCode in the diagnostic at lintProviders.ts#L38. It seems like it would be too complex to ask a user to provide a custom msg-template AND a regular expression to match the provided template and extract the relevant code.
Two possible solutions I see:
- Automatically generate the regular expression based on the template the user provides, If {symbol} is included, use that as the code, otherwise if {code} is included, use that. If neither is included, add the code outside the visible message, and return that.
- Provided an enumerated configuration option for message templates:
-
Legacy:
msgTemplate = '{msg_id}:{msg}'; regEx = '(?<line>\\d+),(?<column>\\d+),(?<type>\\w+),(?<code>\\w\\d+):(?<message>.*)\\r?(\\n|$)';
-
Standard:
msgTemplate = '{msg} ({symbol})'; regEx = '^(?<line>\\d+),(?<column>\\d+),(?<type>\\w+),(?<message>.*) \((?<code>[\w-]+)\)$';
-
(Regex to be validated).
I'd feel pretty comfortable calling the one with the symbolic name "standard", as a quick test suggests that pylint hasn't included the numeric code in the default output since before v1.0.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry about the formatting. I'll try to clean it up. I'm leaning toward number 2 as it's simpler, and solves the problem at hand. The one complication I see is that lintProviders#L37 assumes that the message should be displayed as {code}:{message}, which is not the PyLint standard, but that's not an insurmountable problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I too prefer option 2
I'll have time to fix this up this weekend. |
This is not ready for another review yet. I'll get it cleaned up soon. |
Allow creating diagnostics with pre-formatted message strings.
a8b70de
to
656c3d8
Compare
Codecov Report
@@ Coverage Diff @@
## master #495 +/- ##
==========================================
+ Coverage 56.29% 56.38% +0.09%
==========================================
Files 212 212
Lines 9975 9993 +18
Branches 1754 1759 +5
==========================================
+ Hits 5615 5635 +20
+ Misses 4355 4353 -2
Partials 5 5
Continue to review full report at Codecov.
|
974b5d3
to
c4917fb
Compare
Some questions and concerns:
Another option would be to show the full multi-line message, but I'm not sure whether this is desirable, or where to enable it. I think other languages (like Rust) do it, but they have more verbose error messages in general. |
@DonJayamanne any answers for the questions from @jcdyer ? |
create a named type for that? Named type would be the way to go.
Agreed with this format, Thought I'd still prefer to see the @brettcannon Based on the PR, the new display format would not include the @brettcannon @jcdyer |
Leaving the ID in is fine by me (some people will want that info), and I agree we should be consistent in the formatting for our own sanity in the code. 😉 I say put the user-readable name first, then the message ID since the human-readable part is what most people will use. |
@DonJayamanne @brettcannon: I'm going to have some time to look at this again soon.
You can (and should) use the textual version for excluded lints. That said, the consensus seems to be to include both of them, so I'll do that. |
I agree with Cliff as well on this, but I also understand that know you guys are trying to balance what’s best for the overall project.
Thanks again to everyone!
… On Jan 31, 2018, at 10:13 AM, Cliff Dyer ***@***.***> wrote:
@DonJayamanne @brettcannon: I'm going to have some time to look at this again soon.
Personally I'd prefer to see that, legacy or not, as I'd like to be able to exclude the error from the pylint config.
You can (and should) use the textual version for excluded lints. # pylint: exclude=unused-import works just as well as # pylint: exclude=W0611, and is better documentation.
That said, the consensus seems to be to include both of them, so I'll do that.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub, or mute the thread.
|
@jcdyer Thanks for taking the time to address our comments. |
@jcdyer We're hitting code freeze today, so this won't' make it in this release. Will you have time do you think to fix the merge conflicts and add back in the error number request that @DonJayamanne made for the next release? |
Yes. I should have time later this week. Sorry this slipped off my radar. |
@jcdyer No problem! This PR just came up in a team meeting and so I wanted to help move it forward. |
This would be a great feature to get in! I currently run |
If @jcdyer can't get an update, did you want to fork the PR and update it so we can merge it, @joshburkart ? |
@brettcannon @jcdyer I'd love to! But unfortunately I think this PR looks a bit too complicated/involved for me to feel comfortable diving in, at the moment... :( |
@joshburkart np |
I'm going to close this issue since it isn't currently going anywhere. If anyone finds the time to fix the conflicts and address Don's comments then we can open this back up, otherwise we will try to fix it for the May release. |
Ping @jcdyer? |
Hi @brettcannon. I was missing the I read through the discussion here, and have a suggestion to solve the issue without being too disruptive: Use
Maybe I'm suffering from Stockholm's syndrome after reading these in Jenkins output whenever my PR's contain pylint problems, but I think it is very nicely readable. It keeps the numbers, but also presents the human readable A detail I didn't see mentioned here is that in Let me know if this could be an acceptable fix, and I will implement it (in a new PR from scratch) 😊 From the pylint tutorial:
|
FWIW I switched to using |
@qubitron do you have any input? |
@jcdyer I can no longer see the numeric code for the warnings is this normal? |
Yes |
@jcdyer, @joshclimacell, @brettcannon
|
@EriKWDev the PR was closed without merging, so there are no plans. If you would like the message changed then please open a new feature request. |
New msg-template adds
({symbol})
, and updates pylintArgs description to explain that overriding --msg-template can't be done.Fixes #382.