Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: 🐛 Support 'overrideConfigFile' option for ESLint #745

Merged
merged 1 commit into from
May 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 || {}
},
Comment on lines -99 to -101
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

settings will be in the overrideConfig option

...eslintConfig,
// overrides
rules: { ...eslintConfig.rules, ...relevantRules },
Expand Down