1.安装 npm 包
npm i eslint-config-react-native-prettier --save-dev
npm i prettier-eslint --save-dev
2.配置 .eslintrc
- 项目下创建
.eslintrc
文件 - 配置
{
"extends": ["react-native-prettier"],
"rules": {
"prettier/prettier": [
"error",
{
"tabWidth": 4
}
],
"no-var": "warn",
"no-dupe-class-members": "warn",
"no-duplicate-case": "warn",
"no-duplicate-imports": "warn",
"no-dupe-keys": "warn",
"no-dupe-args": "warn",
"react/no-deprecated": "warn",
"react/no-string-refs": "warn"
}
}
具体配置可以参考
3.安装 VSCode 插件
- Eslint
- Prettier
4.配置 VSCode
// 点击保存时,根据 eslint 规则自定修复,同时集成 prettier 到 eslint 中
"prettier.eslintIntegration": true,
"eslint.autoFixOnSave": true,
// 为了避免和 eslint 冲突,讲编辑器默认的代码检查规则关闭(如果开启了)
"editor.formatOnSave": true,
"javascript.format.enable": false,
// 禁止基于内容自动检测 tabSize
"editor.detectIndentation": false,
网友评论