Skip to content
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
3 changes: 2 additions & 1 deletion lib/xo-to-eslint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,8 @@ export function xoToEslintConfig(flatXoConfig: XoConfigItem[] | undefined, {pret
baseConfig.push({...eslintConfigPrettier, files: eslintConfigItem.files});
} else {
// Validate that Prettier options match other `xoConfig` options.
if ((xoConfigItem.semicolon && prettierOptions.semi === false) ?? (!xoConfigItem.semicolon && prettierOptions.semi === true)) {
/* eslint-disable-next-line */
if ((xoConfigItem.semicolon && prettierOptions.semi === false) || (!xoConfigItem.semicolon && prettierOptions.semi === true)) {
throw new Error(`The Prettier config \`semi\` is ${prettierOptions.semi} while Xo \`semicolon\` is ${xoConfigItem.semicolon}, also check your .editorconfig for inconsistencies.`);
}

Expand Down
17 changes: 17 additions & 0 deletions test/cli.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1195,3 +1195,20 @@ test('replaces cache file with directory when file exists at cache path', async
t.true(cachedFiles.some(file => file.startsWith('.cache')), 'ESLint cache should exist');
});

test('prettier validation detects semicolon conflicts', async t => {
const filePath = path.join(t.context.cwd, 'test.js');
await fs.writeFile(filePath, 'const x = true\n', 'utf8'); // No semicolon

// XO: no semicolons, Prettier: semicolons = conflict
const packageJson = {
xo: {
semicolon: false,
prettier: true,
},
};
await fs.writeFile(path.join(t.context.cwd, 'package.json'), JSON.stringify(packageJson), 'utf8');
await fs.writeFile(path.join(t.context.cwd, '.prettierrc'), '{"semi": true}', 'utf8');

const error = await t.throwsAsync($`node ./dist/cli --cwd ${t.context.cwd}`);
t.true(error.message.includes('semicolon'));
});