prefer-rest-params: ignore uses of ...arguments
See original GitHub issueI 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:
- Created 7 years ago
- Comments:16 (7 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
The linked “Rule Change Proposal Template” at http://eslint.org/docs/developer-guide/contributing/rule-changes is 404
@mathieug please open a new issue or drop by our Gitter chat if you need any help. Thanks!