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

parserOptions was not passed to context #14696

Closed
aladdin-add opened this issue Jun 11, 2021 · 2 comments
Closed

parserOptions was not passed to context #14696

aladdin-add opened this issue Jun 11, 2021 · 2 comments
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint
Projects

Comments

@aladdin-add
Copy link
Member

this is from #14622 (comment)

Tell us about your environment

Node version: v16.0.0
npm version: v7.10.0
Local ESLint version: v7.28.0 (Currently used)
Global ESLint version: Not found
Operating System: linux 4.19.128-microsoft-standard

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using? default

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

let ecmaVersion = null;

linter.defineRule("ecma-version", context => ({
    Program() {
        ecmaVersion = context.parserOptions.ecmaVersion;
    }
}));

linter.verify("", {
    rules: {"ecma-version": 2},
  {parserOptions: {ecmaVersion: 5}},
});

assert.strictEqual(ecmaVersion, 5);

it seems the ecmaVersion is always null.

AssertionError: expected null to equal 5

Are you willing to submit a pull request to fix this bug?

@aladdin-add aladdin-add added bug ESLint is working incorrectly repro:needed labels Jun 11, 2021
@eslint-github-bot eslint-github-bot bot added this to Needs Triage in Triage Jun 11, 2021
@aladdin-add aladdin-add moved this from Needs Triage to Ready for Dev Team in Triage Jun 11, 2021
@aladdin-add aladdin-add added core Relates to ESLint's core APIs and features repro:yes and removed repro:needed labels Jun 11, 2021
@mdjermanovic
Copy link
Member

Hmm, I had tried all three tests from #14622 (comment) on aladdin-add:update/ecma-latest and they worked then.

AssertionError: expected null to equal 5

This happens when there's a parsing error, so the rule isn't run and ecmaVersion keeps its initial value (let ecmaVersion = null). Parsing error isn't thrown from linter.verify(), it's in the linting result as a lint message item.

@aladdin-add
Copy link
Member Author

oh, my bad! I just passed the wrong configs.

Triage automation moved this from Ready for Dev Team to Complete Jun 11, 2021
@aladdin-add aladdin-add added question This issue asks a question about ESLint and removed bug ESLint is working incorrectly core Relates to ESLint's core APIs and features repro:yes labels Jun 11, 2021
@eslint-github-bot eslint-github-bot bot locked and limited conversation to collaborators Dec 9, 2021
@eslint-github-bot eslint-github-bot bot added the archived due to age This issue has been archived; please open a new issue for any further discussion label Dec 9, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
archived due to age This issue has been archived; please open a new issue for any further discussion question This issue asks a question about ESLint
Projects
Archived in project
Triage
Complete
Development

No branches or pull requests

2 participants