Setting up Airbnb ESLint with React and Webpack

故事扮演 提交于 2019-11-29 12:07:27

问题


I am trying to set up linting with Airbnb's Javascript standards on my React project, it uses webpack.

Updated with latest packages based on comments.

"babel-eslint": "^6.1.2",
"eslint": "^3.2.2",
"eslint-config-airbnb": "^10.0.0",
"eslint-plugin-import": "^1.12.0",
"eslint-plugin-jsx-a11y": "^2.0.1",
"eslint-plugin-react": "^6.0.0",
"jshint": "^2.9.2",
"jshint-loader": "^0.8.3",
"json-loader": "^0.5.4",

I also have a preloader setup in my webpack config

preLoaders: [
    {
        test: /\.jsx?$/,
        loaders: ['eslint'],
        // define an include so we check just the files we need
        include: PATHS.app
    }
],

And the following set up for running the script

  "lint": "eslint . --ext .js --ext .jsx --ignore-path .gitignore --cache",

I also have a .eslintrc file which has the following

{
  "extends": "airbnb",
   "env": {
      "node": true,
      "es6": true
   }
 }

This gives me the following error:

Configuration for rule "react/jsx-sort-props" is invalid:
Value "data["0"].shorthandLast" has additional properties.

If i remove the .eslintrc file which i thought might be conflicting, I get the following error:

 error  Parsing error: The keyword 'const' is reserved

Followed by a npm error which causes the task to exit.

Any help would be appreciated!


回答1:


So, I had the same issue, but I fixed this error using last version of current packages:

"eslint": "3.2.2",
"eslint-config-airbnb": "10.0.0",
"eslint-loader": "1.5.0",
"eslint-plugin-import": "1.12.0",
"eslint-plugin-jsx-a11y": "2.0.1",
"eslint-plugin-mocha": "2.2.0",
"eslint-plugin-react": "6.0.0",

And please, do this tutorial: React Code Style with ESLint + Babel + Webpack

module: { 
    preLoaders: [
      {
        test: /\.jsx?$/,
        loaders: ['eslint-loader'],
        include: path.join(__dirname, 'src'),
        exclude: path.join(__dirname, 'src/app/container')
      }
    ],
...
    eslint: {
      configFile: './.eslintrc',  //your .eslintrc file 
      emitWarning: true
    }

.eslintrc file

    {
      "extends": "airbnb"
    }


来源:https://stackoverflow.com/questions/38757885/setting-up-airbnb-eslint-with-react-and-webpack

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!