如何在ES6导出语句中删除eslint解析错误

时间:2017-07-13 15:48:14

标签: javascript reactjs eslint lint

npm v3.10.10 node v6.11.0 eslint v4.2.0

您可以提取 the repo here 。只需npm install然后npm run lint

我正在尝试使用以下导出语句(评论有效,但很难看):

容器/ index.js

export MainContainer from './Main/MainContainer'
// export { default as MainContainer } from './Main/MainContainer'

配置/ routes.js

import React from 'react'
import { Route, HashRouter, browserHistory } from 'react-router-dom'
import { MainContainer } from '../containers'

const routes = (
  <HashRouter history={browserHistory}>
    <Route path="/" component={MainContainer} />
  </HashRouter>
)

export default routes

我安装了以下软件包:

npm install babel-eslint@next --save-dev

.eslintrc

{
  parser: "babel-eslint",
  en: {
    es6: true,
    browser: true
  },
  extends: ["eslint:recommended", "plugin:react/recommended", "standard"],
  plugins: [
    "react"
  ]
}

.eslintrc.json

{
    "env": {
        "browser": true,
        "es6": true
    },
    "extends": "eslint:recommended",
    "parserOptions": {
        "ecmaFeatures": {
            "experimentalObjectRestSpread": true,
            "jsx": true
        },
        "sourceType": "module"
    },
    "plugins": [
        "react"
    ],
    "rules": {
        "indent": [
            "error",
            2
        ],
        "linebreak-style": [
            "error",
            "unix"
        ],
        "quotes": [
            "error",
            "single"
        ],
        "semi": [
            "off",
            "always"
        ]
    }
}

然而,即使已安装,我仍然会在npm run lint

时收到有关MainContainer的错误

enter image description here

的package.json

"scripts": {
  "start": "webpack-dev-server",
  "production": "webpack -p",
  "lint": "eslint app/.; exit 0",
  "fix": "eslint --fix app/.; exit 0"
},

"devDependencies": {
  "babel-core": "^6.25.0",
  "babel-eslint": "^8.0.0-alpha.13",
  "babel-loader": "^7.1.1",
  "babel-plugin-transform-export-extensions": "^6.22.0",
  "babel-preset-es2015": "^6.24.1",
  "babel-preset-react": "^6.24.1",
  "babel-preset-stage-0": "^6.24.1",
  "css-loader": "^0.28.4",
  "eslint": "^4.2.0",
  "eslint-config-standard": "^10.2.1",
  "eslint-plugin-promise": "^3.5.0",
  "eslint-plugin-react": "^7.1.0",
  "eslint-plugin-standard": "^3.0.1",
  "html-webpack-plugin": "^2.29.0",
  "style-loader": "^0.18.2",
  "webpack": "^3.2.0",
  "webpack-dev-server": "^2.5.1"
}

文件夹结构

enter image description here

1 个答案:

答案 0 :(得分:3)

想出来!我需要编辑我的.eslintrc.json文件,而不是.eslintrc

https://github.com/babel/babel-eslint/issues/6

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