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.0 + babel-eslint + no-unused-vars false positive with for-in loop

See original GitHub issue

There’s a new issue in ESLint 6.2.0 just caught by the standard test suite. Issue did not exist in ESLint 6.1.0.

Tell us about your environment

  • ESLint Version: 6.2.0
  • Node Version: 10.16.3
  • npm Version: 6.9.0

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

Please show your full configuration:

Configuration

{
  "parserOptions": {
    "ecmaVersion": 2019,
    "ecmaFeatures": {
      "jsx": true
    },
    "sourceType": "module"
  },
  "parser": "babel-eslint",
  "rules": {
    "no-unused-vars": ["error", { "vars": "all", "args": "none", "ignoreRestSiblings": 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.

function scoreAudioCoverFile (imgFile) {
  const fileName = path.basename(imgFile.name, path.extname(imgFile.name)).toLowerCase()
  const relevanceScore = {
    cover: 80,
    folder: 80,
    album: 80,
    front: 80,
    back: 20,
    spectrogram: -80
  }

  for (const keyword in relevanceScore) {
    if (fileName === keyword) {
      return relevanceScore[keyword]
    }
    if (fileName.indexOf(keyword) !== -1) {
      return relevanceScore[keyword]
    }
  }
  return 0
}
npx eslint --config eslintrc.json t.js

What did you expect to happen?

Just one error:

  1:10  error  'scoreAudioCoverFile' is defined but never used  no-unused-vars

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

Two errors:

   1:10  error  'scoreAudioCoverFile' is defined but never used  no-unused-vars
  12:14  error  'keyword' is defined but never used              no-unused-vars

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 not happen when the default parser is used. However, this issue did not exist with babel-eslint + 6.1.0 and does exist with babel-eslint + 6.2.0.

Issue opened on babel-eslint: https://github.com/babel/babel-eslint/issues/791

Are you willing to submit a pull request to fix this bug? Yes

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:204
  • Comments:55 (16 by maintainers)

github_iconTop GitHub Comments

15reactions
yoyo837commented, Aug 26, 2019
11reactions
vincerubinetticommented, Sep 20, 2019

To whom it affects:

As of yesterday (I think), create-react-app finally released its fix for this babel-eslint bug in react-scripts version 3.1.2.

If you were doing any dirty hacks to temporarily get around this, now’s the time you can finally remove them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

typescript-eslint/no-unused-vars false positive in type ...
Question: What's wrong with this rule and why it triggers in this case. Why eslint recognizes type declaration for functions in types/interfaces ...
Read more >
How to use the eslint.RuleTester.setDefaultConfig function in ...
To help you get started, we've selected a few eslint.RuleTester.setDefaultConfig examples, based on popular ways it is used in public projects.
Read more >
Eslint-plugin-babel - npm.io
eslint -plugin-babel re-implements problematic rules so they do not give false positives or negatives. Requires Node 4 or greater. Install. npm install eslint- ......
Read more >
JamesHenry - npm
babel -eslint. Custom parser for ESLint · eslint-plugin-babel. an eslint rule plugin companion to babel-eslint · lerna. A tool for managing JavaScript projects ......
Read more >
@typescript-eslint/eslint-plugin | Yarn - Package Manager
Important: This documentation covers modern versions of Yarn. For 1.x docs, see classic.yarnpkg.com. Yarn.
Read more >

github_iconTop Related Medium Post

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