Skip to content
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

Update: Improve error message for fatal fixer errors #13120

Merged
merged 1 commit into from Apr 3, 2020
Merged

Update: Improve error message for fatal fixer errors #13120

merged 1 commit into from Apr 3, 2020

Conversation

bradzacher
Copy link
Contributor

What is the purpose of this pull request? (put an "X" next to an item)

[x] Other, please explain:

When the autofixer outputs broken code, the rule tester rightfully hard fails the test.
However, the error current message can be pretty vague as it relies upon the error message from the parser. Some of the parser errors can be explicit and easy to trace, and others can be useless without an error location.

For example, the following invalid code

'const a = "1";`'`

Produces this error message in both espree and typescript-eslint

Unterminated template literal.

Which results in this test failure:

A fatal parsing error occurred in autofix: Parsing error: Unterminated template literal.

This is especially problematic for fixer failure, because you cannot actually see the fixer output anywhere. So the above error message is impossible to action.

Usually I just patch my local eslint install to console.log the fixer output, but I finally figured it was probably just better if this was part of core.

This change simply includes the code in the output so it's possible to see what code caused the error:

A fatal parsing error occurred in autofix.
Error: Parsing error: Unterminated template literal.
Autofix output:
'const a = "1";`'`

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Mar 29, 2020
@mdjermanovic mdjermanovic added core Relates to ESLint's core APIs and features evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion and removed triage An ESLint team member will look at this issue soon labels Mar 30, 2020
@mdjermanovic
Copy link
Member

Very useful change, thanks! 👍

I'm not sure how to label this, looks like an enhancement rather than a chore.

@kaicataldo kaicataldo self-assigned this Mar 30, 2020
@kaicataldo
Copy link
Member

I'll champion this. I don't think this needs to go through the RFC process, given that it's an error message change, but let's see what others think. Is it possible to test the value of the error message (RegExp check is fine) to ensure that the change is correct?

@kaicataldo kaicataldo added the enhancement This change enhances an existing feature of ESLint label Mar 30, 2020
@kaicataldo
Copy link
Member

Agreed that this isn't a chore, but a useful enhancement for end users :)

@bradzacher bradzacher changed the title Chore: Improve error message for fatal fixer errors Update: Improve error message for fatal fixer errors Mar 31, 2020
@bradzacher
Copy link
Contributor Author

I didn't realise there was a test. I've updated the test's regex to validate the structure of the message

Copy link
Member

@nzakas nzakas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Very helpful, thanks!

Copy link
Member

@kaicataldo kaicataldo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, this LGTM!

Copy link
Member

@aladdin-add aladdin-add left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, thanks!

@aladdin-add aladdin-add added accepted There is consensus among the team that this change meets the criteria for inclusion and removed evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion labels Apr 2, 2020
@aladdin-add
Copy link
Member

labelled accepted, as it has 2+ 👍 from the TSC. 😄

@nzakas nzakas merged commit 17e2fe4 into eslint:master Apr 3, 2020
@bradzacher bradzacher deleted the rule-tester-error-messages branch April 3, 2020 00:32
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Oct 1, 2020
@eslint-deprecated eslint-deprecated bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Oct 1, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
accepted There is consensus among the team that this change meets the criteria for inclusion archived due to age This issue has been archived; please open a new issue for any further discussion core Relates to ESLint's core APIs and features enhancement This change enhances an existing feature of ESLint
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants