Skip to content

Commit 81629d2

Browse files
Chore: enable rest/spread rules on ESLint codebase (#10211)
This enables the `prefer-rest-params`, `prefer-spread`, and `rest-spread-spacing` rules on the ESLint codebase.
1 parent 2324570 commit 81629d2

19 files changed

+67
-120
lines changed

Makefile.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -979,10 +979,7 @@ function createConfigForPerformanceTest() {
979979
"rules:"
980980
];
981981

982-
content.push.apply(
983-
content,
984-
ls("lib/rules").map(fileName => ` ${path.basename(fileName, ".js")}: 1`)
985-
);
982+
content.push(...ls("lib/rules").map(fileName => ` ${path.basename(fileName, ".js")}: 1`));
986983

987984
content.join("\n").to(PERF_ESLINTRC);
988985
}

lib/file-finder.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class FileFinder {
134134

135135
// Add what has been cached previously to the cache of each directory searched.
136136
for (let i = 0; i < searched; i++) {
137-
[].push.apply(cache[dirs[i]], cache[directory]);
137+
cache[dirs[i]].push(...cache[directory]);
138138
}
139139

140140
yield* cache[dirs[0]];

lib/linter.js

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ function getDirectiveComments(filename, ast, ruleMapper) {
284284
if (/^eslint-disable-(next-)?line$/.test(match[1]) && comment.loc.start.line === comment.loc.end.line) {
285285
const directiveType = match[1].slice("eslint-".length);
286286

287-
[].push.apply(disableDirectives, createDisableDirectives(directiveType, comment.loc.start, directiveValue));
287+
disableDirectives.push(...createDisableDirectives(directiveType, comment.loc.start, directiveValue));
288288
} else if (comment.type === "Block") {
289289
switch (match[1]) {
290290
case "exported":
@@ -297,11 +297,11 @@ function getDirectiveComments(filename, ast, ruleMapper) {
297297
break;
298298

299299
case "eslint-disable":
300-
[].push.apply(disableDirectives, createDisableDirectives("disable", comment.loc.start, directiveValue));
300+
disableDirectives.push(...createDisableDirectives("disable", comment.loc.start, directiveValue));
301301
break;
302302

303303
case "eslint-enable":
304-
[].push.apply(disableDirectives, createDisableDirectives("enable", comment.loc.start, directiveValue));
304+
disableDirectives.push(...createDisableDirectives("enable", comment.loc.start, directiveValue));
305305
break;
306306

307307
case "eslint": {
@@ -724,10 +724,8 @@ const BASE_TRAVERSAL_CONTEXT = Object.freeze(
724724
Object.keys(DEPRECATED_SOURCECODE_PASSTHROUGHS).reduce(
725725
(contextInfo, methodName) =>
726726
Object.assign(contextInfo, {
727-
[methodName]() {
728-
const sourceCode = this.getSourceCode();
729-
730-
return sourceCode[DEPRECATED_SOURCECODE_PASSTHROUGHS[methodName]].apply(sourceCode, arguments);
727+
[methodName](...args) {
728+
return this.getSourceCode()[DEPRECATED_SOURCECODE_PASSTHROUGHS[methodName]](...args);
731729
}
732730
}),
733731
{}
@@ -816,7 +814,7 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
816814
{
817815
id: ruleId,
818816
options: getRuleOptions(configuredRules[ruleId]),
819-
report() {
817+
report(...args) {
820818

821819
/*
822820
* Create a report translator lazily.
@@ -831,7 +829,7 @@ function runRules(sourceCode, configuredRules, ruleMapper, parserOptions, parser
831829
if (reportTranslator === null) {
832830
reportTranslator = createReportTranslator({ ruleId, severity, sourceCode, messageIds });
833831
}
834-
const problem = reportTranslator.apply(null, arguments);
832+
const problem = reportTranslator(...args);
835833

836834
if (problem.fix && rule.meta && !rule.meta.fixable) {
837835
throw new Error("Fixable rules should export a `meta.fixable` property.");

lib/logging.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@ module.exports = {
1414
* Cover for console.log
1515
* @returns {void}
1616
*/
17-
info() {
18-
console.log.apply(console, arguments);
17+
info(...args) {
18+
console.log(...args);
1919
},
2020

2121
/**
2222
* Cover for console.error
2323
* @returns {void}
2424
*/
25-
error() {
26-
console.error.apply(console, arguments);
25+
error(...args) {
26+
console.error(...args);
2727
}
2828
};

lib/report-translator.js

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -51,35 +51,35 @@ const interpolate = require("./util/interpolate");
5151

5252
/**
5353
* Translates a multi-argument context.report() call into a single object argument call
54-
* @param {...*} arguments A list of arguments passed to `context.report`
54+
* @param {...*} args A list of arguments passed to `context.report`
5555
* @returns {MessageDescriptor} A normalized object containing report information
5656
*/
57-
function normalizeMultiArgReportCall() {
57+
function normalizeMultiArgReportCall(...args) {
5858

5959
// If there is one argument, it is considered to be a new-style call already.
60-
if (arguments.length === 1) {
60+
if (args.length === 1) {
6161

6262
// Shallow clone the object to avoid surprises if reusing the descriptor
63-
return Object.assign({}, arguments[0]);
63+
return Object.assign({}, args[0]);
6464
}
6565

6666
// If the second argument is a string, the arguments are interpreted as [node, message, data, fix].
67-
if (typeof arguments[1] === "string") {
67+
if (typeof args[1] === "string") {
6868
return {
69-
node: arguments[0],
70-
message: arguments[1],
71-
data: arguments[2],
72-
fix: arguments[3]
69+
node: args[0],
70+
message: args[1],
71+
data: args[2],
72+
fix: args[3]
7373
};
7474
}
7575

7676
// Otherwise, the arguments are interpreted as [node, loc, message, data, fix].
7777
return {
78-
node: arguments[0],
79-
loc: arguments[1],
80-
message: arguments[2],
81-
data: arguments[3],
82-
fix: arguments[4]
78+
node: args[0],
79+
loc: args[1],
80+
message: args[2],
81+
data: args[3],
82+
fix: args[4]
8383
};
8484
}
8585

@@ -240,8 +240,8 @@ module.exports = function createReportTranslator(metadata) {
240240
* called every time a rule reports a problem, which happens much less frequently (usually, the vast
241241
* majority of rules don't report any problems for a given file).
242242
*/
243-
return function() {
244-
const descriptor = normalizeMultiArgReportCall.apply(null, arguments);
243+
return (...args) => {
244+
const descriptor = normalizeMultiArgReportCall(...args);
245245

246246
assertValidNodeInfo(descriptor);
247247

lib/rules/no-irregular-whitespace.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ module.exports = {
225225

226226
// If we have any errors remaining report on them
227227
errors.forEach(error => {
228-
context.report.apply(context, error);
228+
context.report(...error);
229229
});
230230
};
231231
} else {

lib/rules/no-shadow.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ module.exports = {
179179
while (stack.length) {
180180
const scope = stack.pop();
181181

182-
stack.push.apply(stack, scope.childScopes);
182+
stack.push(...scope.childScopes);
183183
checkForShadows(scope);
184184
}
185185
}

lib/rules/no-undefined.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ module.exports = {
6868
while (stack.length) {
6969
const scope = stack.pop();
7070

71-
stack.push.apply(stack, scope.childScopes);
71+
stack.push(...scope.childScopes);
7272
checkScope(scope);
7373
}
7474
}

lib/timing.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ module.exports = (function() {
116116
data[key] = 0;
117117
}
118118

119-
return function() {
119+
return function(...args) {
120120
let t = process.hrtime();
121121

122-
fn.apply(null, Array.prototype.slice.call(arguments));
122+
fn(...args);
123123
t = process.hrtime(t);
124124
data[key] += t[0] * 1e3 + t[1] / 1e6;
125125
};

lib/util/safe-emitter.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@
2727
* another module throws an error or registers a listener.
2828
* 2. It calls listener functions without any `this` value. (`EventEmitter` calls listeners with a
2929
* `this` value of the emitter instance, which would give listeners access to other listeners.)
30-
* 3. Events can be emitted with at most 3 arguments. (For example: when using `emitter.emit('foo', a, b, c)`,
31-
* the arguments `a`, `b`, and `c` will be passed to the listener functions.)
3230
* @returns {SafeEmitter} An emitter
3331
*/
3432
module.exports = () => {
@@ -42,9 +40,9 @@ module.exports = () => {
4240
listeners[eventName] = [listener];
4341
}
4442
},
45-
emit(eventName, a, b, c) {
43+
emit(eventName, ...args) {
4644
if (eventName in listeners) {
47-
listeners[eventName].forEach(listener => listener(a, b, c));
45+
listeners[eventName].forEach(listener => listener(...args));
4846
}
4947
},
5048
eventNames() {

0 commit comments

Comments
 (0)