-
-
Notifications
You must be signed in to change notification settings - Fork 209
Add requireConfigFile option #743
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -323,7 +323,7 @@ module.exports = function(ast, parserOptions) { | |
parserOptions.ecmaFeatures.globalReturn) === true, | ||
impliedStrict: false, | ||
sourceType: ast.sourceType, | ||
ecmaVersion: parserOptions.ecmaVersion || 2018, | ||
ecmaVersion: parserOptions.ecmaVersion, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
fallback, | ||
}; | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,15 @@ | ||
"use strict"; | ||
|
||
const babylonToEspree = require("./babylon-to-espree"); | ||
const { parseSync: parse, tokTypes: tt, traverse } = require("@babel/core"); | ||
const { | ||
parseSync: parse, | ||
tokTypes: tt, | ||
traverse, | ||
loadPartialConfig, | ||
} = require("@babel/core"); | ||
|
||
module.exports = function(code, options) { | ||
const opts = { | ||
let opts = { | ||
sourceType: options.sourceType, | ||
filename: options.filePath, | ||
cwd: options.babelOptions.cwd, | ||
|
@@ -35,7 +40,24 @@ module.exports = function(code, options) { | |
}, | ||
}; | ||
|
||
if (options.requireConfigFile !== false) { | ||
const config = loadPartialConfig(opts); | ||
|
||
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.` | ||
); | ||
} | ||
|
||
opts = config.options; | ||
} | ||
} | ||
|
||
let ast; | ||
|
||
try { | ||
ast = parse(code, opts); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not related to this PR, but do we want to throw a helpful error if this ends up returning There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question about this: It looks like |
||
} catch (err) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add some examples of using
overrides
in the ESLint config to targetbabel-eslint
for specific files?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good idea!