最近在react项目中使用了React.lazy,然后就在git pre-commit中报错了。
$ eslint --fix .
Warning: React version not specified in eslint-plugin-react settings. See https://github.com/yannickcr/eslint-plugin-react#configuration .
error Parsing error: Unexpected token import
安装 yarn add babel-eslint@last -D
在eslintrc中配置 “parser”: “babel-eslint”
贴出我的.eslintrc.json
{
"env": {
"browser": true,
"commonjs": true,
"mocha": true,
"es6": true,
"jest": true,
"jquery": true,
"node": true
},
"extends": [
"ebay",
"plugin:react/recommended"
],
"parserOptions": {
"sourceType": "module",
"ecmaVersion": 2018,
"allowImportExportEverywhere": true
},
"parser": "babel-eslint",
"plugins": [
"react"
],
"rules": {
"indent": [
"error",
4,
{"SwitchCase": 1}
],
"linebreak-style": [
"error",
"unix"
],
"quotes": [
"error",
"single"
],
"semi": [
"error",
"always"
],
"max-len": "off",
"no-console": "off",
"no-unused-vars": ["error", {"args": "none" }],
"no-extend-native": [2, {"exceptions": ["String"]}],
"react/prop-types": "off"
}
}