From 3746d674f3810d19156c3060c401adf536d999b8 Mon Sep 17 00:00:00 2001 From: Rebecca Vest Date: Wed, 11 May 2022 10:02:28 -0600 Subject: [PATCH] fix: :bug: Support 'overrideConfigFile' option for ESLint (#745) --- src/index.js | 25 +++++++++++++++++++++---- src/utils.js | 3 --- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/index.js b/src/index.js index ab75eef5..804d556e 100644 --- a/src/index.js +++ b/src/index.js @@ -57,7 +57,7 @@ async function format(options) { const eslintConfig = merge( {}, options.eslintConfig, - await getESLintConfig(filePath, eslintPath) + await getESLintConfig(filePath, eslintPath, options.eslintConfig || {}) ); const prettierOptions = merge( @@ -248,8 +248,24 @@ function getTextFromFilePath(filePath) { } } -async function getESLintConfig(filePath, eslintPath) { - const eslintOptions = {}; +function getESLintApiOptions(eslintConfig) { + // https://eslint.org/docs/developer-guide/nodejs-api + // these options affect what calculateConfigForFile produces + return { + ignore: eslintConfig.ignore || true, + ignorePath: eslintConfig.ignorePath || null, + allowInlineConfig: eslintConfig.allowInlineConfig || true, + baseConfig: eslintConfig.baseConfig || null, + overrideConfig: eslintConfig.overrideConfig || null, + overrideConfigFile: eslintConfig.overrideConfigFile || null, + plugins: eslintConfig.plugins || null, + resolvePluginsRelativeTo: eslintConfig.resolvePluginsRelativeTo || null, + rulePaths: eslintConfig.rulePaths || [], + useEslintrc: eslintConfig.useEslintrc || true + }; +} + +async function getESLintConfig(filePath, eslintPath, eslintOptions) { if (filePath) { eslintOptions.cwd = path.dirname(filePath); } @@ -259,7 +275,8 @@ async function getESLintConfig(filePath, eslintPath) { "${filePath || process.cwd()}" ` ); - const eslint = getESLint(eslintPath, eslintOptions); + const eslint = getESLint(eslintPath, getESLintApiOptions(eslintOptions)); + try { logger.debug(`getting eslint config for file at "${filePath}"`); const config = await eslint.calculateConfigForFile(filePath); diff --git a/src/utils.js b/src/utils.js index 3ebd1ce5..975ea942 100644 --- a/src/utils.js +++ b/src/utils.js @@ -96,9 +96,6 @@ function getRelevantESLintConfig(eslintConfig) { return { // defaults useEslintrc: false, - baseConfig: { - settings: eslintConfig.settings || {} - }, ...eslintConfig, // overrides rules: { ...eslintConfig.rules, ...relevantRules },