Skip to content

Commit 3746d67

Browse files
authored
fix: 🐛 Support 'overrideConfigFile' option for ESLint (#745)
1 parent c425280 commit 3746d67

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/index.js

+21-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ async function format(options) {
5757
const eslintConfig = merge(
5858
{},
5959
options.eslintConfig,
60-
await getESLintConfig(filePath, eslintPath)
60+
await getESLintConfig(filePath, eslintPath, options.eslintConfig || {})
6161
);
6262

6363
const prettierOptions = merge(
@@ -248,8 +248,24 @@ function getTextFromFilePath(filePath) {
248248
}
249249
}
250250

251-
async function getESLintConfig(filePath, eslintPath) {
252-
const eslintOptions = {};
251+
function getESLintApiOptions(eslintConfig) {
252+
// https://eslint.org/docs/developer-guide/nodejs-api
253+
// these options affect what calculateConfigForFile produces
254+
return {
255+
ignore: eslintConfig.ignore || true,
256+
ignorePath: eslintConfig.ignorePath || null,
257+
allowInlineConfig: eslintConfig.allowInlineConfig || true,
258+
baseConfig: eslintConfig.baseConfig || null,
259+
overrideConfig: eslintConfig.overrideConfig || null,
260+
overrideConfigFile: eslintConfig.overrideConfigFile || null,
261+
plugins: eslintConfig.plugins || null,
262+
resolvePluginsRelativeTo: eslintConfig.resolvePluginsRelativeTo || null,
263+
rulePaths: eslintConfig.rulePaths || [],
264+
useEslintrc: eslintConfig.useEslintrc || true
265+
};
266+
}
267+
268+
async function getESLintConfig(filePath, eslintPath, eslintOptions) {
253269
if (filePath) {
254270
eslintOptions.cwd = path.dirname(filePath);
255271
}
@@ -259,7 +275,8 @@ async function getESLintConfig(filePath, eslintPath) {
259275
"${filePath || process.cwd()}"
260276
`
261277
);
262-
const eslint = getESLint(eslintPath, eslintOptions);
278+
const eslint = getESLint(eslintPath, getESLintApiOptions(eslintOptions));
279+
263280
try {
264281
logger.debug(`getting eslint config for file at "${filePath}"`);
265282
const config = await eslint.calculateConfigForFile(filePath);

src/utils.js

-3
Original file line numberDiff line numberDiff line change
@@ -96,9 +96,6 @@ function getRelevantESLintConfig(eslintConfig) {
9696
return {
9797
// defaults
9898
useEslintrc: false,
99-
baseConfig: {
100-
settings: eslintConfig.settings || {}
101-
},
10299
...eslintConfig,
103100
// overrides
104101
rules: { ...eslintConfig.rules, ...relevantRules },

0 commit comments

Comments
 (0)