1 | 'use strict';
|
2 | const createDeprecatedRules = require('./rules/utils/create-deprecated-rules.js');
|
3 | const {loadRules} = require('./rules/utils/rule.js');
|
4 | const legacyConfigBase = require('./configs/legacy-config-base.js');
|
5 | const flatConfigBase = require('./configs/flat-config-base.js');
|
6 | const {name, version} = require('./package.json');
|
7 |
|
8 | const deprecatedRules = createDeprecatedRules({
|
9 |
|
10 | 'import-index': [],
|
11 | 'no-array-instanceof': 'unicorn/no-instanceof-array',
|
12 | 'no-fn-reference-in-iterator': 'unicorn/no-array-callback-reference',
|
13 | 'no-reduce': 'unicorn/no-array-reduce',
|
14 | 'no-unsafe-regex': [],
|
15 | 'prefer-dataset': 'unicorn/prefer-dom-node-dataset',
|
16 | 'prefer-event-key': 'unicorn/prefer-keyboard-event-key',
|
17 | 'prefer-exponentiation-operator': 'prefer-exponentiation-operator',
|
18 | 'prefer-flat-map': 'unicorn/prefer-array-flat-map',
|
19 | 'prefer-node-append': 'unicorn/prefer-dom-node-append',
|
20 | 'prefer-node-remove': 'unicorn/prefer-dom-node-remove',
|
21 | 'prefer-object-has-own': 'prefer-object-has-own',
|
22 | 'prefer-replace-all': 'unicorn/prefer-string-replace-all',
|
23 | 'prefer-starts-ends-with': 'unicorn/prefer-string-starts-ends-with',
|
24 | 'prefer-text-content': 'unicorn/prefer-dom-node-text-content',
|
25 | 'prefer-trim-start-end': 'unicorn/prefer-string-trim-start-end',
|
26 | 'regex-shorthand': 'unicorn/better-regex',
|
27 | });
|
28 |
|
29 | const externalRules = {
|
30 |
|
31 | 'no-negated-condition': 'off',
|
32 |
|
33 | 'no-nested-ternary': 'off',
|
34 | };
|
35 |
|
36 | const rules = loadRules();
|
37 | const recommendedRules = Object.fromEntries(
|
38 | Object.entries(rules).map(([id, rule]) => [
|
39 | `unicorn/${id}`,
|
40 | rule.meta.docs.recommended ? 'error' : 'off',
|
41 | ]),
|
42 | );
|
43 | const allRules = Object.fromEntries(
|
44 | Object.keys(rules).map(id => [
|
45 | `unicorn/${id}`,
|
46 | 'error',
|
47 | ]),
|
48 | );
|
49 |
|
50 | const createConfig = (rules, isLegacyConfig = false) => ({
|
51 | ...(isLegacyConfig ? legacyConfigBase : flatConfigBase),
|
52 | plugins: isLegacyConfig ? ['unicorn'] : {unicorn},
|
53 | rules: {...externalRules, ...rules},
|
54 | });
|
55 |
|
56 | const unicorn = {
|
57 | meta: {
|
58 | name,
|
59 | version,
|
60 | },
|
61 | rules: {
|
62 | ...rules,
|
63 | ...deprecatedRules,
|
64 | },
|
65 | };
|
66 |
|
67 | const configs = {
|
68 | recommended: createConfig(recommendedRules, true),
|
69 | all: createConfig(allRules, true),
|
70 | 'flat/recommended': createConfig(recommendedRules),
|
71 | 'flat/all': createConfig(allRules),
|
72 | };
|
73 |
|
74 | module.exports = {...unicorn, configs};
|