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

SymApp Demo

ToC

添加依赖

1
2
3
4
5
6
7
8
9
"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"
},

添加命令

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

添加规则 .eslintrc

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
{
"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

1
__tests__/

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