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.

Add rule to warn about use of `arguments` in fat arrow functions

See original GitHub issue

Please describe what the rule should do:

warn on usage of arguments inside fat arrow functions

What category of rule is this? (place an “X” next to just one item)

[ ] Enforces code style [x] Warns about a potential error [ ] Suggests an alternate way of doing something [ ] Other (please specify:)

Provide 2-3 code examples that this rule will warn about:

const logArgs = () => console.log(arguments);
function foo(a, b, c) {
  const bar = blah => {
    if(arguments.length > 1) {
      console.log("too many args!");
    }
  };
  bar(123);
}

foo(456, 789);

Why should this rule be included in ESLint (instead of a plugin)?

arguments is not bound for fat arrow functions. The first example is quite easy to catch by a developer, as an error will be thrown. The second example would be hard to track down because arguments is actually referring to foo’s arguments, not bar’s

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:2
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
WickyNilliamscommented, May 22, 2017

or even in ES5:

function getFetchFunction() {
    var args = arguments;
    return () => fetch.apply(null, args);
}

Both of these are much clearer

0reactions
WickyNilliamscommented, May 22, 2017

Now I’ve thought of it more, I think you’re right. May as well use rest params in every case. I didn’t spot the prefer-rest-params rule initially. Closing

Read more comments on GitHub >

github_iconTop Results From Across the Web

Arrow function expressions - JavaScript - MDN Web Docs
An arrow function expression is a compact alternative to a traditional function expression, with some semantic differences and deliberate ...
Read more >
New rule: Add linter for single arg fat arrow functions #309
I think we should implement this rule in the following manner: // Passes lint var foo = bar => { window.alert(bar) } foo('hello')...
Read more >
arrow-parens - ESLint - Pluggable JavaScript Linter
A pluggable and configurable linter tool for identifying and reporting on patterns in JavaScript. Maintain your code quality with ease.
Read more >
Arrow Functions in JavaScript: Fat & Concise Syntax - SitePoint
Learn how to use JavaScript arrow functions, understand fat and concise arrow syntax, and what to be aware of when using them in...
Read more >
Why shouldn't JSX props use arrow functions or bind?
Rerendering many elements might create jank in animations. Using an inline arrow function will cause PureComponent s, and components that use shallowCompare ...
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