Skip to content

Commit

Permalink
fix: 🐛 Support 'overrideConfigFile' option for ESLint (#745)
Browse files Browse the repository at this point in the history
  • Loading branch information
idahogurl authored May 11, 2022
1 parent c425280 commit 3746d67
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
25 changes: 21 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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);
}
Expand All @@ -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);
Expand Down
3 changes: 0 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ function getRelevantESLintConfig(eslintConfig) {
return {
// defaults
useEslintrc: false,
baseConfig: {
settings: eslintConfig.settings || {}
},
...eslintConfig,
// overrides
rules: { ...eslintConfig.rules, ...relevantRules },
Expand Down

0 comments on commit 3746d67

Please sign in to comment.