-
-
Notifications
You must be signed in to change notification settings - Fork 474
Expand file tree
/
Copy pathindex.js
More file actions
95 lines (82 loc) · 2.72 KB
/
index.js
File metadata and controls
95 lines (82 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import createDeprecatedRules from './rules/utils/create-deprecated-rules.js';
import flatConfigBase from './configs/flat-config-base.js';
import * as rawRules from './rules/index.js';
import {toEslintRules} from './rules/rule/index.js';
import packageJson from './package.json' with {type: 'json'};
const rules = toEslintRules(rawRules);
const deprecatedRules = createDeprecatedRules({
'better-regex': {
message: 'Removed. Prefer `eslint-plugin-regexp`',
replacedBy: [],
},
'no-instanceof-array': {
message: 'Replaced by `unicorn/no-instanceof-builtins` which covers more cases.',
replacedBy: ['unicorn/no-instanceof-builtins'],
},
'no-length-as-slice-end': {
message: 'Replaced by `unicorn/no-unnecessary-slice-end` which covers more cases.',
replacedBy: ['unicorn/no-unnecessary-slice-end'],
},
'no-array-push-push': {
message: 'Replaced by `unicorn/prefer-single-call` which covers more cases.',
replacedBy: ['unicorn/prefer-single-call'],
},
'prefer-json-parse-buffer': {
message: 'Renamed to `unicorn/consistent-json-file-read`.',
replacedBy: ['unicorn/consistent-json-file-read'],
},
'prefer-dom-node-dataset': {
message: 'Renamed to `unicorn/dom-node-dataset`.',
replacedBy: ['unicorn/dom-node-dataset'],
},
});
const externalRules = {
// Covered by `unicorn/no-negated-condition`
'no-negated-condition': 'off',
// Covered by `unicorn/no-nested-ternary`
'no-nested-ternary': 'off',
};
const recommendedRules = Object.fromEntries(Object.entries(rules).map(([id, rule]) => [
`unicorn/${id}`,
rule.meta.docs.recommended ? 'error' : 'off',
]));
const unopinionatedRules = Object.fromEntries(Object.entries(rules).map(([id, rule]) => [
`unicorn/${id}`,
rule.meta.docs.recommended === 'unopinionated' ? 'error' : 'off',
]));
// TODO: Enable `prefer-iterator-concat` in the recommended and unopinionated configs when targeting Node.js 26.
const allRules = Object.fromEntries(Object.keys(rules).map(id => [
`unicorn/${id}`,
'error',
]));
const createConfig = (rules, flatConfigName) => ({
...flatConfigBase,
name: flatConfigName,
plugins: {
unicorn,
},
rules: {
...externalRules,
...rules,
},
});
const unicorn = {
meta: {
name: packageJson.name,
version: packageJson.version,
},
rules: {
...rules,
...deprecatedRules,
},
};
const configs = {
recommended: createConfig(recommendedRules, 'unicorn/recommended'),
unopinionated: createConfig(unopinionatedRules, 'unicorn/unopinionated'),
all: createConfig(allRules, 'unicorn/all'),
// TODO: Remove this at some point. Kept for now to avoid breaking users.
'flat/recommended': createConfig(recommendedRules, 'unicorn/flat/recommended'),
'flat/all': createConfig(allRules, 'unicorn/flat/all'),
};
unicorn.configs = configs;
export default unicorn;