React Native 系列【三】代码校验 (eslint)

  Vanessa

SymApp Demo

ToC

添加依赖

"devDependencies": {
  "babel-eslint": "^7.2.3",
  "eslint": "^4.0.0",
  "eslint-config-airbnb-base": "^11.2.0",
  "eslint-formatter-pretty": "^1.1.0",
  "eslint-plugin-import": "^2.3.0",
  "eslint-plugin-react": "^7.1.0",
  "eslint-plugin-react-native": "^2.3.2"
},

添加命令

"scripts": {
  "lint": "eslint . --fix --format=node_modules/eslint-formatter-pretty --quiet"
  }

添加规则 .eslintrc

{
  "parser": "babel-eslint",
  "extends": "airbnb-base",
  "env": {
    "jest": true
  },
  "plugins": [
    "react",
  "react-native"
  ],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
  }
  },
  "rules": {
    "react/jsx-uses-vars": 2,
  "react/jsx-uses-react": 2,
  "comma-dangle": [
      "error",
  {
        "arrays": "never",
  "objects": "never"
  }
    ],
  "no-underscore-dangle": [
      "error",
  {
        "allowAfterThis": true
  }
    ]
  },
  "globals": {
    "fetch": true
  }
}

添加不需要检测的文件 .eslintignore

__tests__/

具体修改可参见 :rotating_light: add eslint · b3log/SymApp@f8505e7


欢迎加入开源技术 Q 群 242561391 B3log,加入黑客派,让学习和分享成为一种习惯!