2016-03-23 80 views
5

我无法弄清楚如何配置我的.eslintrc文件以正确“接受”JSX。换句话说,当在Atom中输入JSX时,它就吓倒了。使用JSX配置eslint

我加了"parser": "babel-eslint",因为这似乎是听到别人一直在做调整自己的棉短绒一部分......但后来我在Atom中得到这个错误:

错误:无法找到模块“巴别塔“从 '/Users/josetello/.atom/packages/linter-eslint/node_modules'

-eslint我有全球和--save-dev安装巴贝尔,eslint。没有运气。不知道为什么它抱怨原子包...

有没有更好的方式来配置JSX的.eslintrc?

我.eslintrc文件:

{ 
    "settings": { 
    "ecmascript": 6 
}, 
"ecmaFeatures": { 
    "blockBindings": true, 
    "jsx": true 
}, 
"parser": "babel-eslint", 
"env": { 
    "browser": true, 
    "jquery": true, 
    "node": true, 
    "mocha": true, 
    "es6": true 
}, 
"rules": { 
    "prefer-arrow-callback": 1, 
    "semi": 1, 
    "strict": 0, 
    "indent": [2, 2], 
    "quotes": [1, "single"], 
    "no-multi-spaces": [1, { 
    "exceptions": { 
     "VariableDeclarator": true, 
     "FunctionExpression": true 
    } 
    }], 
    "key-spacing": [0, {"align": "value"}], 
    "no-underscore-dangle": 0 
}, 
{ 
    "plugins": [ 
     "react" 
    ] 
    } 
} 
+0

您正在使用哪种eslint版本? – dannyjolie

+0

使用版本2.4.0 – Jose

回答

19

事情已经在ESLint 2问候改为ecmaFeaturesand a lot more...

而不是

{ 
    ecmaFeatures: { 
     jsx: true 
    } 
} 

尝试

{ 
    parserOptions: { 
     ecmaFeatures: { 
      jsx: true 
     } 
    } 
} 

我认为你可以删除parser,但我不会自己使用Atom,所以我不打算说一定的。这不是我自己的.eslintrc的一部分。然后你probalby想添加反应linting规则。 https://github.com/yannickcr/eslint-plugin-react

{ 
    "extends": ["eslint:recommended", "plugin:react/recommended"] 
} 

我想只是这一切垃圾添加到rules,所以我可以快速访问时,我想禁用的东西,但也许这只是我。

{ 
    "rules": { 
    "jsx-quotes"  : 1, 
    "react/display-name": 0, 
    "react/forbid-prop-types": 0, 
    "react/jsx-boolean-value": 1, 
    "react/jsx-closing-bracket-location": 1, 
    "react/jsx-curly-spacing": 1, 
    "react/jsx-handler-names": 1, 
    "react/jsx-indent-props": 1, 
    "react/jsx-indent": 1, 
    "react/jsx-key": 1, 
    "react/jsx-max-props-per-line": 0, 
    "react/jsx-no-bind": 0, 
    "react/jsx-no-duplicate-props": 1, 
    "react/jsx-no-literals": 0, 
    "react/jsx-no-undef": 1, 
    "react/jsx-pascal-case": 1, 
    "react/jsx-sort-prop-types": 0, 
    "react/jsx-sort-props": 0, 
    "react/jsx-uses-react": 1, 
    "react/jsx-uses-vars": 1, 
    "react/no-danger": 1, 
    "react/no-deprecated": 1, 
    "react/no-did-mount-set-state": 1, 
    "react/no-did-update-set-state": 1, 
    "react/no-direct-mutation-state": 1, 
    "react/no-is-mounted": 1, 
    "react/no-multi-comp": 0, 
    "react/no-set-state": 1, 
    "react/no-string-refs": 0, 
    "react/no-unknown-property": 1, 
    "react/prefer-es6-class": 1, 
    "react/prop-types": 1, 
    "react/react-in-jsx-scope": 1, 
    "react/require-extension": 1, 
    "react/self-closing-comp": 1, 
    "react/sort-comp": 1, 
    "react/wrap-multilines": 1 
    } 
} 
+0

我真的怀疑它。上周我刚刚在当前项目中升级了eslint和其他一些软件包,但它并没有什么乐趣,但我显然学到了一些新的技巧:) – dannyjolie

+0

它可能会帮助一些人:您可以检查https:// www.robinwieruch.de/react-eslint-webpack-babel/用于React,Webpack,Babel中的ESLint设置。 –

相关问题