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

Fix crash, false-positive in no-statement-after-end #316

Merged
merged 4 commits into from
Dec 23, 2020

Conversation

ninevra
Copy link
Contributor

@ninevra ninevra commented Dec 8, 2020

Fixes #315 by changing the way no-statement-after-end records CodePathSegments. The stack is used only to hold the in-progress segment in the outer CodePaths. When CodePaths begin or end, the current segment is pushed onto or popped from the stack. When CodePathSegments begin or end, the current segment is set or unset.

When in unreachable code at the end of a path, the current segment is therefore undefined, rather than erroneously taken from the next-outermost path.

Checks whether the current segment is set before operating on it.

(Interestingly, this rule doesn't catch statements after t.end() in unreachable code, e.g.:

throw new Error();
t.end();
1; // <-- does not trigger a report

This behavior predates this PR.)

While I believe this fixes the issue, I don't fully understand how this rule ought to handle its edge-cases nor why the codepath analysis system works this way. Please review carefully?

@novemberborn
Copy link
Member

@sindresorhus could you take a look at this when you get some time? 😄

@sindresorhus
Copy link
Member

I don't have a lot of experience with code path analysis, but the changes look ok from what I can tell.

@sindresorhus sindresorhus merged commit 2b04f84 into avajs:master Dec 23, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Edge-case crashes & false-positives in no-statement-after-end with unreachable statements
3 participants