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

fix: ensure defaults are set in @babel/eslint-parser #11970

Merged
merged 3 commits into from Aug 19, 2020
Merged
Show file tree
Hide file tree
Changes from all 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
25 changes: 17 additions & 8 deletions 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) {
Expand Down
3 changes: 2 additions & 1 deletion eslint/babel-eslint-tests/package.json
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions 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);
});
});