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.

False positive in `prefer-rest-params` when checking arguments.length

See original GitHub issue

ESLint version: 2.8.0

What parser are you using?

    "parserOptions": {
        "ecmaVersion": 6,
        "sourceType": "module",
        "ecmaFeatures": {"jsx": true},
    },

When linting this code:

function makeTree(rootPath, branches) {
    console.assert(arguments.length === 2);
    console.assert(_.isArray(rootPath));
    console.assert(_.isArray(branches) && _.isArray(branches[0]));
    return _.map(branches, branch => rootPath.concat(branch));
}

I get this warning:

Use the rest parameters instead of 'arguments'  prefer-rest-params

I believe this to be a false positive. Imho just checking arguments.length should be an exception to this rule (possibly configurable).

Issue Analytics

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

github_iconTop GitHub Comments

3reactions
mysticateacommented, Aug 2, 2016

It seems reasonable to me. Also, this is a relaxing enhancement, so this is a minor fix.

I will champion this.

2reactions
mikesherovcommented, Aug 4, 2016

Right, I agree @mik01aj but the rule is about prefering rest parameters over arguments, so erroring on using arguments other than as a parameter shouldn’t cause an issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

arguments.length - JavaScript - MDN Web Docs
The arguments.length data property contains the number of arguments passed to the function. Value. A non-negative integer.
Read more >
D87540 [clang-tidy] Fix false positive issue in ... - LLVM
I am submitting the patch for review, along with new regression tests to verify that the check is ok if it sees an...
Read more >
Code Issues - Embold Help Center
CFRetainRelease, Check for null arguments to CFRetain/CFRelease/CFMakeCollectable ... If that is the case, the reported instance is a false positive.
Read more >
Mockito. Verify method arguments - java - Stack Overflow
Have you checked the equals method for the mockable class? ... it with the eq() matcher as well as the refEq() matcher but...
Read more >
prefer-rest-params - ESLint - Pluggable JavaScript Linter
There are rest parameters in ES2015. We can use that feature for variadic functions instead of the arguments variable. arguments does not have...
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