[英]Bug ESlint with class React, example : 'state' is not defined. (no-undef)
i'm actually working on a project and when I cloned my project on MacBook, after yarn
in shell for install packages, and atom .
我实际上正在研究一个项目,当我在MacBook上克隆我的项目时,在shell中安装了用于安装包的
yarn
和atom .
for open my ATOM. 打开我的ATOM。 ESLint got a "bug".
ESLint得到了一个“bug”。
For example, for this code : 例如,对于此代码:
/*
* Package Import
*/
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import { Link } from 'react-router-dom';
import classNames from 'classnames';
/*
* Code
*/
class UserDropdown extends Component {
/*
* PropTypes
*/
static propTypes = {
... // Code
}
/*
* State
*/
state = {
... // Code
};
/*
* Actions
*/
onLogOut = () => {
... // Code
};
ESLint tell me : ESLint告诉我:
Error ESLint 'propTypes' is not defined. (no-undef) 22:10
Error ESLint 'state' is not defined. (no-undef) 32:3
Error ESLint 'onLogOut' is not defined. (no-undef) 52:3
I'm still using "babel-plugin-transform-class-properties": "^6.24.1"
, and i declare it in my brunch-config : 我还在使用
"babel-plugin-transform-class-properties": "^6.24.1"
,我在我的brunch-config中声明它:
My brunch-config.coffee 我的brunch-config.coffee
plugins:
babel:
presets: ['latest', 'react']
plugins: [
'transform-class-properties'
'transform-object-rest-spread'
]
My .eslintrc 我的.eslintrc
{
"extends": "airbnb",
"parser": "babel-eslint",
"env": {
"browser": true
},
"rules": {
"brace-style": ["error", "stroustrup"],
"no-param-reassign": ["error", { "props": false }],
"no-mixed-operators": ["error", { "allowSamePrecedence": true }],
"jsx-a11y/no-static-element-interactions": "off",
"react/jsx-filename-extension": "off",
"react/forbid-prop-types": "off",
"react/no-unescaped-entities": "off",
"linebreak-style": "off"
},
"settings": {
"import/resolver": {
"node": {
"paths": ["app/"]
}
}
}
}
And my Packages.json 还有我的Packages.json
"devDependencies": {
"auto-reload-brunch": "^2.7.1",
"autoprefixer": "^6.7.7",
"babel-brunch": "^6.1.1",
"babel-eslint": "^7.2.3",
"babel-plugin-transform-class-properties": "^6.24.1",
"babel-plugin-transform-object-rest-spread": "^6.23.0",
"babel-preset-react": "^6.24.1",
"babel-register": "^6.24.1",
"babel-resolver": "^1.1.0",
"brunch": "^2.10.9",
"chai": "^3.5.0",
"enzyme": "^2.8.2",
"eslint": "^3.19.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-import-resolver-node": "^0.3.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
I'm working on 2 computer, and on Linux, it's OKAY. 我正在使用2台计算机,在Linux上,这是可以的。 So, someone have an idea?
那么,有人有想法吗? If you need more code for understand, i can send it.
如果您需要更多代码来理解,我可以发送它。 Thanks you dude !
谢谢你老兄!
I had the same problem and it was because I had ESLint 4 installed. 我遇到了同样的问题,因为我安装了ESLint 4。 Check your package.json and make sure it's not something like
"eslint": "^3.19.0 || ^4.3.0"
. 检查你的package.json并确保它不像
"eslint": "^3.19.0 || ^4.3.0"
。 I'm using create-react-app, and it's not compatible with ESLint 4 yet: https://github.com/facebookincubator/create-react-app/issues/2604 我正在使用create-react-app,它与ESLint 4不兼容: https : //github.com/facebookincubator/create-react-app/issues/2604
首先,你必须在你的.eslintrc文件中安装babel-eslint作为dev依赖项添加:
"parser": "babel-eslint"
升级eslint
npm i -D eslint@latest
i solved my problem by uninstall node, yarn, and npm. 我通过卸载节点,纱线和npm解决了我的问题。 I used lastest version of node (8.2.1 actually, same for npm and yarn...)
我使用了最新版本的节点(实际上是8.2.1,对于npm和纱线来说都是一样的......)
So after install of Node LTS (6.11.1), and i don't have any problem with ESLint, is nicely working. 所以在安装Node LTS(6.11.1)后,我对ESLint没有任何问题,很好用。
Edit : After re-install Yarn (0.27.5), this problem is back here :thinking: 编辑:重新安装纱线(0.27.5)后,这个问题又回到了这里:思考:
I fixed it using this dependencies: 我使用这个依赖项修复它:
package.json: 的package.json:
"dependencies": {
"react": "16.8.3",
"react-dom": "16.8.3",
"react-scripts": "2.1.8"
}
And i did: 我做了:
yarn
npm install webpack@4.28.3
yarn start
and it worked for me! 它对我有用!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.