Skip to content

Commit b41471f

Browse files
author
Simon Waiblinger
authored
Fix prettier integration being broken due to nullish coalescing misuse (#836)
1 parent 4180123 commit b41471f

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/xo-to-eslint.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,8 @@ export function xoToEslintConfig(flatXoConfig: XoConfigItem[] | undefined, {pret
8181
baseConfig.push({...eslintConfigPrettier, files: eslintConfigItem.files});
8282
} else {
8383
// Validate that Prettier options match other `xoConfig` options.
84-
if ((xoConfigItem.semicolon && prettierOptions.semi === false) ?? (!xoConfigItem.semicolon && prettierOptions.semi === true)) {
84+
/* eslint-disable-next-line */
85+
if ((xoConfigItem.semicolon && prettierOptions.semi === false) || (!xoConfigItem.semicolon && prettierOptions.semi === true)) {
8586
throw new Error(`The Prettier config \`semi\` is ${prettierOptions.semi} while Xo \`semicolon\` is ${xoConfigItem.semicolon}, also check your .editorconfig for inconsistencies.`);
8687
}
8788

test/cli.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1195,3 +1195,20 @@ test('replaces cache file with directory when file exists at cache path', async
11951195
t.true(cachedFiles.some(file => file.startsWith('.cache')), 'ESLint cache should exist');
11961196
});
11971197

1198+
test('prettier validation detects semicolon conflicts', async t => {
1199+
const filePath = path.join(t.context.cwd, 'test.js');
1200+
await fs.writeFile(filePath, 'const x = true\n', 'utf8'); // No semicolon
1201+
1202+
// XO: no semicolons, Prettier: semicolons = conflict
1203+
const packageJson = {
1204+
xo: {
1205+
semicolon: false,
1206+
prettier: true,
1207+
},
1208+
};
1209+
await fs.writeFile(path.join(t.context.cwd, 'package.json'), JSON.stringify(packageJson), 'utf8');
1210+
await fs.writeFile(path.join(t.context.cwd, '.prettierrc'), '{"semi": true}', 'utf8');
1211+
1212+
const error = await t.throwsAsync($`node ./dist/cli --cwd ${t.context.cwd}`);
1213+
t.true(error.message.includes('semicolon'));
1214+
});

0 commit comments

Comments
 (0)