Skip to content

Commit 9e7fad4

Browse files
chore: add script to auto-generate eslint:recommended configuration (#20208)
* chore: add script to auto-generate eslint:recommended configuration * Update tools/update-eslint-recommended.js Co-authored-by: 루밀LuMir <[email protected]> * chore: regen eslint-recommended.js * chore: prettier ignore auto-generated files * fix: review suggestions --------- Co-authored-by: 루밀LuMir <[email protected]>
1 parent 7b9446f commit 9e7fad4

4 files changed

Lines changed: 131 additions & 71 deletions

File tree

‎.prettierignore‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ docs/src/use/formatters/html-formatter-example.html
1010
docs/src/use/formatters/index.md
1111
docs/src/rules/*.md
1212
packages/js/src/configs/eslint-all.js
13+
packages/js/src/configs/eslint-recommended.js
1314
tests/fixtures

‎package.json‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,9 @@
8383
"*": "trunk check --fix",
8484
"lib/rules/*.js": [
8585
"node tools/update-eslint-all.js",
86+
"node tools/update-eslint-recommended.js",
8687
"node tools/update-rule-type-headers.js",
87-
"git add packages/js/src/configs/eslint-all.js lib/types/rules.d.ts"
88+
"git add packages/js/src/configs/*.js lib/types/rules.d.ts"
8889
],
8990
"docs/src/rules/*.md": [
9091
"node tools/check-rule-examples.js",
Lines changed: 66 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
/**
2-
* @fileoverview Configuration applied when a user configuration extends from
3-
* eslint:recommended.
4-
* @author Nicholas C. Zakas
1+
/*
2+
* WARNING: This file is autogenerated using the tools/update-eslint-recommended.js
3+
* script. Do not edit manually.
54
*/
6-
75
"use strict";
86

9-
/* eslint sort-keys: ["error", "asc"] -- Long, so make more readable */
10-
117
/*
128
* IMPORTANT!
139
*
@@ -17,67 +13,67 @@
1713
*/
1814

1915
module.exports = Object.freeze({
20-
rules: Object.freeze({
21-
"constructor-super": "error",
22-
"for-direction": "error",
23-
"getter-return": "error",
24-
"no-async-promise-executor": "error",
25-
"no-case-declarations": "error",
26-
"no-class-assign": "error",
27-
"no-compare-neg-zero": "error",
28-
"no-cond-assign": "error",
29-
"no-const-assign": "error",
30-
"no-constant-binary-expression": "error",
31-
"no-constant-condition": "error",
32-
"no-control-regex": "error",
33-
"no-debugger": "error",
34-
"no-delete-var": "error",
35-
"no-dupe-args": "error",
36-
"no-dupe-class-members": "error",
37-
"no-dupe-else-if": "error",
38-
"no-dupe-keys": "error",
39-
"no-duplicate-case": "error",
40-
"no-empty": "error",
41-
"no-empty-character-class": "error",
42-
"no-empty-pattern": "error",
43-
"no-empty-static-block": "error",
44-
"no-ex-assign": "error",
45-
"no-extra-boolean-cast": "error",
46-
"no-fallthrough": "error",
47-
"no-func-assign": "error",
48-
"no-global-assign": "error",
49-
"no-import-assign": "error",
50-
"no-invalid-regexp": "error",
51-
"no-irregular-whitespace": "error",
52-
"no-loss-of-precision": "error",
53-
"no-misleading-character-class": "error",
54-
"no-new-native-nonconstructor": "error",
55-
"no-nonoctal-decimal-escape": "error",
56-
"no-obj-calls": "error",
57-
"no-octal": "error",
58-
"no-prototype-builtins": "error",
59-
"no-redeclare": "error",
60-
"no-regex-spaces": "error",
61-
"no-self-assign": "error",
62-
"no-setter-return": "error",
63-
"no-shadow-restricted-names": "error",
64-
"no-sparse-arrays": "error",
65-
"no-this-before-super": "error",
66-
"no-undef": "error",
67-
"no-unexpected-multiline": "error",
68-
"no-unreachable": "error",
69-
"no-unsafe-finally": "error",
70-
"no-unsafe-negation": "error",
71-
"no-unsafe-optional-chaining": "error",
72-
"no-unused-labels": "error",
73-
"no-unused-private-class-members": "error",
74-
"no-unused-vars": "error",
75-
"no-useless-backreference": "error",
76-
"no-useless-catch": "error",
77-
"no-useless-escape": "error",
78-
"no-with": "error",
79-
"require-yield": "error",
80-
"use-isnan": "error",
81-
"valid-typeof": "error",
82-
}),
16+
rules: Object.freeze({
17+
"constructor-super": "error",
18+
"for-direction": "error",
19+
"getter-return": "error",
20+
"no-async-promise-executor": "error",
21+
"no-case-declarations": "error",
22+
"no-class-assign": "error",
23+
"no-compare-neg-zero": "error",
24+
"no-cond-assign": "error",
25+
"no-const-assign": "error",
26+
"no-constant-binary-expression": "error",
27+
"no-constant-condition": "error",
28+
"no-control-regex": "error",
29+
"no-debugger": "error",
30+
"no-delete-var": "error",
31+
"no-dupe-args": "error",
32+
"no-dupe-class-members": "error",
33+
"no-dupe-else-if": "error",
34+
"no-dupe-keys": "error",
35+
"no-duplicate-case": "error",
36+
"no-empty": "error",
37+
"no-empty-character-class": "error",
38+
"no-empty-pattern": "error",
39+
"no-empty-static-block": "error",
40+
"no-ex-assign": "error",
41+
"no-extra-boolean-cast": "error",
42+
"no-fallthrough": "error",
43+
"no-func-assign": "error",
44+
"no-global-assign": "error",
45+
"no-import-assign": "error",
46+
"no-invalid-regexp": "error",
47+
"no-irregular-whitespace": "error",
48+
"no-loss-of-precision": "error",
49+
"no-misleading-character-class": "error",
50+
"no-new-native-nonconstructor": "error",
51+
"no-nonoctal-decimal-escape": "error",
52+
"no-obj-calls": "error",
53+
"no-octal": "error",
54+
"no-prototype-builtins": "error",
55+
"no-redeclare": "error",
56+
"no-regex-spaces": "error",
57+
"no-self-assign": "error",
58+
"no-setter-return": "error",
59+
"no-shadow-restricted-names": "error",
60+
"no-sparse-arrays": "error",
61+
"no-this-before-super": "error",
62+
"no-undef": "error",
63+
"no-unexpected-multiline": "error",
64+
"no-unreachable": "error",
65+
"no-unsafe-finally": "error",
66+
"no-unsafe-negation": "error",
67+
"no-unsafe-optional-chaining": "error",
68+
"no-unused-labels": "error",
69+
"no-unused-private-class-members": "error",
70+
"no-unused-vars": "error",
71+
"no-useless-backreference": "error",
72+
"no-useless-catch": "error",
73+
"no-useless-escape": "error",
74+
"no-with": "error",
75+
"require-yield": "error",
76+
"use-isnan": "error",
77+
"valid-typeof": "error"
78+
}),
8379
});

‎tools/update-eslint-recommended.js‎

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
/**
2+
* @fileoverview Script to update the eslint:recommended configuration.
3+
* @author aladdin-add<[email protected]>
4+
*/
5+
6+
"use strict";
7+
8+
//-----------------------------------------------------------------------------
9+
// Requirements
10+
//-----------------------------------------------------------------------------
11+
12+
const fs = require("node:fs");
13+
const builtInRules = require("../lib/rules");
14+
15+
//------------------------------------------------------------------------------
16+
// Helpers
17+
//------------------------------------------------------------------------------
18+
19+
const recommendedRule = {};
20+
21+
for (const [ruleId, rule] of builtInRules) {
22+
if (!rule.meta.deprecated) {
23+
if (rule.meta.docs.recommended === true) {
24+
recommendedRule[ruleId] = "error";
25+
}
26+
}
27+
}
28+
29+
const recommendedRulesText = JSON.stringify(
30+
recommendedRule,
31+
null,
32+
4,
33+
).replaceAll("\n", "\n ");
34+
35+
//-----------------------------------------------------------------------------
36+
// Main
37+
//-----------------------------------------------------------------------------
38+
39+
const code = `/*
40+
* WARNING: This file is autogenerated using the tools/update-eslint-recommended.js
41+
* script. Do not edit manually.
42+
*/
43+
"use strict";
44+
45+
/*
46+
* IMPORTANT!
47+
*
48+
* We cannot add a "name" property to this object because it's still used in eslintrc
49+
* which doesn't support the "name" property. If we add a "name" property, it will
50+
* cause an error.
51+
*/
52+
53+
module.exports = Object.freeze({
54+
rules: Object.freeze(${recommendedRulesText}),
55+
});
56+
`;
57+
58+
fs.writeFileSync(
59+
"./packages/js/src/configs/eslint-recommended.js",
60+
code,
61+
"utf8",
62+
);

0 commit comments

Comments
 (0)