question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

prefer-rest-params: ignore uses of ...arguments

See original GitHub issue

I would like to suggest a change to the prefer-rest-params rule.

My use case is thus:

// constructor of this subclass takes arguments a, b, c, d, e, f
constructor(a) {
  super(...arguments);
  doSomethingSpecialWith(a);
}

In cases where a function takes many arguments, and you only want to operate on a subset, prefer-rest-params forces patterns like these:

constructor(a, ...rest) {
  super(a, ...rest);
  doSomethingSpecialWith(a);
}

constructor(...args) {
  const [a] = args;
  super(...args);
  doSomethingSpecialWith(a);
}

The first pattern is not ideal because you have to change code in two places now if you change what variables you’re using. The second pattern is not ideal in my opinion because it’s added what seems to me to be mental overhead.


I would like to suggest that prefer-rest-params should not fire if the only use of arguments in a function is to spread it.

The following patterns would not be errors:

constructor(a) {
  super(...arguments);
  doSomethingSpecialWith(a);
}

The following patterns would still be errors:

constructor(a) {
  super(...arguments);
  doSomethingSpecialWith(arguments[0]);
}

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:16 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
sethkinastcommented, Sep 12, 2016

The linked “Rule Change Proposal Template” at http://eslint.org/docs/developer-guide/contributing/rule-changes is 404

0reactions
vitorbalcommented, Jan 19, 2017

@mathieug please open a new issue or drop by our Gitter chat if you need any help. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

prefer-rest-params - ESLint - Pluggable JavaScript Linter
This rule is aimed to flag usage of arguments variables. Examples. Examples of incorrect code for this rule: /*eslint prefer-rest-params: "error"*/ ...
Read more >
How to use rest params with already defined params, eslint ...
The rule says you should not use arguments but you want to use arguments. You can ignore a rule for one line, but...
Read more >
Suggest using the rest parameters instead of arguments ...
Rule Details. This rule is aimed to flag usage of arguments variables. ... /*eslint prefer-rest-params: "error"*/ function foo() { console.log(arguments); } ...
Read more >
Top 5 reselect Code Examples - Snyk
Learn more about how to use reselect, based on reselect code examples created ... //eslint-disable-line prefer-rest-params // apply arguments instead of ...
Read more >
prefer-rest-params - Rules - ESLint中文文档
Suggest using the rest parameters instead of arguments (prefer-rest-params) · Rule Details · Examples · When Not To Use It · Related Rules...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found