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.

no-unused-vars with ignoreRestSiblings:true reports false-positives

See original GitHub issue

Tell us about your environment

  • ESLint Version: 7.21.0
  • Node Version: 12.16.2
  • npm Version: 6.14.4
  • Operating System: Windows

What parser (default, @babel/eslint-parser, @typescript-eslint/parser, etc.) are you using? babel-eslint

Please show your full configuration:

Configuration
module.exports = {
    extends: 'airbnb',
    parser: 'babel-eslint',
    plugins: [
        'jasmine',
        'webdriverio',
        'react-redux',
    ],
    env: {
        'browser': true,
        'node': true,
        'jasmine': true,
        'webdriverio/wdio': true,
    },
    rules: {
        'import/no-cycle': 'off',
        'react/jsx-props-no-spreading': 'off',
        'react/no-access-state-in-setstate': 'off',
        'arrow-parens': ['error', "as-needed", { "requireForBlockBody": true }],
        'function-paren-newline': 'off',
        'indent': ['error', 4, { 'SwitchCase': 1 }],
        'no-undef': 'error',
        'no-underscore-dangle': 'off',
        'no-multiple-empty-lines': ['warn', { "max": 2 } ],
        'no-else-return': ['error', { allowElseIf: true }],
        'no-restricted-globals': [
            "error",
            { name: 'Set', message: 'Use window.Set or add an eslint-ignore if native Set is what you want' },
            { name: 'Map', message: 'Use window.Map or add an eslint-ignore if native Map is what you want' }
        ],
        'max-len': ['error', 120],
        'implicit-arrow-linebreak': 'off',
        'jsx-a11y/click-events-have-key-events': 'off',
        'jsx-a11y/interactive-supports-focus': 'off',
        'jsx-a11y/label-has-for': 'off',
        'jsx-a11y/label-has-associated-control': 'off',
        'jsx-a11y/no-noninteractive-element-interactions': 'off',
        'jsx-a11y/no-static-element-interactions': 'off',
        'jsx-a11y/anchor-is-valid': 'off',
        'jsx-a11y/control-has-associated-label': 'off',
        'class-methods-use-this': 'off',
        'no-plusplus': ['error', { 'allowForLoopAfterthoughts': true }],
        'no-mixed-operators': ['error', { 'allowSamePrecedence': true }],
        'no-multi-spaces': ['error', { ignoreEOLComments: true }],
        'no-console': 'warn',
        'no-continue': 'off',
        'no-unused-vars': ['error', { 'ignoreRestSiblings': true }],
        'object-curly-newline': 'off',
        'operator-linebreak': ["warn", "after"],
        'prefer-destructuring': 'off',
        'prefer-promise-reject-errors': 'warn',
        'react/sort-comp': ['warn', { order: ['static-methods',  'lifecycle', 'everything-else', 'render'] }],
        'react/forbid-prop-types': 'off',
        'react/jsx-fragments': 'off',
        'react/jsx-filename-extension': 'off',
        'react/jsx-indent': ['error', 4],
        'react/jsx-indent-props': ['error', 4],
        'react/no-danger': 'off',
        'react/require-default-props': 'off',
        'react/jsx-boolean-value': 'off',
        'react/no-did-update-set-state': 'off', // recommended way since 16.3.
        'react/destructuring-assignment': 'off',
        'react/static-property-placement': 'off',
        'react-redux/prefer-separate-component-file': 'off',
        'react-redux/connect-prefer-named-arguments': 'off',
        'react/no-unused-prop-types': 'off', // superseded by react-redux/no-unused-prop-types
        'react/jsx-props-no-multi-spaces': 'off',
        // disallow certain syntax forms
        // http://eslint.org/docs/rules/no-restricted-syntax
        'no-restricted-syntax': [
            'error',
            {
                selector: 'ForInStatement',
                message: 'for..in loops iterate over the entire prototype chain, which is virtually never what you want. Use Object.{keys,values,entries}, and iterate over the resulting array.',
            },
            {
                selector: 'LabeledStatement',
                message: 'Labels are a form of GOTO; using them makes code confusing and hard to maintain and understand.',
            },
            {
                selector: 'WithStatement',
                message: '`with` is disallowed in strict mode because it makes code impossible to predict and optimize.',
            },
        ],
        camelcase: 'off'
    },
    globals: {
        '__BUILD_NR__': true,
        'requestIdleCallback': true,
        'any': true
    },
    settings: {
        'import/core-modules': [
            'native-api',
        ],
        'react': {
            'pragma': 'React',
            'version': '16.3'
        },
    }
};

What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.

function buildLibraryStructure(folders, entries) {
    const structureMap = {
        root: {
            id: 'root',
            title: 'Library',
            type: navItemTypes.folder,
            parent: null,
            children: [],
            weight: 1,
        },
    };

    // reused dummy variables used to spread data out of entries/folders
    /* eslint-disable no-unused-vars */
    let folder;
    let validFrom;
    let validUntil;
    let parent;
    /* eslint-enable no-unused-vars */
    let rest;

    // Add folders to map of items
    folders.forEach((folderItem) => {
        ({ folder, validFrom, validUntil, ...rest } = folderItem);

        structureMap[folderItem.id] = {
            ...rest,
            oid: folderItem.id,
            isFolder: true,
        };
    });
    return structureMap;
}

What did you expect to happen? I believe the rule no-unused-vars should not be triggered.

The rule is configured as 'no-unused-vars': ['error', { 'ignoreRestSiblings': true }],. The above code splits definition and spreading of the two variables folder and rest. The definition of the variables are even enclosed in a disable no-unused-vars

What actually happened? Please copy-paste the actual, raw output from ESLint.

38:16 error ‘folder’ is assigned a value but never used no-unused-vars 38:20 error ‘validFrom’ is assigned a value but never used no-unused-vars 38:31 error ‘validUntil’ is assigned a value but never used no-unused-vars

Steps to reproduce this issue:

  1. split definition and usage of variables
  2. use the rest operator with a throw-away variables on an other line
  3. no-unsed-vars is triggered

Are you willing to submit a pull request to fix this bug? No, I don’t think I could

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
LulaV14commented, Mar 31, 2021

My apologies @nzakas I’ve been very busy lately and haven’t put a PR for this. I see there’s an open PR created by @yeonjuan that should fix the issue.

I’ll try checking other good first-time issues.

0reactions
yeonjuancommented, Apr 1, 2021

Hi @LulaV14. Sorry for doing it without checking your progress. I should have checked but I missed it…😭

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript-eslint/no-unused-vars false positive in type ...
string, saying that value is defined but never used. Even if type assigned correctly and actual onClick handler uses the value! Question: What's ......
Read more >
eslint - UNPKG
... Fix typo and missing article before noun in docs (#13611) (Patrice Sandhu) ... false positive with Symbol as an argument (#13337) (Milos...
Read more >
False Positives: Self-Driving Cars and the Agony of ... - WIRED
In self-driving cars, the problem with avoiding both false positives and negatives is that the more you do to get away from one,...
Read more >
node_modules/eslint/CHANGELOG.md · master - PLMlab
39dfe08 Update: false positives in function-call-argument-newline (fixes ... 2324570 Breaking: no-unused-vars reports all after-used params ...
Read more >
Assessing the case for requiring AEB on city buses and ...
It was known from the development of pedestrian AEB for passenger cars that the ability to apply the ... Figure 2: True positive...
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