no-unused-vars false positive in for-in loops? still an issue?
See original GitHub issueTell us about your environment
Node version: v12.18.3
npm version: v6.14.8
Local ESLint version: v7.7.0 (Currently used)
Global ESLint version: Not found
Done in 10.47s.
What parser (default, @babel/eslint-parser
, @typescript-eslint/parser
, etc.) are you using?
None?
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
I’m a contributor to https://github.com/streamich/git-cz and was trying to get this PR approved: https://github.com/streamich/git-cz/pull/171
As you can see its failing. Then I decided to reproduce the PR by upgrading the ESLint version locally, run ESLint, and see what the output was locally, and its the same as the build server:
/home/travis/build/streamich/git-cz/lib/cli.js
81:16 error 'key' is defined but never used no-unused-vars
/home/travis/build/streamich/git-cz/lib/getConfig.js
16:14 error 'file' is defined but never used no-unused-vars
✖ 2 problems (2 errors, 0 warnings)
So I decided to take a look at the problematic files/lines:
cli.js
// eslint-disable-next-line guard-for-in
for (const key in passThroughParams) {
const value = passThroughParams[key];
if (key.length === 1) {
appendedArgs.push('-' + key);
} else {
appendedArgs.push('--' + key);
}
if (value !== true) {
appendedArgs.push(value);
}
}
getConfig.js
for (const file of configFiles) {
const filename = path.resolve(dir, file);
if (fs.existsSync(filename) && fs.statSync(filename).isFile()) {
return require(filename);
}
}
as you can see 👀 both variables are definitely used right after being declared.
What did you expect to happen?
Not to get those 2 errors. everything should pass.
What actually happened? Please include the actual, raw output from ESLint.
/home/travis/build/streamich/git-cz/lib/cli.js
81:16 error 'key' is defined but never used no-unused-vars
/home/travis/build/streamich/git-cz/lib/getConfig.js
16:14 error 'file' is defined but never used no-unused-vars
✖ 2 problems (2 errors, 0 warnings)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
The command "yarn lint" exited with 1.
Are you willing to submit a pull request to fix this bug? not really because supposedly this was already fixed in #12117 and I have no idea why it’s happening again.
Some extra steps that I think you can run to have a good example of this happening:
git clone https://github.com/streamich/git-cz
cd git-cz
npm i
npm i eslint@latest #to update from eslint 4 to 7
npm run eslint #runs the eslint task/script
#get errors :joy:
Then you can open the files it complains about and play with them to try to fix it.
Related issues: #13163 and #12117 Supposedly this was fixed but somehow it’s happening in this code/project as you can see… and we don’t use babel…
Have a nice day! 🤗
Issue Analytics
- State:
- Created 3 years ago
- Comments:5 (3 by maintainers)
Top GitHub Comments
It seems that the project is using an older version of
babel-eslint
..eslintrc.json
in streamich/git-cz extends mailonline config, which sets"parser": "babel-eslint"
, and has"babel-eslint": "^8.0.2"
as a dependency.Upgrading
babel-eslint
will probably solve the issue.Thank you. Sorry for creating a duplicated issue. I wasn’t aware that this project required another one that required
babel-eslint
. 🤔