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

本贴最后更新于 2479 天前,其中的信息可能已经东海扬尘

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__/

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

  • React

    React 是 Facebook 开源的一个用于构建 UI 的 JavaScript 库。

    192 引用 • 291 回帖 • 444 关注
  • eslint
    3 引用

相关帖子

欢迎来到这里!

我们正在构建一个小众社区,大家在这里相互信任,以平等 • 自由 • 奔放的价值观进行分享交流。最终,希望大家能够找到与自己志同道合的伙伴,共同成长。

注册 关于
请输入回帖内容 ...