diff --git a/eslint/babel-eslint-parser/src/configuration.js b/eslint/babel-eslint-parser/src/configuration.js index 1ad06e670320..0e4cf5b3209e 100644 --- a/eslint/babel-eslint-parser/src/configuration.js +++ b/eslint/babel-eslint-parser/src/configuration.js @@ -1,15 +1,24 @@ import { loadPartialConfig } from "@babel/core"; export function normalizeESLintConfig(options) { - const defaultOptions = { - babelOptions: {}, - ecmaVersion: 2020, - sourceType: "module", - allowImportExportEverywhere: false, - requireConfigFile: true, - }; + const { + babelOptions = {}, + // ESLint sets ecmaVersion: undefined when ecmaVersion is not set in the config. + ecmaVersion = 2020, + sourceType = "module", + allowImportExportEverywhere = false, + requireConfigFile = true, + ...otherOptions + } = options; - return Object.assign(defaultOptions, options); + return { + babelOptions, + ecmaVersion, + sourceType, + allowImportExportEverywhere, + requireConfigFile, + ...otherOptions, + }; } export function normalizeBabelParseConfig(options) { diff --git a/eslint/babel-eslint-tests/package.json b/eslint/babel-eslint-tests/package.json index 73c48105aee9..05c78c1eef47 100644 --- a/eslint/babel-eslint-tests/package.json +++ b/eslint/babel-eslint-tests/package.json @@ -4,7 +4,8 @@ "description": "Tests for babel/eslint-* packages", "license": "MIT", "private": true, - "devDependencies": { + "dependencies": { + "@babel/eslint-parser": "^7.11.0", "dedent": "^0.7.0", "eslint": "^7.5.0", "eslint-plugin-import": "^2.22.0" diff --git a/eslint/babel-eslint-tests/test/integration/eslint/config.js b/eslint/babel-eslint-tests/test/integration/eslint/config.js new file mode 100644 index 000000000000..e82465b86f9b --- /dev/null +++ b/eslint/babel-eslint-tests/test/integration/eslint/config.js @@ -0,0 +1,21 @@ +import eslint from "eslint"; +import * as parser from "@babel/eslint-parser"; + +describe("ESLint config", () => { + it('should set ecmaVersion to latest and sourceType to "module" by default', () => { + 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: { + babelOptions: { + configFile: require.resolve( + "../../../../babel-eslint-shared-fixtures/config/babel.config.js", + ), + }, + }, + }); + expect(messages.length).toEqual(0); + }); +}); diff --git a/eslint/babel-eslint-tests/test/integration/eslint/eslint.js b/eslint/babel-eslint-tests/test/integration/eslint/verify.js similarity index 100% rename from eslint/babel-eslint-tests/test/integration/eslint/eslint.js rename to eslint/babel-eslint-tests/test/integration/eslint/verify.js