Skip to content

Commit dccee63

Browse files
Chore: avoid hard-coding the list of core rules in eslint:recommended (#11336)
This updates the `eslint:recommended` config to be generated dynamically rather than being hard-coded, to reduce the number of places that need to be kept up to date when core rules are added.
1 parent c1fd6f5 commit dccee63

File tree

2 files changed

+4
-284
lines changed

2 files changed

+4
-284
lines changed

Makefile.js

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,6 @@ target.checkRuleFiles = function() {
837837

838838
echo("Validating rules");
839839

840-
const eslintRecommended = require("./conf/eslint-recommended").rules;
841840
const ruleTypes = require("./tools/rule-types.json");
842841
const ruleFiles = find("lib/rules/").filter(fileType("js"));
843842
let errors = 0;
@@ -846,15 +845,6 @@ target.checkRuleFiles = function() {
846845
const basename = path.basename(filename, ".js");
847846
const docFilename = `docs/rules/${basename}.md`;
848847

849-
/**
850-
* Check if basename is present in eslint:recommended configuration.
851-
* @returns {boolean} true if present
852-
* @private
853-
*/
854-
function isInConfig() {
855-
return Object.prototype.hasOwnProperty.call(eslintRecommended, basename);
856-
}
857-
858848
/**
859849
* Check if basename is present in rule-types.json file.
860850
* @returns {boolean} true if present
@@ -896,12 +886,6 @@ target.checkRuleFiles = function() {
896886
}
897887
}
898888

899-
// check for recommended configuration
900-
if (!isInConfig()) {
901-
console.error("Missing eslint:recommended setting for %s in conf/eslint-recommended.js", basename);
902-
errors++;
903-
}
904-
905889
// check for recommended configuration
906890
if (!isInRuleTypes()) {
907891
console.error("Missing setting for %s in tools/rule-types.json", basename);

conf/eslint-recommended.js

Lines changed: 4 additions & 268 deletions
Original file line numberDiff line numberDiff line change
@@ -6,274 +6,10 @@
66

77
"use strict";
88

9-
/* eslint sort-keys: ["error", "asc"] */
9+
const builtInRules = require("../lib/built-in-rules-index");
1010

1111
module.exports = {
12-
rules: {
13-
"accessor-pairs": "off",
14-
"array-bracket-newline": "off",
15-
"array-bracket-spacing": "off",
16-
"array-callback-return": "off",
17-
"array-element-newline": "off",
18-
"arrow-body-style": "off",
19-
"arrow-parens": "off",
20-
"arrow-spacing": "off",
21-
"block-scoped-var": "off",
22-
"block-spacing": "off",
23-
"brace-style": "off",
24-
"callback-return": "off",
25-
camelcase: "off",
26-
"capitalized-comments": "off",
27-
"class-methods-use-this": "off",
28-
"comma-dangle": "off",
29-
"comma-spacing": "off",
30-
"comma-style": "off",
31-
complexity: "off",
32-
"computed-property-spacing": "off",
33-
"consistent-return": "off",
34-
"consistent-this": "off",
35-
"constructor-super": "error",
36-
curly: "off",
37-
"default-case": "off",
38-
"dot-location": "off",
39-
"dot-notation": "off",
40-
"eol-last": "off",
41-
eqeqeq: "off",
42-
"for-direction": "error",
43-
"func-call-spacing": "off",
44-
"func-name-matching": "off",
45-
"func-names": "off",
46-
"func-style": "off",
47-
"function-paren-newline": "off",
48-
"generator-star-spacing": "off",
49-
"getter-return": "error",
50-
"global-require": "off",
51-
"guard-for-in": "off",
52-
"handle-callback-err": "off",
53-
"id-blacklist": "off",
54-
"id-length": "off",
55-
"id-match": "off",
56-
"implicit-arrow-linebreak": "off",
57-
indent: "off",
58-
"indent-legacy": "off",
59-
"init-declarations": "off",
60-
"jsx-quotes": "off",
61-
"key-spacing": "off",
62-
"keyword-spacing": "off",
63-
"line-comment-position": "off",
64-
"linebreak-style": "off",
65-
"lines-around-comment": "off",
66-
"lines-around-directive": "off",
67-
"lines-between-class-members": "off",
68-
"max-classes-per-file": "off",
69-
"max-depth": "off",
70-
"max-len": "off",
71-
"max-lines": "off",
72-
"max-lines-per-function": "off",
73-
"max-nested-callbacks": "off",
74-
"max-params": "off",
75-
"max-statements": "off",
76-
"max-statements-per-line": "off",
77-
"multiline-comment-style": "off",
78-
"multiline-ternary": "off",
79-
"new-cap": "off",
80-
"new-parens": "off",
81-
"newline-after-var": "off",
82-
"newline-before-return": "off",
83-
"newline-per-chained-call": "off",
84-
"no-alert": "off",
85-
"no-array-constructor": "off",
86-
"no-async-promise-executor": "off",
87-
"no-await-in-loop": "off",
88-
"no-bitwise": "off",
89-
"no-buffer-constructor": "off",
90-
"no-caller": "off",
91-
"no-case-declarations": "error",
92-
"no-catch-shadow": "off",
93-
"no-class-assign": "error",
94-
"no-compare-neg-zero": "error",
95-
"no-cond-assign": "error",
96-
"no-confusing-arrow": "off",
97-
"no-console": "error",
98-
"no-const-assign": "error",
99-
"no-constant-condition": "error",
100-
"no-continue": "off",
101-
"no-control-regex": "error",
102-
"no-debugger": "error",
103-
"no-delete-var": "error",
104-
"no-div-regex": "off",
105-
"no-dupe-args": "error",
106-
"no-dupe-class-members": "error",
107-
"no-dupe-keys": "error",
108-
"no-duplicate-case": "error",
109-
"no-duplicate-imports": "off",
110-
"no-else-return": "off",
111-
"no-empty": "error",
112-
"no-empty-character-class": "error",
113-
"no-empty-function": "off",
114-
"no-empty-pattern": "error",
115-
"no-eq-null": "off",
116-
"no-eval": "off",
117-
"no-ex-assign": "error",
118-
"no-extend-native": "off",
119-
"no-extra-bind": "off",
120-
"no-extra-boolean-cast": "error",
121-
"no-extra-label": "off",
122-
"no-extra-parens": "off",
123-
"no-extra-semi": "error",
124-
"no-fallthrough": "error",
125-
"no-floating-decimal": "off",
126-
"no-func-assign": "error",
127-
"no-global-assign": "error",
128-
"no-implicit-coercion": "off",
129-
"no-implicit-globals": "off",
130-
"no-implied-eval": "off",
131-
"no-inline-comments": "off",
132-
"no-inner-declarations": "error",
133-
"no-invalid-regexp": "error",
134-
"no-invalid-this": "off",
135-
"no-irregular-whitespace": "error",
136-
"no-iterator": "off",
137-
"no-label-var": "off",
138-
"no-labels": "off",
139-
"no-lone-blocks": "off",
140-
"no-lonely-if": "off",
141-
"no-loop-func": "off",
142-
"no-magic-numbers": "off",
143-
"no-misleading-character-class": "off",
144-
"no-mixed-operators": "off",
145-
"no-mixed-requires": "off",
146-
"no-mixed-spaces-and-tabs": "error",
147-
"no-multi-assign": "off",
148-
"no-multi-spaces": "off",
149-
"no-multi-str": "off",
150-
"no-multiple-empty-lines": "off",
151-
"no-native-reassign": "off",
152-
"no-negated-condition": "off",
153-
"no-negated-in-lhs": "off",
154-
"no-nested-ternary": "off",
155-
"no-new": "off",
156-
"no-new-func": "off",
157-
"no-new-object": "off",
158-
"no-new-require": "off",
159-
"no-new-symbol": "error",
160-
"no-new-wrappers": "off",
161-
"no-obj-calls": "error",
162-
"no-octal": "error",
163-
"no-octal-escape": "off",
164-
"no-param-reassign": "off",
165-
"no-path-concat": "off",
166-
"no-plusplus": "off",
167-
"no-process-env": "off",
168-
"no-process-exit": "off",
169-
"no-proto": "off",
170-
"no-prototype-builtins": "off",
171-
"no-redeclare": "error",
172-
"no-regex-spaces": "error",
173-
"no-restricted-globals": "off",
174-
"no-restricted-imports": "off",
175-
"no-restricted-modules": "off",
176-
"no-restricted-properties": "off",
177-
"no-restricted-syntax": "off",
178-
"no-return-assign": "off",
179-
"no-return-await": "off",
180-
"no-script-url": "off",
181-
"no-self-assign": "error",
182-
"no-self-compare": "off",
183-
"no-sequences": "off",
184-
"no-shadow": "off",
185-
"no-shadow-restricted-names": "off",
186-
"no-spaced-func": "off",
187-
"no-sparse-arrays": "error",
188-
"no-sync": "off",
189-
"no-tabs": "off",
190-
"no-template-curly-in-string": "off",
191-
"no-ternary": "off",
192-
"no-this-before-super": "error",
193-
"no-throw-literal": "off",
194-
"no-trailing-spaces": "off",
195-
"no-undef": "error",
196-
"no-undef-init": "off",
197-
"no-undefined": "off",
198-
"no-underscore-dangle": "off",
199-
"no-unexpected-multiline": "error",
200-
"no-unmodified-loop-condition": "off",
201-
"no-unneeded-ternary": "off",
202-
"no-unreachable": "error",
203-
"no-unsafe-finally": "error",
204-
"no-unsafe-negation": "error",
205-
"no-unused-expressions": "off",
206-
"no-unused-labels": "error",
207-
"no-unused-vars": "error",
208-
"no-use-before-define": "off",
209-
"no-useless-call": "off",
210-
"no-useless-catch": "off",
211-
"no-useless-computed-key": "off",
212-
"no-useless-concat": "off",
213-
"no-useless-constructor": "off",
214-
"no-useless-escape": "error",
215-
"no-useless-rename": "off",
216-
"no-useless-return": "off",
217-
"no-var": "off",
218-
"no-void": "off",
219-
"no-warning-comments": "off",
220-
"no-whitespace-before-property": "off",
221-
"no-with": "off",
222-
"nonblock-statement-body-position": "off",
223-
"object-curly-newline": "off",
224-
"object-curly-spacing": "off",
225-
"object-property-newline": "off",
226-
"object-shorthand": "off",
227-
"one-var": "off",
228-
"one-var-declaration-per-line": "off",
229-
"operator-assignment": "off",
230-
"operator-linebreak": "off",
231-
"padded-blocks": "off",
232-
"padding-line-between-statements": "off",
233-
"prefer-arrow-callback": "off",
234-
"prefer-const": "off",
235-
"prefer-destructuring": "off",
236-
"prefer-numeric-literals": "off",
237-
"prefer-object-spread": "off",
238-
"prefer-promise-reject-errors": "off",
239-
"prefer-reflect": "off",
240-
"prefer-rest-params": "off",
241-
"prefer-spread": "off",
242-
"prefer-template": "off",
243-
"quote-props": "off",
244-
quotes: "off",
245-
radix: "off",
246-
"require-atomic-updates": "off",
247-
"require-await": "off",
248-
"require-jsdoc": "off",
249-
"require-unicode-regexp": "off",
250-
"require-yield": "error",
251-
"rest-spread-spacing": "off",
252-
semi: "off",
253-
"semi-spacing": "off",
254-
"semi-style": "off",
255-
"sort-imports": "off",
256-
"sort-keys": "off",
257-
"sort-vars": "off",
258-
"space-before-blocks": "off",
259-
"space-before-function-paren": "off",
260-
"space-in-parens": "off",
261-
"space-infix-ops": "off",
262-
"space-unary-ops": "off",
263-
"spaced-comment": "off",
264-
strict: "off",
265-
"switch-colon-spacing": "off",
266-
"symbol-description": "off",
267-
"template-curly-spacing": "off",
268-
"template-tag-spacing": "off",
269-
"unicode-bom": "off",
270-
"use-isnan": "error",
271-
"valid-jsdoc": "off",
272-
"valid-typeof": "error",
273-
"vars-on-top": "off",
274-
"wrap-iife": "off",
275-
"wrap-regex": "off",
276-
"yield-star-spacing": "off",
277-
yoda: "off"
278-
}
12+
rules: Object.assign({}, ...Object.keys(builtInRules).map(ruleId => ({
13+
[ruleId]: builtInRules[ruleId].meta.docs.recommended ? "error" : "off"
14+
})))
27915
};

0 commit comments

Comments
 (0)