From 27b5cb4d9d71fa5d7b728f38e6efbc2bbd53b608 Mon Sep 17 00:00:00 2001 From: fisker Cheung Date: Thu, 23 Jan 2020 16:36:18 +0800 Subject: [PATCH] Enable ESLint `prefer-rest-params` rule (#7400) --- .eslintrc.yml | 1 + src/common/fast-path.js | 30 +++++++++++++++--------------- src/language-css/parser-postcss.js | 7 ++----- 3 files changed, 18 insertions(+), 20 deletions(-) diff --git a/.eslintrc.yml b/.eslintrc.yml index 434639399..54a40050f 100644 --- a/.eslintrc.yml +++ b/.eslintrc.yml @@ -44,6 +44,7 @@ rules: object: false - enforceForRenamedProperties: false prefer-object-spread: error + prefer-rest-params: error prefer-spread: error quotes: - error diff --git a/src/common/fast-path.js b/src/common/fast-path.js index eaf9a84f2..33f4900b4 100644 --- a/src/common/fast-path.js +++ b/src/common/fast-path.js @@ -56,13 +56,13 @@ FastPath.prototype.getParentNode = function getParentNode(count) { // reference to this (modified) FastPath object. Note that the stack will // be restored to its original state after the callback is finished, so it // is probably a mistake to retain a reference to the path. -FastPath.prototype.call = function call(callback /*, name1, name2, ... */) { +FastPath.prototype.call = function call(callback, ...names) { const s = this.stack; const origLen = s.length; let value = s[origLen - 1]; - const argc = arguments.length; - for (let i = 1; i < argc; ++i) { - const name = arguments[i]; + const argc = names.length; + for (let i = 0; i < argc; ++i) { + const name = names[i]; value = value[name]; s.push(name, value); } @@ -83,14 +83,14 @@ FastPath.prototype.callParent = function callParent(callback, count) { // accessing this.getValue()[name1][name2]... should be array-like. The // callback will be called with a reference to this path object for each // element of the array. -FastPath.prototype.each = function each(callback /*, name1, name2, ... */) { +FastPath.prototype.each = function each(callback, ...names) { const s = this.stack; const origLen = s.length; let value = s[origLen - 1]; - const argc = arguments.length; + const argc = names.length; - for (let i = 1; i < argc; ++i) { - const name = arguments[i]; + for (let i = 0; i < argc; ++i) { + const name = names[i]; value = value[name]; s.push(name, value); } @@ -111,14 +111,14 @@ FastPath.prototype.each = function each(callback /*, name1, name2, ... */) { // Similar to FastPath.prototype.each, except that the results of the // callback function invocations are stored in an array and returned at // the end of the iteration. -FastPath.prototype.map = function map(callback /*, name1, name2, ... */) { +FastPath.prototype.map = function map(callback, ...names) { const s = this.stack; const origLen = s.length; let value = s[origLen - 1]; - const argc = arguments.length; + const argc = names.length; - for (let i = 1; i < argc; ++i) { - const name = arguments[i]; + for (let i = 0; i < argc; ++i) { + const name = names[i]; value = value[name]; s.push(name, value); } @@ -144,13 +144,13 @@ FastPath.prototype.map = function map(callback /*, name1, name2, ... */) { * | undefined * )} predicates */ -FastPath.prototype.match = function match(/* predicates */) { +FastPath.prototype.match = function match(...predicates) { let stackPointer = this.stack.length - 1; let name = null; let node = this.stack[stackPointer--]; - for (let i = 0; i < arguments.length; ++i) { + for (let i = 0; i < predicates.length; ++i) { if (node === undefined) { return false; } @@ -163,7 +163,7 @@ FastPath.prototype.match = function match(/* predicates */) { node = this.stack[stackPointer--]; } - if (arguments[i] && !arguments[i](node, name, number)) { + if (predicates[i] && !predicates[i](node, name, number)) { return false; } diff --git a/src/language-css/parser-postcss.js b/src/language-css/parser-postcss.js index 50914dbc7..a524aa7f9 100644 --- a/src/language-css/parser-postcss.js +++ b/src/language-css/parser-postcss.js @@ -516,11 +516,8 @@ function requireParser(isSCSSParser) { // TODO: Remove this hack when this issue is fixed: // https://github.com/shellscape/postcss-less/issues/88 const LessParser = require("postcss-less/dist/less-parser"); - LessParser.prototype.atrule = function() { - return Object.getPrototypeOf(LessParser.prototype).atrule.apply( - this, - arguments - ); + LessParser.prototype.atrule = function(...args) { + return Object.getPrototypeOf(LessParser.prototype).atrule.apply(this, args); }; return require("postcss-less");