簡體   English   中英

使用 React 和 Webpack 設置 Airbnb ESLint

[英]Setting up Airbnb ESLint with React and Webpack

我正在嘗試在我的 React 項目上使用 Airbnb 的 Javascript 標准設置 linting,它使用 webpack。

根據評論更新了最新的軟件包。

"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",

我的 webpack 配置中也有一個預加載器設置

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

以下設置用於運行腳本

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

我還有一個.eslintrc文件,其中包含以下內容

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

這給了我以下錯誤:

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

如果我刪除了我認為可能存在沖突的.eslintrc文件, .eslintrc出現以下錯誤:

 error  Parsing error: The keyword 'const' is reserved

接着是一個 npm 錯誤,導致任務退出。

所以,我遇到了同樣的問題,但我使用當前包的最新版本修復了這個錯誤:

"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",

請執行本教程:使用 ESLint + Babel + Webpack 的 React Code Style

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 文件

    {
      "extends": "airbnb"
    }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM