Skip to content

Instantly share code, notes, and snippets.

@umstek
Created June 8, 2024 14:15
Show Gist options
  • Save umstek/da056e505f819ad924c04ab820b2382e to your computer and use it in GitHub Desktop.
Save umstek/da056e505f819ad924c04ab820b2382e to your computer and use it in GitHub Desktop.
Deduplicate ESLint configs migrated with Biome
// Needs Bun
import biome from './biome.json';
// Extracted from https://biomejs.dev/linter/rules/#recommended-rules
const recommended = (await Bun.file('./recommended.txt').text())
.split('\n')
.map((x: string) => x.trim())
.filter(Boolean);
biome.linter.rules.recommended = true;
delete biome.overrides;
const groups = Object.keys(biome.linter.rules).filter(
(x) => typeof biome.linter.rules[x] === 'object',
);
for (const rule of recommended) {
for (const group of groups) {
if (
biome.linter.rules?.[group][rule] &&
['error', 'warn', 'info'].includes(biome.linter.rules[group][rule])
) {
// Delete rule covered by recommended rules
delete biome.linter.rules[group][rule];
}
// Deletes any rules that are Biome-recommended, but turned off by original eslint config
if (biome.linter.rules?.[group][rule] === 'off') {
delete biome.linter.rules[group][rule];
}
}
}
Bun.write('biome.deduped.json', JSON.stringify(biome, null, 2));
@umstek
Copy link
Author

umstek commented Jun 8, 2024

Still needs some manual intervention

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment