I use this linter with react and standardjs but I have this warning (yarn lint) :
'state' is not defined.
How can I fix it?
On what line of code? It sounds like it's giving you a valid warning, but you haven't shown any code so there's no way to address this.
@loganfsmyth for example in this line https://github.com/kleros/kleros-front/blob/f268e2101f728ffa8e85893bfc428b6593ca012d/src/Disputes/index.js#L11
I am now getting lint errors of no-undef for decorators, defaultProps, and state in my React Components.
````
import Autobind from "autobind-decorator";
...
export default class SomeClass extends React.Component {
static defaultProps = {
// initial properties
};
state = {
// Some state
};
@Autobind
onButtonClick(event){
// Some function
}
}
````
I'm using:
I had gotten this error but now have fixed it here is my full eslint related devDependencies:
{
"devDependencies": {
"babel-eslint": "^8.0.2",
"eslint": "^4.12.0",
"eslint-config-airbnb": "^16.1.0",
"eslint-plugin-flowtype": "2.39.1",
"eslint-plugin-import": "^2.8.0",
"eslint-plugin-jsx-a11y": "^6.0.2",
"eslint-plugin-react": "^7.5.1",
"...": "...other stuff"
},
"eslintConfig": {
"extends": [
"airbnb",
"standard",
"standard-react"
],
"parser": "babel-eslint",
"plugins": [
"babel",
"react",
"promise"
],
"env": {
"browser": true,
"jest": true
},
I'm having the same issue, and its also happening with arrow methods, see my issue that I posted in the eslint issues here:
https://github.com/eslint/eslint/issues/10302#issuecomment-386152627
Has this issue already been solved? I do not see/ understand the solution.
@ehmkah I'm no longer having this issue, but my babel setup has changed significantly since then
@ryanrogalski - ok maybe my configuration is too old. Hopeful this issue does not appear anymore update it. :-)
in my case, it was because i was using the babel-eslint parser without the babel eslint plugin
installing and including https://github.com/babel/eslint-plugin-babel fixed it
Same problem here.
can someone post full setup here
Suddenly having this issue, nothing in my setup has changed. Relevant packages being used in devDependencies
"babel-eslint": "^7.1.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"eslint": "^3.19.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^5.0.3",
"eslint-plugin-react": "^7.0.1",
And here is my .eslintrc.json
{
"env": {
"browser": true,
"es6": true
},
"extends": [
"eslint:recommended",
"plugin:import/errors",
"plugin:import/warnings"
],
"parser": "babel-eslint",
"parserOptions": {
"ecmaFeatures": {
"experimentalObjectRestSpread": true,
"jsx": true
},
"sourceType": "module"
},
"plugins": [
"react"
],
"globals": {
"process": true
},
"rules": {
"indent": [
"error",
2,
{ "SwitchCase": 1 }
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"no-console": 0,
"react/jsx-uses-react": 2,
"react/jsx-uses-vars": 2,
"react/react-in-jsx-scope": 2
}
}
I tried using the babel plugin and installing eslint-plugin-babel as @abdul-stripe suggested, however as soon as I do that, I get another error
Error while running ESLint: eslint.Linter is not a constructor
Which gets thrown specifically in that package. Perhaps a version mismatch? I don't get it though, I never had to do this before. This just started happening all of a sudden. My guess is that someone put a breaking change in a minor package update somewhere...
Update: Have installed [email protected] and the above ESLint error is no longer getting thrown, but the original issue is not resolved.
Can everyone post what editor they are using? Perhaps it's related? I'm using Atom v1.30.0 with [email protected]
Update 2: I've fixed the issue. I went through all my dependencies in my develop branch and compared them to my current feature branch and found that the only difference was react-scripts. I was using 1.0.7 previously and in my branch it had been upgraded to 1.1.5. Forcing my app to go back to [email protected] fixed it for me. If you check the dependencies of this package, the required eslint version has gone from 3.19.0 to > 4. Seems like a breaking change to me, I they should have gone to 2.0.0.
So here are my final devDependencies
"devDependencies": {
"babel-eslint": "^7.1.0",
"babel-plugin-transform-object-rest-spread": "^6.26.0",
"eslint": "^3.19.0",
"eslint-plugin-babel": "^4.1.2",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^5.0.3",
"eslint-plugin-react": "^7.0.1",
"import-sort-cli": "^3.3.0",
"import-sort-parser-babylon": "^3.2.0",
"import-sort-style-absolute": "^1.0.1",
"madge": "^2.2.0",
"node-sass": "^4.9.2",
"react-scripts": "1.0.7"
},
Make sure you check package-lock.json to be really sure that you are using the right version of all this stuff.
@rohan-deshpande, I'm glad that you were able to fix but changing the version of react-scripts seems risky...
@robbporto I didn't change it, it was ^1.0.7 before and running npm install bumped it to 1.1.5 because I had a ^ before the version and the minor upgrade broke all my stuff. Minor upgrades should not cause breaking changes. Reverting it back to 1.0.7 and locking it fixed things because my other dependencies were stable with that version of react-scripts
Should be closed in favour of #487
My solution was to add:
"babel-eslint": "^8.0.2"
To the dependencies list.
Thank you for the issue. Now that @babel/eslint-parser has been released, we are making this repository read-only. If this is a change you would still like to advocate for, please reopen this in the babel/babel monorepo.
Most helpful comment
I am now getting lint errors of no-undef for decorators, defaultProps, and state in my React Components.
````
import Autobind from "autobind-decorator";
...
export default class SomeClass extends React.Component {
};
}
````
I'm using: