Skip to content

Commit a512ad1

Browse files
authored
Add all config (#1512)
1 parent 7bece2a commit a512ad1

File tree

12 files changed

+199
-139
lines changed

12 files changed

+199
-139
lines changed

configs/all.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
'use strict';
2+
const conflictingRules = require('./conflicting-rules.js');
3+
4+
module.exports = {
5+
...require('./base.js'),
6+
rules: {
7+
...Object.fromEntries(
8+
Object.entries(require('./recommended.js').rules)
9+
.filter(
10+
ruleEntry =>
11+
!Object.keys(conflictingRules.rules).includes(ruleEntry[0]),
12+
)
13+
.map(ruleEntry => [ruleEntry[0], 'error']),
14+
),
15+
...conflictingRules.rules,
16+
},
17+
};

configs/base.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
'use strict';
2+
module.exports = {
3+
env: {
4+
es6: true,
5+
},
6+
parserOptions: {
7+
ecmaVersion: 2021,
8+
sourceType: 'module',
9+
},
10+
plugins: [
11+
'unicorn',
12+
],
13+
};

configs/conflicting-rules.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
'use strict';
2+
module.exports = {
3+
rules: {
4+
'no-nested-ternary': 'off',
5+
},
6+
};

configs/recommended.js

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
'use strict';
2+
module.exports = {
3+
...require('./base.js'),
4+
rules: {
5+
'unicorn/better-regex': 'error',
6+
'unicorn/catch-error-name': 'error',
7+
'unicorn/consistent-destructuring': 'error',
8+
'unicorn/consistent-function-scoping': 'error',
9+
'unicorn/custom-error-definition': 'off',
10+
'unicorn/empty-brace-spaces': 'error',
11+
'unicorn/error-message': 'error',
12+
'unicorn/escape-case': 'error',
13+
'unicorn/expiring-todo-comments': 'error',
14+
'unicorn/explicit-length-check': 'error',
15+
'unicorn/filename-case': 'error',
16+
'unicorn/import-index': 'off',
17+
'unicorn/import-style': 'error',
18+
'unicorn/new-for-builtins': 'error',
19+
'unicorn/no-abusive-eslint-disable': 'error',
20+
'unicorn/no-array-callback-reference': 'error',
21+
'unicorn/no-array-for-each': 'error',
22+
'unicorn/no-array-method-this-argument': 'error',
23+
'unicorn/no-array-push-push': 'error',
24+
'unicorn/no-array-reduce': 'error',
25+
'unicorn/no-console-spaces': 'error',
26+
'unicorn/no-document-cookie': 'error',
27+
'unicorn/no-for-loop': 'error',
28+
'unicorn/no-hex-escape': 'error',
29+
'unicorn/no-instanceof-array': 'error',
30+
'unicorn/no-invalid-remove-event-listener': 'error',
31+
'unicorn/no-keyword-prefix': 'off',
32+
'unicorn/no-lonely-if': 'error',
33+
'no-nested-ternary': 'off',
34+
'unicorn/no-nested-ternary': 'error',
35+
'unicorn/no-new-array': 'error',
36+
'unicorn/no-new-buffer': 'error',
37+
'unicorn/no-null': 'error',
38+
'unicorn/no-object-as-default-parameter': 'error',
39+
'unicorn/no-process-exit': 'error',
40+
'unicorn/no-static-only-class': 'error',
41+
'unicorn/no-this-assignment': 'error',
42+
'unicorn/no-unreadable-array-destructuring': 'error',
43+
'unicorn/no-unsafe-regex': 'off',
44+
'unicorn/no-unused-properties': 'off',
45+
'unicorn/no-useless-fallback-in-spread': 'error',
46+
'unicorn/no-useless-length-check': 'error',
47+
'unicorn/no-useless-spread': 'error',
48+
'unicorn/no-useless-undefined': 'error',
49+
'unicorn/no-zero-fractions': 'error',
50+
'unicorn/number-literal-case': 'error',
51+
'unicorn/numeric-separators-style': 'error',
52+
'unicorn/prefer-add-event-listener': 'error',
53+
'unicorn/prefer-array-find': 'error',
54+
'unicorn/prefer-array-flat': 'error',
55+
'unicorn/prefer-array-flat-map': 'error',
56+
'unicorn/prefer-array-index-of': 'error',
57+
'unicorn/prefer-array-some': 'error',
58+
// TODO: Enable this by default when targeting a Node.js version that supports `Array#at`.
59+
'unicorn/prefer-at': 'off',
60+
'unicorn/prefer-date-now': 'error',
61+
'unicorn/prefer-default-parameters': 'error',
62+
'unicorn/prefer-dom-node-append': 'error',
63+
'unicorn/prefer-dom-node-dataset': 'error',
64+
'unicorn/prefer-dom-node-remove': 'error',
65+
'unicorn/prefer-dom-node-text-content': 'error',
66+
'unicorn/prefer-includes': 'error',
67+
'unicorn/prefer-keyboard-event-key': 'error',
68+
'unicorn/prefer-math-trunc': 'error',
69+
'unicorn/prefer-modern-dom-apis': 'error',
70+
'unicorn/prefer-module': 'error',
71+
'unicorn/prefer-negative-index': 'error',
72+
'unicorn/prefer-node-protocol': 'error',
73+
'unicorn/prefer-number-properties': 'error',
74+
'unicorn/prefer-object-from-entries': 'error',
75+
// TODO: Enable this by default when targeting a Node.js version that supports `Object.hasOwn`.
76+
'unicorn/prefer-object-has-own': 'off',
77+
'unicorn/prefer-optional-catch-binding': 'error',
78+
'unicorn/prefer-prototype-methods': 'error',
79+
'unicorn/prefer-query-selector': 'error',
80+
'unicorn/prefer-reflect-apply': 'error',
81+
'unicorn/prefer-regexp-test': 'error',
82+
'unicorn/prefer-set-has': 'error',
83+
'unicorn/prefer-spread': 'error',
84+
// TODO: Enable this by default when targeting Node.js 16.
85+
'unicorn/prefer-string-replace-all': 'off',
86+
'unicorn/prefer-string-slice': 'error',
87+
'unicorn/prefer-string-starts-ends-with': 'error',
88+
'unicorn/prefer-string-trim-start-end': 'error',
89+
'unicorn/prefer-switch': 'error',
90+
'unicorn/prefer-ternary': 'error',
91+
// TODO: Enable this by default when targeting Node.js 14.
92+
'unicorn/prefer-top-level-await': 'off',
93+
'unicorn/prefer-type-error': 'error',
94+
'unicorn/prevent-abbreviations': 'error',
95+
'unicorn/require-array-join-separator': 'error',
96+
'unicorn/require-number-to-fixed-digits-argument': 'error',
97+
'unicorn/require-post-message-target-origin': 'error',
98+
'unicorn/string-content': 'off',
99+
'unicorn/throw-new-error': 'error',
100+
...require('./conflicting-rules.js').rules,
101+
},
102+
overrides: [
103+
{
104+
files: ['*.ts', '*.tsx'],
105+
rules: {
106+
'unicorn/require-post-message-target-origin': 'off',
107+
},
108+
},
109+
],
110+
};

docs/new-rule.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Use the [`astexplorer` site](https://astexplorer.net) with the `espree` parser a
1717
- Open “rules/{RULE_ID}.js” and implement the rule logic.
1818
- Add the correct [`meta.type`](https://eslint.org/docs/developer-guide/working-with-rules#rule-basics) to the rule.
1919
- Open “docs/rules/{RULE_ID}.js” and write some documentation.
20-
- Double check `index.js` and `readme.md`, make sure the new rule is correctly added.
20+
- Double check `configs/recommended.js` and `readme.md`, make sure the new rule is correctly added.
2121
- Run `$ npm test` to ensure the tests pass.
2222
- Run `$ npm run integration` to run the rules against real projects to ensure your rule does not fail on real-world code.
2323
- Open a pull request with a title in exactly the format `` Add `rule-name` rule ``, for example, `` Add `no-unused-properties` rule ``.

index.js

Lines changed: 4 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
'use strict';
22
const createDeprecatedRules = require('./rules/utils/create-deprecated-rules.js');
33
const {loadRules} = require('./rules/utils/rule.js');
4+
const recommendedConfig = require('./configs/recommended.js');
5+
const all = require('./configs/all.js');
46

57
const deprecatedRules = createDeprecatedRules({
68
// {ruleId: ReplacementRuleId | ReplacementRuleId[]}, if no replacement, use `{ruleId: []}`
@@ -26,122 +28,7 @@ module.exports = {
2628
...deprecatedRules,
2729
},
2830
configs: {
29-
recommended: {
30-
env: {
31-
es6: true,
32-
},
33-
parserOptions: {
34-
ecmaVersion: 2021,
35-
sourceType: 'module',
36-
},
37-
plugins: [
38-
'unicorn',
39-
],
40-
rules: {
41-
'unicorn/better-regex': 'error',
42-
'unicorn/catch-error-name': 'error',
43-
'unicorn/consistent-destructuring': 'error',
44-
'unicorn/consistent-function-scoping': 'error',
45-
'unicorn/custom-error-definition': 'off',
46-
'unicorn/empty-brace-spaces': 'error',
47-
'unicorn/error-message': 'error',
48-
'unicorn/escape-case': 'error',
49-
'unicorn/expiring-todo-comments': 'error',
50-
'unicorn/explicit-length-check': 'error',
51-
'unicorn/filename-case': 'error',
52-
'unicorn/import-index': 'off',
53-
'unicorn/import-style': 'error',
54-
'unicorn/new-for-builtins': 'error',
55-
'unicorn/no-abusive-eslint-disable': 'error',
56-
'unicorn/no-array-callback-reference': 'error',
57-
'unicorn/no-array-for-each': 'error',
58-
'unicorn/no-array-method-this-argument': 'error',
59-
'unicorn/no-array-push-push': 'error',
60-
'unicorn/no-array-reduce': 'error',
61-
'unicorn/no-console-spaces': 'error',
62-
'unicorn/no-document-cookie': 'error',
63-
'unicorn/no-for-loop': 'error',
64-
'unicorn/no-hex-escape': 'error',
65-
'unicorn/no-instanceof-array': 'error',
66-
'unicorn/no-invalid-remove-event-listener': 'error',
67-
'unicorn/no-keyword-prefix': 'off',
68-
'unicorn/no-lonely-if': 'error',
69-
'no-nested-ternary': 'off',
70-
'unicorn/no-nested-ternary': 'error',
71-
'unicorn/no-new-array': 'error',
72-
'unicorn/no-new-buffer': 'error',
73-
'unicorn/no-null': 'error',
74-
'unicorn/no-object-as-default-parameter': 'error',
75-
'unicorn/no-process-exit': 'error',
76-
'unicorn/no-static-only-class': 'error',
77-
'unicorn/no-this-assignment': 'error',
78-
'unicorn/no-unreadable-array-destructuring': 'error',
79-
'unicorn/no-unsafe-regex': 'off',
80-
'unicorn/no-unused-properties': 'off',
81-
'unicorn/no-useless-fallback-in-spread': 'error',
82-
'unicorn/no-useless-length-check': 'error',
83-
'unicorn/no-useless-spread': 'error',
84-
'unicorn/no-useless-undefined': 'error',
85-
'unicorn/no-zero-fractions': 'error',
86-
'unicorn/number-literal-case': 'error',
87-
'unicorn/numeric-separators-style': 'error',
88-
'unicorn/prefer-add-event-listener': 'error',
89-
'unicorn/prefer-array-find': 'error',
90-
'unicorn/prefer-array-flat': 'error',
91-
'unicorn/prefer-array-flat-map': 'error',
92-
'unicorn/prefer-array-index-of': 'error',
93-
'unicorn/prefer-array-some': 'error',
94-
// TODO: Enable this by default when targeting a Node.js version that supports `Array#at`.
95-
'unicorn/prefer-at': 'off',
96-
'unicorn/prefer-date-now': 'error',
97-
'unicorn/prefer-default-parameters': 'error',
98-
'unicorn/prefer-dom-node-append': 'error',
99-
'unicorn/prefer-dom-node-dataset': 'error',
100-
'unicorn/prefer-dom-node-remove': 'error',
101-
'unicorn/prefer-dom-node-text-content': 'error',
102-
'unicorn/prefer-includes': 'error',
103-
'unicorn/prefer-keyboard-event-key': 'error',
104-
'unicorn/prefer-math-trunc': 'error',
105-
'unicorn/prefer-modern-dom-apis': 'error',
106-
'unicorn/prefer-module': 'error',
107-
'unicorn/prefer-negative-index': 'error',
108-
'unicorn/prefer-node-protocol': 'error',
109-
'unicorn/prefer-number-properties': 'error',
110-
'unicorn/prefer-object-from-entries': 'error',
111-
// TODO: Enable this by default when targeting a Node.js version that supports `Object.hasOwn`.
112-
'unicorn/prefer-object-has-own': 'off',
113-
'unicorn/prefer-optional-catch-binding': 'error',
114-
'unicorn/prefer-prototype-methods': 'error',
115-
'unicorn/prefer-query-selector': 'error',
116-
'unicorn/prefer-reflect-apply': 'error',
117-
'unicorn/prefer-regexp-test': 'error',
118-
'unicorn/prefer-set-has': 'error',
119-
'unicorn/prefer-spread': 'error',
120-
// TODO: Enable this by default when targeting Node.js 16.
121-
'unicorn/prefer-string-replace-all': 'off',
122-
'unicorn/prefer-string-slice': 'error',
123-
'unicorn/prefer-string-starts-ends-with': 'error',
124-
'unicorn/prefer-string-trim-start-end': 'error',
125-
'unicorn/prefer-switch': 'error',
126-
'unicorn/prefer-ternary': 'error',
127-
// TODO: Enable this by default when targeting Node.js 14.
128-
'unicorn/prefer-top-level-await': 'off',
129-
'unicorn/prefer-type-error': 'error',
130-
'unicorn/prevent-abbreviations': 'error',
131-
'unicorn/require-array-join-separator': 'error',
132-
'unicorn/require-number-to-fixed-digits-argument': 'error',
133-
'unicorn/require-post-message-target-origin': 'error',
134-
'unicorn/string-content': 'off',
135-
'unicorn/throw-new-error': 'error',
136-
},
137-
overrides: [
138-
{
139-
files: ['*.ts', '*.tsx'],
140-
rules: {
141-
'unicorn/require-post-message-target-origin': 'off',
142-
},
143-
},
144-
],
145-
},
31+
recommended: recommendedConfig,
32+
all,
14633
},
14734
};

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@
2424
},
2525
"files": [
2626
"index.js",
27-
"rules"
27+
"rules",
28+
"configs"
2829
],
2930
"keywords": [
3031
"eslint",

readme.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,7 @@ See [docs/deprecated-rules.md](docs/deprecated-rules.md)
255255

256256
## Recommended config
257257

258-
This plugin exports a [`recommended` config](index.js) that enforces good practices.
258+
This plugin exports a [`recommended` config](configs/recommended.js) that enforces good practices.
259259

260260
Enable it in your `package.json` with the `extends` option:
261261

@@ -272,6 +272,23 @@ See the [ESLint docs](https://eslint.org/docs/user-guide/configuring/configurati
272272

273273
**Note**: This config will also enable the correct [parser options](https://eslint.org/docs/user-guide/configuring/language-options#specifying-parser-options) and [environment](https://eslint.org/docs/user-guide/configuring/language-options#specifying-environments).
274274

275+
## All config
276+
277+
This plugin exports an [`all` config](configs/all.js) that makes use of all rules (except for deprecated ones).
278+
279+
Enable it in your `package.json` with the `extends` option:
280+
281+
```json
282+
{
283+
"name": "my-awesome-project",
284+
"eslintConfig": {
285+
"extends": "plugin:unicorn/all"
286+
}
287+
}
288+
```
289+
290+
See the [ESLint docs](https://eslint.org/docs/user-guide/configuring/configuration-files#extending-configuration-files) for more information about extending config files.
291+
275292
## Maintainers
276293

277294
- [Sindre Sorhus](https://github.com/sindresorhus)

scripts/create-rule.mjs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,20 +36,20 @@ function renderTemplate({source, target, data}) {
3636
return fs.writeFileSync(targetFile, content);
3737
}
3838

39-
function updateIndex(id) {
40-
const RULE_START = '\t\t\trules: {\n';
41-
const RULE_END = '\n\t\t\t}';
42-
const RULE_INDENT = '\t'.repeat(4);
39+
function updateRecommended(id) {
40+
const RULE_START = '\n\trules: {\n';
41+
const RULE_END = '\n\t}';
42+
const RULE_INDENT = '\t'.repeat(2);
4343
let ruleContent = `${RULE_INDENT}'unicorn/${id}': 'error',`;
4444

45-
const file = path.join(ROOT, 'index.js');
45+
const file = path.join(ROOT, 'configs/recommended.js');
4646
const content = fs.readFileSync(file, 'utf8');
4747
const [before, rest] = content.split(RULE_START);
4848
const [rules, after] = rest.split(RULE_END);
4949

5050
const lines = rules.split('\n');
5151
if (!lines.every(line => line.startsWith(RULE_INDENT))) {
52-
throw new Error('Unexpected content in “index.js”.');
52+
throw new Error('Unexpected content in “configs/recommended.js”.');
5353
}
5454

5555
const unicornRuleLines = lines.filter(line => line.startsWith(`${RULE_INDENT}'unicorn/`));
@@ -156,7 +156,7 @@ function updateIndex(id) {
156156
target: `test/${id}.mjs`,
157157
data,
158158
});
159-
updateIndex(id);
159+
updateRecommended(id);
160160

161161
try {
162162
await execa('code', [

0 commit comments

Comments
 (0)