2017-07-25 18 views
1

我实际上是在一个项目上工作,当我在MacBook上克隆我的项目时,在yarn的shell中安装了软件包,atom .用于打开我的ATOM。 ESLint有一个“bug”。具有类React的错误ESlint,例如:'状态'未定义。 (no-undef)

例如,此代码:

/* 
* 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告诉我:

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 

我仍在使用"babel-plugin-transform-class-properties": "^6.24.1", 和我宣布它在我的早午餐配置:

我的早午餐 - 配置咖啡

plugins: 
    babel: 
     presets: ['latest', 'react'] 
     plugins: [ 
     'transform-class-properties' 
     'transform-object-rest-spread' 
     ] 

我.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/"] 
     } 
    } 
    } 
} 

而且我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", 

我正在2台计算机上,并在Linux上,这没关系。 那么,有人有一个想法?如果你需要更多的代码来理解,我可以发送它。谢谢你,伙计!

回答

1

首先,你必须安装通天-eslint作为一个开发依赖然后在.eslintrc文件中加入:

"parser": "babel-eslint" 
+0

对不起,我忘了我的packages.json,但我有它在devDep –

+0

我编辑我的第一篇 –

+0

所以也许原子使用全局配置运行eslint时,尝试全局安装babel-eslint –

0

我通过卸载点,线,和NPM解决我的问题。 我使用最新版本的节点(实际上8.2.1,npm和纱线相同...)

所以安装节点LTS(6.11.1)后,我没有任何ESLint的问题,是很好地工作。

编辑:重新安装纱(0.27.5)后,这个问题是回到这里:思想:

3

我有同样的问题,那是因为我已经安装ESLint 4。检查你的package.json并确保它不是"eslint": "^3.19.0 || ^4.3.0"。我使用的是创建反应的,应用程序,它不与ESLint 4尚未兼容:https://github.com/facebookincubator/create-react-app/issues/2604

+0

Hello Fredrik!我在3.19上,但问题仍然存在。 links @ github。我可以看到,我的问题不仅仅针对我。 因此,我正在等待一个新版本。也许我需要在我的计算机上完全卸载eslint以进行清理,并安装适当版本的eslint 3.19。 谢谢! –

相关问题