-
-
Notifications
You must be signed in to change notification settings - Fork 5.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
@babel/eslint-parser: refactor configuration logic (#10860)
- Loading branch information
1 parent
7b54a94
commit 25f7e68
Showing
4 changed files
with
69 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { loadPartialConfig } from "@babel/core"; | ||
|
||
export function normalizeESLintConfig(options) { | ||
const defaultOptions = { | ||
babelOptions: {}, | ||
ecmaVersion: 2020, | ||
sourceType: "module", | ||
allowImportExportEverywhere: false, | ||
}; | ||
|
||
return Object.assign(defaultOptions, options); | ||
} | ||
|
||
export function normalizeBabelParseConfig(options) { | ||
const parseOptions = { | ||
sourceType: options.sourceType, | ||
filename: options.filePath, | ||
cwd: options.babelOptions.cwd, | ||
root: options.babelOptions.root, | ||
rootMode: options.babelOptions.rootMode, | ||
envName: options.babelOptions.envName, | ||
configFile: options.babelOptions.configFile, | ||
babelrc: options.babelOptions.babelrc, | ||
babelrcRoots: options.babelOptions.babelrcRoots, | ||
extends: options.babelOptions.extends, | ||
env: options.babelOptions.env, | ||
overrides: options.babelOptions.overrides, | ||
test: options.babelOptions.test, | ||
include: options.babelOptions.include, | ||
exclude: options.babelOptions.exclude, | ||
ignore: options.babelOptions.ignore, | ||
only: options.babelOptions.only, | ||
parserOpts: { | ||
allowImportExportEverywhere: options.allowImportExportEverywhere, | ||
allowReturnOutsideFunction: true, | ||
allowSuperOutsideMethod: true, | ||
ranges: true, | ||
tokens: true, | ||
plugins: ["estree"], | ||
}, | ||
caller: { | ||
name: "@babel/eslint-parser", | ||
}, | ||
}; | ||
|
||
if (options.requireConfigFile !== false) { | ||
const config = loadPartialConfig(parseOptions); | ||
|
||
if (config !== null) { | ||
if (!config.hasFilesystemConfig()) { | ||
throw new Error( | ||
`No Babel config file detected for ${config.options.filename}. Either disable config file checking with requireConfigFile: false, or configure Babel so that it can find the config files.`, | ||
); | ||
} | ||
|
||
return config.options; | ||
} | ||
} | ||
|
||
return parseOptions; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters