Skip to content

Commit 0bd2e77

Browse files
authored
fix: use overrideConfigFile: true + overrideConfig instead (#1193)
1 parent 5c03479 commit 0bd2e77

File tree

3 files changed

+21
-14
lines changed

3 files changed

+21
-14
lines changed

.changeset/late-eels-march.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"prettier-eslint": patch
3+
---
4+
5+
fix: use `overrideConfigFile: true` + `overrideConfig` instead

src/index.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -228,6 +228,8 @@ function createPrettify(formatOptions: PrettierOptions, prettierPath: string) {
228228

229229
function createEslintFix(eslintConfig: ESLintConfig, eslintPath: string) {
230230
return async function eslintFix(text: string, filePath?: string) {
231+
eslintConfig.overrideConfigFile = true;
232+
231233
eslintConfig.overrideConfig = {
232234
languageOptions: eslintConfig.languageOptions,
233235
rules: eslintConfig.rules,
@@ -246,8 +248,8 @@ function createEslintFix(eslintConfig: ESLintConfig, eslintPath: string) {
246248
delete eslintConfig.plugins;
247249
delete eslintConfig.settings;
248250

249-
// FIXME: Seems to be an ESLint core issue: `Key "plugins": Cannot redefine plugin`
250-
delete eslintConfig.overrideConfig.plugins;
251+
// FIXME: Seems like a bug in eslint - https://github.com/eslint/eslint/issues/19722
252+
delete eslintConfig.overrideConfig.plugins!['@'];
251253

252254
const eslint = await getESLint(eslintPath, eslintConfig);
253255
try {

test/index.spec.ts

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* eslint-disable @typescript-eslint/unbound-method, sonarjs/no-commented-code */
1+
/* eslint-disable @typescript-eslint/unbound-method */
22

33
// eslint-disable-next-line unicorn/prefer-node-protocol -- mocked
44
import fsMock_ from 'fs';
@@ -131,7 +131,7 @@ const tests: Array<{
131131
{
132132
title: 'without a filePath and no config',
133133
input: { text: defaultInputText() },
134-
output: prettierLastOutput(),
134+
output: noopOutput(),
135135
},
136136
{
137137
title: 'inferring bracketSpacing',
@@ -187,7 +187,7 @@ const tests: Array<{
187187
languageOptions: { globals: { windows: 'writable' } },
188188
},
189189
},
190-
output: prettierLastOutput(),
190+
output: noopOutput(),
191191
},
192192
{
193193
title: 'CSS example',
@@ -284,7 +284,7 @@ const tests: Array<{
284284
},
285285
},
286286
},
287-
output: "var foo = { bar: 'baz' };",
287+
output: 'var foo = { bar: "baz" };',
288288
},
289289
];
290290

@@ -524,14 +524,14 @@ function defaultInputText() {
524524
`;
525525
}
526526

527-
// function noopOutput() {
528-
// return `
529-
// function foo() {
530-
// // stuff
531-
// console.log("Hello world!", and, stuff);
532-
// }
533-
// `;
534-
// }
527+
function noopOutput() {
528+
return `
529+
function foo() {
530+
// stuff
531+
console.log("Hello world!", and, stuff);
532+
}
533+
`;
534+
}
535535

536536
function defaultOutput() {
537537
return `

0 commit comments

Comments
 (0)