Skip to content

Commit 686b7fe

Browse files
feat: add an off preset
1 parent c3c0849 commit 686b7fe

File tree

4 files changed

+47
-5
lines changed

4 files changed

+47
-5
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ Presets:
152152

153153
- **Recommended** (plugin:functional/recommended)
154154
- **Lite** (plugin:functional/lite)
155+
- **Off** (plugin:functional/off)
155156

156157
Categorized:
157158

src/configs/off.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import type { Linter } from "eslint";
2+
3+
import all from "./all";
4+
5+
function turnRulesOff(rules: Linter.Config["rules"]): Linter.Config["rules"] {
6+
return rules === undefined
7+
? undefined
8+
: Object.fromEntries(
9+
Object.entries(rules).map(([name, value]) => [name, "off"])
10+
);
11+
}
12+
13+
const config: Linter.Config = {
14+
rules: turnRulesOff(all.rules),
15+
overrides: all.overrides?.map((override) => ({
16+
...override,
17+
rules: turnRulesOff(override.rules),
18+
})),
19+
};
20+
21+
export default config;

src/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import noExceptions from "~/configs/no-exceptions";
99
import noMutations from "~/configs/no-mutations";
1010
import noObjectOrientation from "~/configs/no-object-orientation";
1111
import noStatements from "~/configs/no-statements";
12+
import off from "~/configs/off";
1213
import stylistic from "~/configs/stylistic";
1314
import { rules } from "~/rules";
1415

@@ -24,6 +25,7 @@ const config: EslintPluginConfig = {
2425
recommended: functional,
2526
"external-recommended": externalRecommended,
2627
lite: functionalLite,
28+
off,
2729
"no-mutations": noMutations,
2830
"no-exceptions": noExceptions,
2931
"no-object-orientation": noObjectOrientation,

tests/configs.test.ts

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,40 @@ import noExceptions from "~/configs/no-exceptions";
1111
import noMutations from "~/configs/no-mutations";
1212
import noObjectOrientation from "~/configs/no-object-orientation";
1313
import noStatements from "~/configs/no-statements";
14+
import off from "~/configs/off";
1415
import stylistic from "~/configs/stylistic";
1516
import { rules } from "~/rules";
1617

17-
test('Config "All" - should have all the non-deprecated rules', (t) => {
18-
const allRules = Object.values(rules);
19-
const allNonDeprecatedRules = allRules.filter(
20-
(rule) => rule.meta.deprecated !== true
21-
);
18+
const allRules = Object.values(rules);
19+
const allNonDeprecatedRules = allRules.filter(
20+
(rule) => rule.meta.deprecated !== true
21+
);
2222

23+
test('Config "All" - should have all the non-deprecated rules', (t) => {
2324
const configAllJSRules = Object.keys(all.rules ?? {});
2425
const configAllTSRules = Object.keys(all.overrides?.[0].rules ?? {});
2526
const configAllRules = new Set([...configAllJSRules, ...configAllTSRules]);
2627

2728
t.is(configAllRules.size, allNonDeprecatedRules.length);
2829
});
2930

31+
test('Config "Off" - should have all the rules "All" has but turned off', (t) => {
32+
const configOffJSRules = Object.keys(off.rules ?? {});
33+
const configOffTSRules = Object.keys(off.overrides?.[0].rules ?? {});
34+
const configOffRules = new Set([...configOffJSRules, ...configOffTSRules]);
35+
36+
t.is(configOffRules.size, allNonDeprecatedRules.length);
37+
38+
for (const [name, value] of Object.entries(off.rules)) {
39+
const severity = Array.isArray(value) ? value[0] : value;
40+
t.is(
41+
severity,
42+
"off",
43+
`Rule "${name}"" should be turned off in the off config.`
44+
);
45+
}
46+
});
47+
3048
/**
3149
* A map of each config (except the "all" config) to it's name.
3250
*/

0 commit comments

Comments
 (0)