Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule Proposal: `prefer-rest-params` #4108

Closed
mysticatea opened this Issue Oct 10, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@mysticatea
Copy link
Member

mysticatea commented Oct 10, 2015

There is rest parameters in ES2015 features.
We can use that instead of the arguments variable.
The arguments does not have methods of Array.prototype, so it's inconvenience a bit.

So I propose a rule that suggests a use of rest parameters instead of the implicit arguments variable.

This rule considers the following patterns are problem.

function foo() {
    console.log(arguments);
}

function foo(action) {
    var args = [].slice.call(arguments, 1);
    action.apply(null, args);
}

This rule considers the following patterns are not problem.

function foo(...args) {
    console.log(args);
}

function foo(action, ...args) {
    action.apply(null, args); // or `action(...args)`, related with the `prefer-spread` rule.
}

// Note: the implicit arguments can be overwritten.
function foo(arguments) {
    console.log(arguments); // This is the first argument.
}
function foo() {
    var arguments = 0;
    console.log(arguments); // This is a local variable.
}

I guessed this rule merely checks whether or not the variable of arguments has any references.
It's similar to https://github.com/eslint/eslint/pull/4107/files#diff-7b84fea30db343f87eb7fda7ecaac74eR173

@nzakas

This comment has been minimized.

Copy link
Member

nzakas commented Oct 11, 2015

Sounds good!

@mysticatea mysticatea self-assigned this Nov 23, 2015

@mysticatea

This comment has been minimized.

Copy link
Member Author

mysticatea commented Nov 23, 2015

I'm working on this.

mysticatea added a commit to mysticatea/eslint that referenced this issue Nov 23, 2015

@nzakas nzakas closed this in #4524 Dec 1, 2015

@eslint eslint bot locked and limited conversation to collaborators Feb 7, 2018

@eslint eslint bot added the archived due to age label Feb 7, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
You can’t perform that action at this time.