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.

ESLint 6.2.2 + babel-eslint 10.0.3 + no-unused-vars false positive with for-of loop

See original GitHub issue

Tell us about your environment

  • ESLint Version: 6.2.2
  • Node Version: 12.6.0
  • npm Version: 6.11.2

What parser (default, Babel-ESLint, etc.) are you using? Babel-ESLint 10.0.3

Also tried Babel-ESLint 10.0.2 but ran into https://github.com/eslint/eslint/issues/12117. Following the advice there, I tried running 10.0.3

Please show your full configuration:

Configuration
{
  parser: 'babel-eslint',
  parserOptions: {
    ecmaVersion: 6,
    sourceType: 'module',
    ecmaFeatures: {
      jsx: true,
      generators: true,
      experimentalObjectRestSpread: true
    }
  },
  extends: ["airbnb"],
  rules: {
    'react/sort-comp': 0,
    "react/require-default-props": 0,
    "react/forbid-prop-types": ['error', { forbid: ['any', 'array']}],
    "react/destructuring-assignment": 0,
    "react/static-property-placement": ['error', 'static public field'],
    "react/state-in-constructor": 0,
    "react/jsx-props-no-spreading": 0,

    "linebreak-style": 0,
    "function-paren-newline": ['error', 'consistent'],
    "object-curly-newline": ['error', { 'consistent': true }],

    "babel/semi": 2,
    "no-param-reassign": ['error', { props: false }],
    "arrow-parens": ['error', 'as-needed', { "requireForBlockBody": true }],
  }
}

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

for (const type of TYPES) {
  const itemsOfType = items.filter(item => item.__typename === type);
}
      for (const [name, offset] of items) {
        if (offset >= scrollTop) {
          this.setState({ active: name });
          return;
        }
      }
npm run lint

What did you expect to happen? Get no errors

What actually happened? Please include the actual, raw output from ESLint.

  98:10  error  'type' is defined but never used             no-unused-vars
  126:15  error  'name' is defined but never used          no-unused-vars
  126:21  error  'offset' is defined but never used          no-unused-vars

Are you willing to submit a pull request to fix this bug? Yes, but I can’t commit to it in the next couple of weeks

Issue Analytics

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

github_iconTop GitHub Comments

1reaction
platinumazurecommented, Sep 3, 2019

@camyyssa It looks like your babel-eslint is still using the old eslint-scope for some reason. Try blowing away the node_modules and rerunning npm install, does that resolve your issue?

0reactions
camyyssacommented, Sep 3, 2019

😳 It does!

I could have found the steps to resolve this on my own 😊. Sorry to waste your time @platinumazure 🙂 but thank you so much for the help!

For future me, and in case you stumble on this post because you have the same problem:

  1. Upgrade dependency, remove node-modules, and try again
  2. If you’re using the library as a sub-dependency, try to fix it to the latest version using yarn resolutions https://yarnpkg.com/lang/en/docs/selective-version-resolutions/ (doesn’t seem to exist on npm)

This is a temporary solution, to check if updating the dependency solves the problem. It looks dangerous to me to keep this in your package.json long-term, since it forces the package manager to install a certain version of a sub-dependency

Read more comments on GitHub >

github_iconTop Results From Across the Web

ESLint 6.2.0 + babel-eslint + no-unused-vars false positive ...
The variable keyword from the for-in loop is seen as not used. This may be a bug in babel-eslint since the issue does...
Read more >
no-unused-vars - 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 >
Why am I getting a 'no-unused-vars' warning in a for... ...
Please upgrade the babel-eslint package to version 10.0.3 . This will most likely fix those false-positives where vars are used inside loops ......
Read more >
no-unused-vars - TypeScript ESLint
no -unused-vars. Disallow unused variables. ✓. Extending "plugin:@typescript-eslint/recommended" in an ESLint configuration enables this rule.
Read more >
eslint-plugin-no-unused-vars-rest - npm package
Learn more about eslint-plugin-no-unused-vars-rest: package health score, popularity, security, maintenance, versions and more.
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