Skip to content

Commit

Permalink
fix: off config no longer contains "overrides" (#286)
Browse files Browse the repository at this point in the history
  • Loading branch information
RebeccaStevens authored Oct 24, 2021
1 parent a267af6 commit 5ad533d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
18 changes: 9 additions & 9 deletions src/configs/off.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ import type { Linter } from "eslint";

import all from "./all";

function turnRulesOff(rules: Linter.Config["rules"]): Linter.Config["rules"] {
function turnRulesOff(rules: ReadonlyArray<string>): Linter.Config["rules"] {
return rules === undefined
? undefined
: Object.fromEntries(
Object.entries(rules).map(([name, value]) => [name, "off"])
);
: Object.fromEntries(rules.map((name) => [name, "off"]));
}

const allRulesNames = new Set([
...Object.keys(all.rules ?? {}),
...(all.overrides?.flatMap((override) => Object.keys(override.rules ?? {})) ??
[]),
]);

const config: Linter.Config = {
rules: turnRulesOff(all.rules),
overrides: all.overrides?.map((override) => ({
...override,
rules: turnRulesOff(override.rules),
})),
rules: turnRulesOff([...allRulesNames]),
};

export default config;
5 changes: 2 additions & 3 deletions tests/configs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ test('Config "All" - should have all the non-deprecated rules', (t) => {

test('Config "Off" - should have all the rules "All" has but turned off', (t) => {
const configOffJSRules = Object.keys(off.rules ?? {});
const configOffTSRules = Object.keys(off.overrides?.[0].rules ?? {});
const configOffRules = new Set([...configOffJSRules, ...configOffTSRules]);
t.is(configOffJSRules.length, allNonDeprecatedRules.length);

t.is(configOffRules.size, allNonDeprecatedRules.length);
t.is(off.overrides, undefined, '"Off" config should not have overrides');

for (const [name, value] of Object.entries(off.rules)) {
const severity = Array.isArray(value) ? value[0] : value;
Expand Down

0 comments on commit 5ad533d

Please sign in to comment.