我不知道如何配置我的 .eslintrc 文件以正确“接受”JSX。换句话说,当在 Atom 中输入 JSX 时,它会崩溃。
我添加了 "parser": "babel-eslint"
,因为这似乎是其他人调整其 linter 所做的工作的一部分......但后来我得到了这个错误原子:
错误:无法从“/Users/josetello/.atom/packages/linter-eslint/node_modules”中找到模块“babel-eslint”
我已经全局安装了 babel-eslint 和 --save-dev
。没有运气。不知道为什么它提示原子包...
是否有更好的方法为 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"
]
}
}
最佳答案
ESLint 2 中关于 ecmaFeatures
的情况发生了变化 ( and a lot more... )
而不是
{
ecmaFeatures: {
jsx: true
}
}
尝试
{
parserOptions: {
ecmaFeatures: {
jsx: true
}
}
}
我认为你可以删除parser
,但我自己不使用Atom,所以我不会肯定地说。它不是我自己的 .eslintrc 的一部分。然后你可能想要添加 React linting 规则。 https://github.com/yannickcr/eslint-plugin-react
{
"extends": ["eslint:recommended", "plugin:react/recommended"]
}
我喜欢将所有这些垃圾添加到规则
中,这样当我想要禁用某些东西时我可以快速访问,但也许只有我这样。
{
"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
}
}
关于reactjs - 使用 JSX 配置 eslint,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36188569/