安装
npm install eslint-config-rax
依赖的库有:
// 基础依赖
"babel-eslint": "^10.0.1"
"eslint": "^5.16.0"
"eslint-plugin-import": "^2.17.2"
// 使用Typescript时依赖
"@typescript-eslint/eslint-plugin": "^1.7.0"
"@typescript-eslint/parser": "^1.7.0"
"typescript": "^3.4.5"
// 使用React时依赖
"eslint-plugin-react": "^7.12.4"
使用
设置 .eslintrc.js
内容如下:
- 普通JS项目设置示例见 .eslintrc.js
- React项目设置示例见 .eslintrc.js
- Typescript 项目设置示例见 .eslintrc.js
- React Typescript 项目设置示例见 .eslintrc.js
规则定义说明
- 基础规则 基于Rax 相关项目沉淀
- React规则 基于Rax 相关项目沉淀
- Typescript规则 基于 @typescript-eslint/eslint-plugin 推荐规则
修改规则
若修改增添规则,请提供规则的用处和理由
比如:
/**
* Indent is replaced by two Spaces
* @reason Conventional convention
*/
"indent": "off",
'@typescript-eslint/indent': [
'error',
2,
{
SwitchCase: 1,
flatTernaryExpressions: true
}
],