Skip to content

Instantly share code, notes, and snippets.

@DarkGL
Forked from umstek/dedupe.ts
Created June 12, 2024 02:04
Show Gist options
  • Save DarkGL/299b9e8f4e017cf4d29e6d2dbb91a856 to your computer and use it in GitHub Desktop.
Save DarkGL/299b9e8f4e017cf4d29e6d2dbb91a856 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));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment