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

Edge-case crashes & false-positives in no-statement-after-end with unreachable statements #315

Closed
ninevra opened this issue Dec 8, 2020 · 0 comments · Fixed by #316
Closed

Comments

@ninevra
Copy link
Contributor

ninevra commented Dec 8, 2020

The path analysis logic in no-statement-after-end doesn't properly handle unreachable statements, sometimes causing crashes or false-positives.

In eslint (tested in v6 and v7), CodePathSegments end when encountering e.g. return or throw. Unreachable statements after that point don't appear to be in any CodePathSegment. This can cause no-statement-after-end to crash when trying to analyze unreachable statements in the global scope or to treat unreachable statements in one path as reachable statements in the next outermost path.

Example of a crash:

const test = require('ava');

throw new Error('make some unreachable code');

1; // <-- triggers a crash

Example of a false positive:

const test = require('ava');

test.cb(t => {
  function newCodePath() {
    throw new Error('make some unreachable code');
    // Now we're in the outer scope, according to the rule
    t.end();
  }

  // Now the rule thinks we've ended.
  1; // <-- triggers a report
});

This came up while writing tests for avajs/ava#1424.

This is unlikely to affect many users, since triggering it requires very odd and/or obviously incorrect code.

I'm working on a PR to fix this presently.

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 a pull request may close this issue.

1 participant