ESLint 6.2.0 + babel-eslint + no-unused-vars false positive with for-in loop
See original GitHub issueThere’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:
- Created 4 years ago
- Reactions:204
- Comments:55 (16 by maintainers)
Top GitHub Comments
https://github.com/babel/babel-eslint/pull/794 fixed this.
To whom it affects:
As of yesterday (I think),
create-react-app
finally released its fix for thisbabel-eslint
bug inreact-scripts
version3.1.2
.If you were doing any dirty hacks to temporarily get around this, now’s the time you can finally remove them.