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

[eslint] Allow "latest" as ecmaVersion #13638

Merged
merged 4 commits into from Aug 30, 2021
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion eslint/babel-eslint-parser/src/configuration.cjs
Expand Up @@ -11,7 +11,7 @@ exports.normalizeESLintConfig = function (options) {

return {
babelOptions: { cwd: process.cwd(), ...babelOptions },
ecmaVersion,
ecmaVersion: ecmaVersion === "latest" ? 2020 : ecmaVersion,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The latest is 2022 as of August 2021. I think we can normalize "latest" to 1e8 like acorn did (https://github.com/acornjs/acorn/blob/691a31b1e3d6936f4e6991da3d81c1a6b06610cf/acorn/src/options.js#L109) so we don't have to update it every year.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See you again in 99997979 years to update this!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I won't miss the date.

sourceType,
allowImportExportEverywhere,
requireConfigFile,
Expand Down
19 changes: 19 additions & 0 deletions eslint/babel-eslint-tests/test/integration/eslint/config.js
Expand Up @@ -21,4 +21,23 @@ describe("ESLint config", () => {
});
expect(messages.length).toEqual(0);
});

it('should allow ecmaVersion to "latest"', () => {
const linter = new eslint.Linter();
linter.defineParser("@babel/eslint-parser", parser);
// ImportDeclarations result in a parser error if ecmaVersion < 2015 and sourceType != "module".
const messages = linter.verify('import { hello } from "greetings"', {
parser: "@babel/eslint-parser",
parserOptions: {
ecmaVersion: "latest",
babelOptions: {
configFile: path.resolve(
path.dirname(fileURLToPath(import.meta.url)),
"../../../../babel-eslint-shared-fixtures/config/babel.config.js",
),
},
},
});
expect(messages.length).toEqual(0);
});
});