New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ESLint 6.2.0 + babel-eslint + no-unused-vars false positive with for-in loop #12117
Comments
I just noticed this as well, maybe a second example might help in finding the problem. test.js export const foo = bar => {
const baz = {};
for (const key of bar) {
baz[key] = [];
}
return baz;
}; eslint --parser babel-eslint --rule '{"no-unused-vars": ["error"]}' --no-eslintrc test.js |
This may have been caused by the change to the |
Well, at least the rule doesn't result in a false positive for my example when I just add the additional condition again in a otherwise unchanged v6.2.0. |
We are getting man false positives with 6.2.0 as well:
for (const arg of args) {
if (arg !== undefined) {
return arg
}
}
for (const type of ['a', 'b']) {
const x = Array.isArray(options[type]) ? options[type] : [] |
|
Most likely it is that commit, with |
@feross Any chance you can test the same code out with the default parser to determine if this issue should be fixed in babel-eslint or here? @mdjermanovic's assessment is most likely what's going on here. |
The same question! I use 6.1.0 instead and it works. |
@kaicataldo The issue doesn't exist with the default parser. |
As recommended at eslint/eslint#12117
because it depends on babel-eslint 10.0.3, which gets us the fix for eslint/eslint#12117. upgrading only babel-eslint was causing CI to fail because react-scripts noticed the mismatch
It's a bug in eslint, just upgrade eslint to v6.7.1. |
I upgraded to eslint v6.7.2 and still seeing this. |
@allan2coder This is not accurate, or at least not fully accurate. babel-eslint did have to write a fix on their side as well. Please ensure you have latest babel-eslint.
@MarkPare See above: You do need to upgrade babel-eslint to latest as well. If you upgrade babel-eslint and still run into this issue, please open a new issue and fill out our issue template so we can take a look at your configuration and help you more effectively. Thanks! |
...i.e. I also had to remove the .eslintcache directory. |
If anyone is still running into this issue with React Native due to @react-native-community/eslint-config having a hard reference to version 10.0.1 of babel-eslint and you're using yarn, add this to your "resolutions": {
"@react-native-community/eslint-config/babel-eslint": "^10.0.3"
} |
In liferay-portal right now, we've resolved our babel-eslint dependency to v10.0.2: https://github.com/liferay/liferay-portal/blob/52b997396c42fa102a7d850d5f3521d63377423c/modules/yarn.lock#L3637 But that has a bug in it causing false positives of the no-unused-vars rule in relation with `for` loops, as explained here: eslint/eslint#12117 By tightening the requirement here, we can force liferay-portal to use the fixed version (we're already on the latest, fixed version of ESLint itself, so no need to worry about that). Test plan: Remove this suppression from the flags-taglib project: https://github.com/liferay/liferay-portal/blob/52b997396c42fa102a7d850d5f3521d63377423c/modules/apps/flags/flags-taglib/src/main/resources/META-INF/resources/flags/soy/Flags.es.js#L113 See the spurious lint warning: ``` flags-taglib ❯ portool yarn checkFormat info: using /Users/greghurrell/code/portal/liferay-portal/build/node/bin/node yarn run v1.17.3 $ liferay-npm-scripts check Prettier checked 12 files /Users/greghurrell/code/portal/liferay-portal/modules/apps/flags/flags-taglib/src/main/resources/META-INF/resources/flags/soy/Flags.es.js 113:14 error 'name' is defined but never used. no-unused-vars ✖ 1 problem (1 error, 0 warnings) ``` Force usage of babel-eslint 10.0.3 (with `yarn add`, confirming with `yarn why` that it really is the only version in use in liferay-portal) and then retest: ``` flags-taglib! ❯ portool yarn checkFormat info: using /Users/greghurrell/code/portal/liferay-portal/build/node/bin/node yarn run v1.17.3 $ liferay-npm-scripts check Prettier checked 12 files ✨ Done in 2.02s. ```
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
What parser (default, Babel-ESLint, etc.) are you using? babel-eslint
Please show your full configuration:
Configuration
What did you do? Please include the actual source code causing the issue, as well as the command that you used to run ESLint.
What did you expect to happen?
Just one error:
What actually happened? Please include the actual, raw output from ESLint.
Two errors:
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 withbabel-eslint
+ 6.1.0 and does exist withbabel-eslint
+ 6.2.0.Issue opened on
babel-eslint
: babel/babel-eslint#791Are you willing to submit a pull request to fix this bug?
Yes
The text was updated successfully, but these errors were encountered: