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 1 commit
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
Member

Choose a reason for hiding this comment

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

Does it throw if we just directly pass "latest"?

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 don't know, I can't find where it's used.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

eslint-scope does not support 'latest' as valid. Does is make more sense to update it there?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

eslint-scope suggest handling on parser side. eslint/eslint-scope#74 (comment)

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);
});
});