[eslint] Allow "latest" as ecmaVersion (#13638)

This commit is contained in:
fisker Cheung 2021-08-30 18:05:37 +08:00 committed by GitHub
parent 313ecb579d
commit c1f5ca6676
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 20 additions and 1 deletions

View File

@ -11,7 +11,7 @@ exports.normalizeESLintConfig = function (options) {
return { return {
babelOptions: { cwd: process.cwd(), ...babelOptions }, babelOptions: { cwd: process.cwd(), ...babelOptions },
ecmaVersion, ecmaVersion: ecmaVersion === "latest" ? 1e8 : ecmaVersion,
sourceType, sourceType,
allowImportExportEverywhere, allowImportExportEverywhere,
requireConfigFile, requireConfigFile,

View File

@ -21,4 +21,23 @@ describe("ESLint config", () => {
}); });
expect(messages.length).toEqual(0); expect(messages.length).toEqual(0);
}); });
it('should allow ecmaVersion to be "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);
});
}); });