Closed feross closed 4 years ago
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 no-unused-vars
rule introduced in this PR: https://github.com/eslint/eslint/pull/12055 cc @mdjermanovic
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:
6:14 error 'arg' is defined but never used no-unused-vars
for (const arg of args) {
if (arg !== undefined) {
return arg
}
}
111:16 error 'type' is defined but never used no-unused-vars
for (const type of ['a', 'b']) {
const x = Array.isArray(options[type]) ? options[type] : []
babel-eslint
is using "eslint-scope": "3.7.1"
This may have been caused by the change to the
no-unused-vars
rule introduced in this PR: #12055 cc @mdjermanovic
Most likely it is that commit, with babel-eslint
in the keyword example there is a TDZ
scope between function
and for
, probably because it's using the old version of eslint-scope
@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.
thanks for the feedback!
technically this is not an issue in eslint; but to avoid blocking users, personally(not for the team) I'd suggest to revert that change and release a patch.
we can reintroduce it when it was fixed in babel-eslint. :)
I just hit the same issue with a bunch of false positives after upgrading to 6.2.0
. I'm also using babel-eslint
.
Each of the false positives for the no-unused-vars
that I'm seeing are related to variable declared in a for...of loop, like:
for (let theVariable of theCollection)
This triggers an error for theVariable
.
+1
technically this is not an issue in eslint; but to avoid blocking users, personally(not for the team) I'd suggest to revert that change and release a patch.
I'm not sure reverting the change is the best option.
Due to our semver policy, we advise that ~
is used instead of ^
, since minor versions can include bug fixes that can increase the number of errors.
Locking the ESLint version or using ~6.1.0
should make sure people can continue using babel-eslint until babel-eslint fixes the issue.
@feross Thanks for confirming!
I see there's already an issue open for babel-eslint, and it looks like we have a lead on what might be causing it. I think we should leave this issue open until it's fixed in babel-eslint so that people who encounter this error find the temporary workaround, but can discussion on how to fix it move to that issue?
@kaicataldo I'd leave it open for discussion. As of writing, it's the first result on Google for this error.
@vincerubinetti I think you and I just said the same thing π
babel-eslint is using an outdated version of eslint-scope and doesn't really support ESLint 6 as the ESlint requires eslint-scope@^5.0.0 but babel-eslint requires a pinned version of 3.7.1.
I have managed to fix the issue by updating the dependencies and including proposed changes to match Espree 6 AST. This fork is based on a not yet released major version of babel-eslint and may come with breaking changes.
Anyway, the fork (which can be installed by just replacing the regular version inside package.json with "babel-eslint": "github:przemyslawzalewski/babel-eslint#b6965ab8dedd5a9374475e692912a0df2f239262"
) works for me and yields no false positives so I will wait for the babel-eslint to be released with the fixes.
I have proposed another PR as a PATCH change for the babel-eslint repository that should be easier to integrate and I hope it will be merged soon. In the meanwhile, I have released a forked package for the ^10 version with the fixes included:
https://www.npmjs.com/package/@przemyslawzalewski/babel-eslint/v/10.0.3
Usage is simple as changing some entires in a package.json:
"babel-eslint": "^10.0.2"
-> "@przemyslawzalewski/babel-eslint": "^10.0.3"
and
"parser": "babel-eslint"
-> "parser": "@przemyslawzalewski/babel-eslint"
within the eslint config file.
There is also a fork of the not yet released ^11 branch, however, it may include some breaking changes: https://www.npmjs.com/package/@przemyslawzalewski/babel-eslint/v/11.0.0
If you use yarnοΌyou can solve this problem by adding the following code to package.json.
"resolutions": {
"babel-eslint/eslint-scope": "^5.0.0"
}
@Sun79 that's not something npm supports.
@Sun79 Only yarn works.
@ljharb @yoyo837 Sorry, I made a mistake.π
I just experienced this issue, here's another example:
for (const [fileType, fileExt] of Object.entries(extensions)) {
try {
componentFiles[fileType] = dir + "/" + name + fileExt;
} catch (e) {}
}
https://github.com/babel/babel-eslint/pull/794 fixed this.
I'm going to close this as it seems the issue is resolved. Please let me know if this should be reopened. Thanks!
@platinumazure What are the exact versions of eslint+babel-eslint we should be using to get this fix?
@devinrhode2 upgrade babel-eslint
to v10.0.3
.
I got eslint 5.15 and it works for me.
@yoyo837 that worked! I'm using eslint 6.2.2. and babel-eslint 10.0.3 and it all works! :) thank you
Looks like it is still failing for this snippet of code here...
if (this.props.data && this.props.tileData) {
for (const key in this.props.tileData) {
tiles.push(
Object.assign({}, this.props.tileData[key], {
id: parseInt(key.replace(/\D/g, ''), 10),
size: (this.props.tileData[key].size || '').toLowerCase()
})
);
}
}
and
if (task.errors) {
for (const name in task.errors) {
if (errors[name]) {
errors[name] = [...errors[name], ...task.errors[name]];
} else {
errors[name] = task.errors[name];
}
}
}
@devinrhode2 Please open a new issue with the issue template filled out and we can try to help. Thanks!
Any updates here?
For me it has been fixed :woman_shrugging: we're on the latest version with no problems
I am going to come get rosa mae PERIOD!!
On Tue, Sep 10, 2019, 7:43 AM Aurora Skye notifications@github.com wrote:
For me it has been fixed π€·ββ we're on the latest version with no problems
β You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/eslint/eslint/issues/12117?email_source=notifications&email_token=AMATDUYBDQXA36INAMOBXPDQI6I7FA5CNFSM4IMUNCO2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOD6K6G6A#issuecomment-529916792, or mute the thread https://github.com/notifications/unsubscribe-auth/AMATDU3DVQ3UH3GDD6M3FRDQI6I7FANCNFSM4IMUNCOQ .
Hmm, I'm on 6.3.0
and it's still occurring for me, unfortunately. Should I create another ticket?
@marcinlesek Can you try blowing away your node_modules and reinstalling? And if the issue recurs, please then run npm ls eslint-scope
and see if you can find if there's an old eslint-scope somewhere-- if so, see if the dependency which contains the old version of eslint-scope can be upgraded.
At this point, the root cause is likely npm's package deduplication logic, not anything on the ESLint side. (But please let us know if you think differently after investigating.)
@marcinlesek It's also working for me since upgrading babel-eslint
to latest. What version of babel-eslint
are you running?
@platinumazure @jharris4 both answers are correct guys, thanks! I upgraded eslint-scope
from 3.7.1
to 5.0.0
and babel aslant from 10.0.1
to 10.0.3
and it now works correctly.
Kudos!
I am on 10.0.3, and have eslint-scope on 5.0.0, but still getting the false positives. This is my package.json file
{
"name": "employer_web_client",
"version": "1.0.0",
"description": "Employer Web Client",
"main": "index.js",
"engines": {
"node": "~10.16.1",
"npm": "6.9.0"
},
"scripts": {
"start": "node bin/server",
"qa": "node bin/server --env=qalocal",
"test:dev": "npm test -- --watch",
"test": "NODE_ENV=test NODE_OPTIONS=--max_old_space_size=4096 karma start bin/karma.js --capture-timeout 6000",
"jv-allina": "npm start -- --jv allina",
"jv-allina-commercial": "npm start -- --jv allina-commercial",
"jv-innovation": "npm start -- --jv innovation",
"jv-innovation-commercial": "npm start -- --jv innovation-commercial",
"jv-banner-commercial": "npm start -- --jv banner-commercial",
"jv-sutter-commercial": "npm start -- --jv sutter-commercial",
"jv-texas-commercial": "npm start -- --jv texas-commercial",
"set-aetnadigital-registry": "npm config set @aetnadigital:registry https://nexus.aetnadigital.net/repository/npm/",
"compile": "npm run clean && node bin/compile",
"prod": "npm run nuke && NODE_ENV=production node bin/compile && NODE_ENV=production npm start",
"prod-allina": "npm run nuke && NODE_ENV=production node bin/compile --jv=allina && NODE_ENV=production npm run jv-allina",
"prod-allina-commercial": "npm run nuke && NODE_ENV=production node bin/compile --jv=allina-commercial && NODE_ENV=production npm run jv-allina-commercial",
"prod-innovation": "npm run nuke && NODE_ENV=production node bin/compile --jv=innovation && NODE_ENV=production npm run jv-innovation",
"prod-innovation-commercial": "npm run nuke && NODE_ENV=production node bin/compile --jv=innovation-commercial && NODE_ENV=production npm run jv-innovation-commercial",
"prod-banner-commercial": "npm run nuke && NODE_ENV=production node bin/compile --jv=banner-commercial && NODE_ENV=production npm run jv-banner-commercial",
"prod-sutter-commercial": "npm run nuke && NODE_ENV=production node bin/compile --jv=sutter-commercial && NODE_ENV=production npm run jv-sutter-commercial",
"prod-texas-commercial": "npm run nuke && NODE_ENV=production node bin/compile --jv=texas-commercial && NODE_ENV=production npm run jv-texas-commercial",
"clean": "rm -rf dist tests/coverage",
"nuke": "rm -rf node_modules && npm run set-aetnadigital-registry && npm install && npm run clean",
"onlys": "if grep -rn 'src/' -e 'describe.only' -e 'it.only' -e 'context.only'; then echo 'You left a .only in a unit test'; exit 1; fi",
"lint": "npm run onlys && eslint . --ext .js --ext .jsx",
"analyze": "npm ls webpack-bundle-analyzer --prefix ./docs || npm install -D webpack-bundle-analyzer --prefix ./docs && NODE_ENV=production npm run compile -- --analyze",
"copyrighter": "bash copyrighter.sh"
},
"repository": {
"type": "git",
"url": "git+https://github.com/aetnahealth/employer_web_client.git"
},
"author": "Healthagen",
"license": "UNLICENSED",
"private": "true",
"dependencies": {
"@aetnadigital/anatomy": "^2.1.0",
"@babel/runtime-corejs2": "^7.0.0",
"animejs": "^3.0.1",
"appboy-web-sdk": "^2.0.7",
"copy-webpack-plugin": "^5.0.0",
"css-vars-ponyfill": "^2.0.2",
"custom-event-polyfill": "^0.3.0",
"date-fns": "^1.29.0",
"debug": "^4.1.0",
"deepmerge": "^3.0.0",
"dotenv": "^4.0.0",
"downshift": "^3.1.5",
"focus-visible": "^4.1.5",
"history": "^4.7.2",
"humps": "~1.1.0",
"imask": "^3.4.0",
"json2mq": "^0.2.0",
"jsonwebtoken": "^8.3.0",
"koa": "^2.5.3",
"koa-body": "^4.1.1",
"koa-connect-history-api-fallback": "~0.3.1",
"koa-convert": "~1.2.0",
"koa-json": "~1.1.3",
"koa-router": "~5.4.0",
"koa-static": "~2.0.0",
"lodash": "^4.17.15",
"normalizr": "^3.2.4",
"pluralize": "^7.0.0",
"oaf-react-router": "^2.0.1",
"prop-types": "~15.6.0",
"react": "^16.9.0",
"react-addons-css-transition-group": "^15.6.2",
"react-dom": "^16.9.0",
"react-google-autocomplete": "^1.0.11",
"react-helmet": "^5.2.0",
"react-markdown": "4.0.2",
"react-redux": "~5.0.5",
"react-router": "^4.2.0",
"react-router-dom": "^4.2.2",
"react-router-hash-link": "^1.2.1",
"react-router-redux": "^5.0.0-alpha.9",
"react-scroll": "^1.7.10",
"react-test-renderer": "^16.1.0",
"react-transition-group": "^1.2.1",
"react-waypoint": "^7.3.2",
"redux": "~3.6.0",
"redux-actions": "~2.0.3",
"redux-form": "^7.3.0",
"redux-saga": "^0.16.0",
"redux-saga-middleware": "^1.0.3",
"redux-thunk": "~2.2.0",
"reselect": "^3.0.1",
"smoothscroll-polyfill": "^0.4.4",
"stickyfilljs": "^2.1.0",
"styled-components": "^2.2.1",
"url-search-params-polyfill": "^2.0.3",
"whatwg-fetch": "^2.0.4",
"yargs": "~5.0.0"
},
"devDependencies": {
"@babel/core": "^7.2.0",
"@babel/plugin-proposal-class-properties": "^7.1.0",
"@babel/plugin-proposal-decorators": "^7.1.2",
"@babel/plugin-proposal-do-expressions": "^7.0.0",
"@babel/plugin-proposal-export-default-from": "^7.0.0",
"@babel/plugin-proposal-export-namespace-from": "^7.0.0",
"@babel/plugin-proposal-function-bind": "^7.0.0",
"@babel/plugin-proposal-function-sent": "^7.0.0",
"@babel/plugin-proposal-json-strings": "^7.0.0",
"@babel/plugin-proposal-logical-assignment-operators": "^7.0.0",
"@babel/plugin-proposal-nullish-coalescing-operator": "^7.0.0",
"@babel/plugin-proposal-numeric-separator": "^7.0.0",
"@babel/plugin-proposal-optional-chaining": "^7.0.0",
"@babel/plugin-proposal-pipeline-operator": "^7.0.0",
"@babel/plugin-proposal-throw-expressions": "^7.0.0",
"@babel/plugin-syntax-dynamic-import": "^7.0.0",
"@babel/plugin-syntax-import-meta": "^7.0.0",
"@babel/plugin-transform-regenerator": "^7.0.0",
"@babel/plugin-transform-runtime": "^7.0.0",
"@babel/plugin-transform-template-literals": "^7.0.0",
"@babel/polyfill": "^7.0.0",
"@babel/preset-env": "^7.1.5",
"@babel/preset-react": "^7.0.0",
"@babel/register": "^7.6.0",
"autoprefixer": "^9.1.3",
"babel-eslint": "v11.0.0-beta.0",
"eslint-config-babel": "^7.0.1",
"babel-loader": "^8.0.0",
"babel-plugin-add-module-exports": "^0.2.1",
"babel-plugin-istanbul": "^5.2.0",
"babel-plugin-lodash": "^3.3.4",
"babel-preset-react-hmre": "^1.1.1",
"chai": "^3.4.1",
"chai-as-promised": "^5.1.0",
"chai-enzyme": "^1.0.0-beta.1",
"compression-webpack-plugin": "^1.1.11",
"css-loader": "^3.2.0",
"cssnano": "^4.1.0",
"enzyme": "^3.7.0",
"enzyme-adapter-react-16": "^1.6.0",
"eslint": "^6.0.1",
"eslint-config-airbnb": "^10.0.1",
"eslint-loader": "^2.2.1",
"eslint-plugin-babel": "^3.2.0",
"eslint-plugin-import": "2.14.0",
"eslint-plugin-jsx-a11y": "^2.2.3",
"eslint-plugin-react": "^6.2.0",
"eslint-scope": "5.0.0",
"extract-text-webpack-plugin": "^3.0.2",
"fetch-mock": "^5.10.0",
"file-loader": "^1.1.11",
"fs-extra": "^0.30.0",
"html-webpack-plugin": "^3.2.0",
"image-webpack-loader": "^4.6.0",
"ip": "^1.1.4",
"js-md5": "^0.4.1",
"karma": "^4.3.0",
"karma-chai": "^0.1.0",
"karma-chai-as-promised": "^0.1.2",
"karma-chai-sinon": "^0.1.5",
"karma-chrome-launcher": "^3.1.0",
"karma-coverage": "^1.1.2",
"karma-mocha": "^1.3.0",
"karma-sourcemap-loader": "^0.3.7",
"karma-spec-reporter": "0.0.26",
"karma-webpack": "^4.0.0-beta.0",
"koa-logger": "^1.3.0",
"loader-utils": "^1.1.0",
"lost": "^7.0.3",
"macaddress": "~0.2.9",
"mini-css-extract-plugin": "^0.3.0",
"mocha": "~5.2.0",
"node-noop": "^1.0.0",
"nodemon": "^1.18.7",
"optimize-css-assets-webpack-plugin": "^5.0.0",
"postcss-custom-media": "^7.0.8",
"postcss-focus-visible": "^3.0.0",
"postcss-focus-within": "^2.0.0",
"postcss-import": "^12.0.0",
"postcss-loader": "^3.0.0",
"postcss-nesting": "^6.0.0",
"postcss-preset-env": "^5.3.0",
"postcss-reporter": "^6.0.0",
"puppeteer": "^1.19.0",
"raw-loader": "^0.5.1",
"react-hot-loader": "^3.0.0-beta.7",
"react-text-truncate": "^0.12.0",
"react-toastify": "^2.1.0",
"redbox-react": "^1.5.0",
"redux-devtools": "^3.4.1",
"redux-devtools-dock-monitor": "^1.1.2",
"redux-devtools-log-monitor": "^1.4.0",
"redux-logger": "^3.0.6",
"redux-mock-store": "^1.0.2",
"sinon": "^1.17.2",
"sinon-chai": "^2.8.0",
"sonarqube-scanner": "^2.5.0",
"style-loader": "^0.21.0",
"stylelint": "^9.10.1",
"stylelint-webpack-plugin": "^0.10.5",
"svg-sprite-loader": "3.9.0",
"svgo": "^1.3.0",
"svgo-loader": "^2.1.0",
"url-loader": "^1.1.2",
"webpack": "^4.20.2",
"webpack-cli": "^3.0.8",
"webpack-dev-middleware": "^3.1.3",
"webpack-hot-middleware": "^2.22.3",
"webpack-merge": "^4.1.1",
"webpack-modernizr-loader": "^4.0.1"
}
}
@pbn04001 you need to remove eslint-scope from your devDependencies.
The fixed version works because it grabs that package from inside the eslint package.
Code is here if youβre interested: https://github.com/babel/babel-eslint/blob/10.x/lib/analyze-scope.js#L6
"eslint": "6.3.0",
"eslint-config-standard": "14.1.0",
"eslint-plugin-import": "2.18.2",
"eslint-plugin-node": "10.0.0",
"eslint-plugin-promise": "4.2.1",
"eslint-plugin-standard": "4.0.1",
Gives me an unused warning on test
const tests=['a']
for (let test of tests) {
console.log(test)
}
.eslintrc
{
"extends": "standard",
"rules": {
"space-before-function-paren": ["error", "never"],
"no-unused-vars": ["warn"]
}
}
@dbroadhurst Please share your ESLint configuration and your actual ESLint version. Help us to help you :smile:
I've added my .eslintrc file. Not sure what you mean by actual ESLint version.
node_modules/.bin/eslint -v
v6.3.0
Slight mix up but I have an easy test case. Might be create-react-app issue
create-react-app test
add the test code and get the warning. eslint is v6.3.0
Idk if it's related, but note that create-react-app
still hasn't been updated with the fixed version of eslint
/babel-eslint
/eslint-scope
/whatever. The patch has been merged but it hasn't been released and pushed to npm yet, it looks like:
https://github.com/facebook/create-react-app/pull/7662 https://github.com/facebook/create-react-app/issues/7566
for (const item of map.values()) {
newArr.push(item);
}
Throwing false positive no-unused-vars
error. I've updated eslint
andbabel-eslint
and rebuilt my node_modules but still hitting it.
Looks like webpack uses eslint-scope@4.0.3
. Could that be causing issues?
βββ¬ eslint@6.4.0
β βββ eslint-scope@5.0.0
βββ¬ next@9.0.3
β βββ¬ webpack@4.38.0
β βββ eslint-scope@4.0.3 deduped
βββ¬ webpack@4.40.2
βββ eslint-scope@4.0.3
"devDependencies": {
"babel-eslint": "^10.0.3",
"eslint": "^6.4.0",
"eslint-config-airbnb": "^18.0.1",
"eslint-config-prettier": "^6.3.0",
"eslint-config-react": "^1.1.7",
"eslint-plugin-prettier": "^3.1.0",
"eslint-plugin-react": "^7.14.3",
"prettier": "^1.18.2"
}
module.exports = {
env: {
es6: true,
browser: true
},
extends: [
"airbnb",
"plugin:react/recommended",
"prettier",
],
parserOptions: {
ecmaVersion: 2018,
ecmaFeatures: {
experimentalObjectRestSpread: true,
jsx: true
},
sourceType: 'module',
},
rules: {
"prettier/prettier": "error",
"react/react-in-jsx-scope": "off",
"react/jsx-filename-extension": [1, { "extensions": [".js", ".jsx"] }]
},
plugins: [
"prettier", "react"
],
settings: {
react: {
pragma: "React",
version: "detect"
}
},
parser: "babel-eslint"
};
Looks like webpack uses
eslint-scope@4.0.3
. Could that be causing issues?
I think so. Please see if a new version of webpack is available which uses a more recent eslint-scope
, otherwise you might wish to install eslint-scope directly as a devDependency.
To be clear, this is completely an npm bug, not an ESLint bug. In your dependency structure, ESLint is dependent on latest eslint-scope, but for some reason, npm laid out the physical folder structure in such a way that ESLint gets an old instance of eslint-scope when the linter is run.
Looks like webpack uses
eslint-scope@4.0.3
. Could that be causing issues?I think so. Please see if a new version of webpack is available which uses a more recent
eslint-scope
, otherwise you might wish to install eslint-scope directly as a devDependency.To be clear, this is completely an npm bug, not an ESLint bug. In your dependency structure, ESLint is dependent on latest eslint-scope, but for some reason, npm laid out the physical folder structure in such a way that ESLint gets an old instance of eslint-scope when the linter is run.
same happens with yarn
solved by upgrading babel-eslint
to 10.0.3
It's a bug in eslint, just upgrade eslint to v6.7.1.
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
```js { "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.
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
: https://github.com/babel/babel-eslint/issues/791Are you willing to submit a pull request to fix this bug? Yes