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

Handle throw with no arguments in no-throw-literal #13143

Closed
wants to merge 1 commit into from
Closed

Handle throw with no arguments in no-throw-literal #13143

wants to merge 1 commit into from

Conversation

steelbrain
Copy link

Prerequisites checklist

  • I have read the contributing guidelines.
  • The team has reached consensus on the changes proposed in this pull request. If not, I understand that the evaluation process will begin with this pull request and won't be merged until the team has reached consensus.

What is the purpose of this pull request?

[ ] Documentation update
[x] Bug fix (template)

Repro for the bug

throw

Yep, that's it. Empty file with that will crash ESLint.

Here's the stack trace from ESLint output channel in VSCode

[Error - 1:41:32 PM] TypeError: Cannot read property 'type' of null
Occurred while linting [fileName].ts:132
    at Object.couldBeError (eslint/lib/rules/utils/ast-utils.js:1262:22)
    at ThrowStatement (eslint/lib/rules/no-throw-literal.js:38:31)
    at eslint/lib/linter/safe-emitter.js:45:58
    at Array.forEach (<anonymous>)
    at Object.emit (eslint/lib/linter/safe-emitter.js:45:38)
    at NodeEventGenerator.applySelector (eslint/lib/linter/node-event-generator.js:254:26)
    at NodeEventGenerator.applySelectors (eslint/lib/linter/node-event-generator.js:283:22)
    at NodeEventGenerator.enterNode (eslint/lib/linter/node-event-generator.js:297:14)
    at CodePathAnalyzer.enterNode (eslint/lib/linter/code-path-analysis/code-path-analyzer.js:634:23)
    at eslint/lib/linter/linter.js:936:32

I'm using the @typescript-eslint parser if that's relevant.

@jsf-clabot
Copy link

jsf-clabot commented Apr 5, 2020

CLA assistant check
All committers have signed the CLA.

@eslint-deprecated eslint-deprecated bot added the triage An ESLint team member will look at this issue soon label Apr 5, 2020
@mdjermanovic mdjermanovic added 3rd party plugin This is an issue related to a 3rd party plugin, config, or parser evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules and removed triage An ESLint team member will look at this issue soon labels Apr 5, 2020
@mdjermanovic
Copy link
Member

Thanks for the PR!

However, I don't think we should change the code to support node.argument === null because it is expected to be a parsing error, like in this demo with the default parser.

throw without argument is invalid syntax by The throw Statement specification. Rules and helper functions usually don't account for invalid syntax.

In my opinion, this should be fixed in @typescript-eslint/parser.

@steelbrain
Copy link
Author

steelbrain commented Apr 6, 2020

Very well, thank you. I'll x-post this to the parser

Edit: Opened typescript-eslint/typescript-eslint#1852

@steelbrain steelbrain closed this Apr 6, 2020
@steelbrain steelbrain deleted the handle-no-arg-in-throw branch April 6, 2020 06:21
@eslint-deprecated eslint-deprecated bot locked and limited conversation to collaborators Oct 4, 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 4, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
3rd party plugin This is an issue related to a 3rd party plugin, config, or parser archived due to age This issue has been archived; please open a new issue for any further discussion evaluating The team will evaluate this issue to decide whether it meets the criteria for inclusion rule Relates to ESLint's core rules
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants