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
New: Break on parsing errors #76
Conversation
Hi @A-Katopodis!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.
Read more about contributing to ESLint here |
Hi @A-Katopodis!, thanks for the Pull Request The pull request title isn't properly formatted. We ask that you update the message to match this format, as we use it to generate changelogs and automate releases.
Read more about contributing to ESLint here |
I’m confused; eslint already exits nonzero when there’s a parsing error (or any lint error), so shouldn’t this already be the default behavior? |
@ljharb The issue that this cannot be differentiated. As you mentioned it exits with no zero but if you specified a wrong type of Also updated the RFC to include some more information and examples found in the linked issue |
Your OP mentions CI; generally all nonzero exit codes are treated identically by everything but humans (they’re used for debugging, mainly). Is this RFC just asking for a distinct nonzero exit code for reports with linting errors and parsing errors, versus reports with linting errors but without parsing errors? |
The exit code exists it's 2 but the behavior is kinda different. For example if we run eslint against this piece of code which has an obvious syntax error: As you can see from the image the Exit Code is reported as 1 despite the parsing error it produces. This piece of code gives 1: This piece of code gives 1 again due to a found rule (no-unused-vars): Furthermore this behavior is the same when eslint is not able to read tsconfig.json ( for example wrong path by the user, which should be a misconfiguration) are again reported as exit code 1. What I would suggest in my opinion is using the already existing code When a user passes the flag ( Of course we can create another exit code for this specific use case but since eslint reporting with a different exit code for some cases by default I would still keep the opt-in flag ( |
A parsing error results in a exit code of 1 because ESLint can continue linting other files. An exit code of 2 is used when ESLint needs to exit because it can't continue. (Parsing errors are currently considered linting errors.) Also, note that ESLint doesn't read |
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'm not sure I understand the need for this option, especially if the main use case is when tsconfig.json
fails to load, which ESLint itself doesn't do.
Additionally, you've left out a section for alternative approaches to solving the same problem. Please add that section and address the questions I've left, and we can see if there's support on the team for moving forward.
Thanks for updating the RFC. I’m still not sure I understand the tsconfig.json use case. Can you explain that? It seems like maybe that’s something typescript-eslint could handle on its own? |
1. Add a `fatal-parse-error` option. | ||
2. Gather and report the fatal messages from `cli-engine`. | ||
3. Return exit code `2` in the case of any fatal errors on `cli` |
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.
Should this option apply to all fatal: true
linting messages?
Aside from parsing errors, there is at least one other case where ESLint produces linting messages with fatal: true
- when a configuration comment cannot be JSON-parsed (though this is also some sort of a parsing error).
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.
In my opinion should be to all fatal: true
messages.
Any type of error (coming from invalid JSON, invalid sourceType
or a parser error) that does not allow the file to be linted and the rules to run should be reported.
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.
ESLint will still lint a file with an invalid configuration comment. It can be said that the file wasn't successfully linted because the configuration comment wasn't applied, but there will be some inconsistencies.
For example:
/* eslint no-undef: ["error" */ // <-- missing ']', invalid JSON
/* eslint no-void: ["error"] */
void a;
/* eslint no-undef: ["error", "foo"] */ // <-- invalid option
/* eslint no-void: ["error"] */
void a;
/* eslint no-undeff: ["error"] */ // <-- typo, this rule doesn't exist
/* eslint no-void: ["error"] */
void a;
In all three examples, ESLint lints the file and reports a no-void
linting error. It also reports a linting error for the invalid configuration comment on the first line in all three examples, but only in the first example the error has fatal: true
.
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 behavior in those three cases makes sense to me, in terms of severity.
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.
Added more clear explanations about the tsconfig.json and added the alternative approach section
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.
Thanks for the additional detail, I left a couple other comments. I'm still not 100% on board, but I'm starting to see how this could be useful. Interested in what other team members think.
Thanks @nzakas if anything else is needed let me know. I would also like to add that I would be glad to implement this change. |
|
||
## Summary | ||
|
||
The suggested change is for ESLint tp support an argument that will make the CLI exit with code 2 if any fatal errors are reported. The option will be an opt-in boolean argument called `--fatal-parse-error`. |
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 think the only open question I have is whether --fatal-parse-error
makes sense as the flag name. It seems a bit unclear because all parse errors are flagged as fatal, so maybe something like --exit-on-fatal-error
would better describe the purpose?
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 agree that --exit-on-fatal-error
indicates the functionality better. I have updated the RFC to reflect the new name
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.
Thanks. I think this looks good now.
It looks like the majority of the feedback has been addressed, so moving to final commenting period. |
@eslint/eslint-tsc It's time to decide on this RFC. Please leave an approval if we can move forward or else leave your feedback. |
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 rationale for this makes sense after reading through the discussion, and there's enough detail to move forward with an implementation. Thanks @A-Katopodis! LGTM.
Since we are already past the final commenting period without objections, I’m merging this. Thanks @A-Katopodis for your hard work on this. We really appreciate it. |
Summary
The suggested change is for ESLint to support a parameter that will break the ESLint run when it finds configuration errors. The option will be an opt-in argument called
--break-on-error
.Related Issues
eslint/eslint#13711