react项目 .eslintrc常规通用配置 要用的最多的
时间: 2023-10-13 14:04:29 浏览: 51
针对React项目常用的.eslintrc配置如下:
```
{
"parser": "babel-eslint",
"extends": [
"eslint:recommended",
"plugin:react/recommended"
],
"plugins": [
"react"
],
"rules": {
"indent": ["error", 2],
"linebreak-style": ["error", "unix"],
"quotes": ["error", "single"],
"semi": ["error", "always"],
"react/prop-types": 0,
"react/jsx-uses-react": "error",
"react/jsx-uses-vars": "error"
}
}
```
其中,`parser`指定使用`babel-eslint`解析器;`extends`继承了`eslint:recommended`和`plugin:react/recommended`,前者是ESLint默认规则,后者是React相关规则;`plugins`指定使用React插件;`rules`定义具体的规则,例如缩进、换行符、引号、分号等,其中`react/prop-types`规则用于检查是否定义了组件的props类型;`react/jsx-uses-react`和`react/jsx-uses-vars`规则用于检查是否正确引入了React。
相关推荐
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)