詳解React項(xiàng)目中eslint使用百度風(fēng)格
1.安裝百度Eslint Rule 插件
npm i -D eslint @babel/eslint-parser @babel/eslint-plugin @ecomfe/eslint-config // react項(xiàng)目 npm i -D eslint-plugin-react eslint-plugin-react-hooks // 如果需要支持typescript的話 npm i -D @typescript-eslint/parser @typescript-eslint/eslint-plugin
2.配置.eslintrc文件
{
"parser": "@typescript-eslint/parser", // typescript解析器
"extends": [
"@ecomfe/eslint-config", // 繼承廠內(nèi)EE-eslint規(guī)則配置
"@ecomfe/eslint-config/react"
],
"plugins": [
"@typescript-eslint", // 增加一些typescript語法檢查
"react", // react語法檢查
"react-hooks" // hooks語法檢查
],
"rules": {
"indent": [
"error",
4,
{
"SwitchCase": 1
}
], // 強(qiáng)制4格風(fēng)格
"no-unused-vars": "off", // 關(guān)掉eslint no-unused-vars默認(rèn)配置
"@typescript-eslint/no-unused-vars": [
"warn",
{
"vars": "all",
"args": "after-used",
"ignoreRestSiblings": false
}
], // 使用@typescript-eslint/no-unused-vars配置
"import/no-unresolved": "off",
"react/jsx-uses-react": 2, // 屏蔽"React" is defined but never used錯誤
"import/order": "off", // 不需要引入順序驗(yàn)證
"comma-dangle": [
"off"
], // 不允許最后多余的逗號
"@typescript-eslint/consistent-type-definitions": [
"off"
], // 先off掉
"react-hooks/rules-of-hooks": "error", // 檢查Hook的規(guī)則
"react-hooks/exhaustive-deps": "warn", // 檢查effect的依賴
"max-params": [
"warn",
8
], // 方法最多8個參數(shù)
"no-use-before-define": "off",
"@typescript-eslint/no-use-before-define": [
"error",
{
"functions": false,
"variables": false
}
], // 注意:方法和變量可以在使用之后定義!為了解決hooks中經(jīng)常會出現(xiàn)的循環(huán)依賴的問題,不過要注意危險
"react/jsx-no-bind": [
"warn",
{
"allowArrowFunctions": true // 暫且允許箭頭函數(shù),來提升代碼可讀性
}
],
"max-nested-callbacks": [
"warn",
4
], // 循環(huán)最多4層,超過4層警告
"react/require-default-props": "off", // 組件的非必填屬性不要求一定有默認(rèn)值
"react/no-find-dom-node": "off", // 暫且允許使用react-dom的findDOMNode方法
"@babel/object-curly-spacing": "off",
"object-curly-spacing": [
"off",
"always",
{
"arraysInObjects": false
}
], // 對象括號是否允許添加空格
"brace-style": [
"off",
"1tbs"
],
"react/no-string-refs": "warn", // string類型的refs報warn
"no-unreachable-loop": "off",
"eol-last": ["error", "always"] // 文件末尾需要多空一行
}
}

3.安裝Eslint, Prettier Eslint插件


4.如果不可以檢查一下Prettier ESlint需要的包有沒有安裝

到此這篇關(guān)于React項(xiàng)目中eslint使用百度風(fēng)格的文章就介紹到這了,更多相關(guān)React項(xiàng)目使用eslint內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!
相關(guān)文章
React利用scheduler思想實(shí)現(xiàn)任務(wù)的打斷與恢復(fù)
這篇文章主要為大家詳細(xì)介紹了React如何利用scheduler思想實(shí)現(xiàn)任務(wù)的打斷與恢復(fù),文中的示例代碼講解詳細(xì),感興趣的小伙伴可以參考一下2024-03-03
React組件對子組件children進(jìn)行加強(qiáng)的方法
這篇文章主要給大家介紹了關(guān)于React組件中對子組件children進(jìn)行加強(qiáng)的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用React具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧2019-06-06
使用VScode 插件debugger for chrome 調(diào)試react源碼的方法
這篇文章主要介紹了使用VScode 插件debugger for chrome 調(diào)試react源碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-09-09
解決react?antd?Table組件使用radio單選框?更新選中數(shù)據(jù)不渲染問題
這篇文章主要介紹了解決react?antd?Table組件使用radio單選框?更新選中數(shù)據(jù)不渲染問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2024-03-03
React?Native?中實(shí)現(xiàn)倒計(jì)時功能
這篇文章主要介紹了React?Native中實(shí)現(xiàn)倒計(jì)時功能示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08

