強制陣列方法的回撥函式中包含 return 語句
💡 建議
ESLint 中的規則按型別分組,以幫助你理解它們的目的。每個規則都有表情符號表示
使用 recommended 配置從 @eslint/js 在 配置檔案 中啟用此規則
此規則報告的一些問題可以透過 --fix 命令列 選項自動修復
此規則報告的一些問題可以透過編輯器 建議 手動修復
此規則當前 凍結 並且不接受功能請求。
這些規則與程式碼中可能的邏輯錯誤有關
強制陣列方法的回撥函式中包含 return 語句
💡 建議
要求在建構函式中呼叫 super()
✅ 擴充套件
強制 for 迴圈更新子句將計數器向正確的方向移動
✅ 擴充套件
強制 getter 函式中包含 return 語句
✅ 擴充套件
禁止將非同步函式用作 Promise 執行器
✅ 擴充套件
禁止在迴圈中使用 await
禁止重新賦值類成員
✅ 擴充套件
禁止與 -0 進行比較
✅ 擴充套件
禁止在條件表示式中使用賦值運算子
✅ 擴充套件
禁止重新賦值 const、using 和 await using 變數
✅ 擴充套件
禁止表示式,其中操作不會影響值
✅ 擴充套件
禁止在條件中使用常量表達式
✅ 擴充套件
禁止從建構函式返回值
禁止在正則表示式中使用控制字元
✅ 擴充套件
禁止使用 debugger
✅ 擴充套件
禁止在 function 定義中重複引數
✅ 擴充套件
禁止重複類成員
✅ 擴充套件
禁止在 if-else-if 鏈中重複條件
✅ 擴充套件
禁止在物件字面量中重複鍵
✅ 擴充套件
禁止重複 case 標籤
✅ 擴充套件
禁止重複模組匯入
禁止在正則表示式中使用空字元類
✅ 擴充套件
禁止空解構模式
✅ 擴充套件
禁止在 catch 子句中重新賦值異常
✅ 擴充套件
禁止 case 語句的 fallthrough
✅ 擴充套件
禁止重新賦值 function 宣告
✅ 擴充套件
禁止將值賦給匯入的繫結
✅ 擴充套件
禁止在巢狀塊中進行變數或 function 宣告
禁止在 RegExp 建構函式中使用無效的正則表示式字串
✅ 擴充套件
禁止不規則的空白字元
✅ 擴充套件
禁止使用會損失精度的字面量數字
✅ 擴充套件
禁止在字元類語法中使用由多個程式碼點組成的字元
✅ 擴充套件
💡 建議
禁止使用全域性非建構函式函式的新運算子
✅ 擴充套件
禁止將全域性物件屬性作為函式呼叫
✅ 擴充套件
禁止從 Promise 執行器函式返回值
💡 建議
禁止直接在物件上呼叫某些 Object.prototype 方法
✅ 擴充套件
💡 建議
禁止賦值,其中兩側完全相同
✅ 擴充套件
禁止比較,其中兩側完全相同
禁止從 setter 函式返回值
✅ 擴充套件
禁止稀疏陣列
✅ 擴充套件
禁止在普通字串中使用模板字面量佔位符語法
禁止在建構函式中呼叫 super() 之前使用 this/super
✅ 擴充套件
禁止宣告但從未使用過的 let 或 var 變數
✅ 擴充套件
禁止使用未宣告的變數,除非在 /*global */ 註釋中提及
✅ 擴充套件
禁止令人困惑的多行表示式
✅ 擴充套件
禁止未修改的迴圈條件
禁止在 return、throw、continue 和 break 語句之後使用不可達程式碼
✅ 擴充套件
禁止迴圈體只允許一次迭代的迴圈
禁止在 finally 塊中使用控制流語句
✅ 擴充套件
禁止否定關係運算符的左運算元
✅ 擴充套件
💡 建議
禁止在不允許 undefined 值的情況下使用可選鏈
✅ 擴充套件
禁止使用未使用的私有類成員
✅ 擴充套件
禁止使用未使用的變數
✅ 擴充套件
💡 建議
禁止在變數定義之前使用變數
禁止變數賦值,當值未使用時
✅ 擴充套件
禁止在正則表示式中使用無用的反向引用
✅ 擴充套件
禁止賦值,這些賦值可能由於使用 await 或 yield 而導致競爭條件
要求在檢查 NaN 時呼叫 isNaN()
✅ 擴充套件
💡 建議
強制將 typeof 表示式與有效的字串進行比較
✅ 擴充套件
💡 建議
這些規則建議以不同的方式做事
強制在物件和類中使用 getter 和 setter 對
❄️ 凍結
要求箭頭函式體周圍使用大括號
🔧 修復
強制在變數定義的範圍內使用變數
❄️ 凍結
強制使用駝峰命名約定
❄️ 凍結
強制或禁止對註釋的第一個字母進行大寫
🔧 修復
強制類方法使用 this
強制程式允許的最大圈複雜度
要求 return 語句始終或從不指定值
❄️ 凍結
強制在捕獲當前執行上下文時使用一致的命名
❄️ 凍結
強制對所有控制語句使用一致的大括號樣式
🔧 修復
要求 switch 語句中包含 default 分支
強制 switch 語句中的 default 子句位於最後
❄️ 凍結
強制預設引數位於最後
❄️ 凍結
儘可能強制使用點符號
🔧 修復
要求使用 === 和 !==
🔧 修復
💡 建議
❄️ 凍結
要求函式名稱與分配給它們的變數或屬性的名稱匹配
要求或禁止命名 function 表示式
❄️ 凍結
強制一致地使用 function 宣告或分配給變數的表示式
要求在物件字面量和類中對訪問器對進行分組
要求 for-in 迴圈包含 if 語句
❄️ 凍結
禁止指定的識別符號
❄️ 凍結
強制執行識別符號的最小和最大長度
❄️ 凍結
要求識別符號與指定的正則表示式匹配
❄️ 凍結
要求或禁止在變數宣告中進行初始化
要求或禁止使用邏輯賦值運算子簡寫
🔧 修復
💡 建議
強制每個檔案允許的最大類數
強制塊可以巢狀的最大深度
強制每個檔案允許的最大行數
強制函式中允許的最大行數
強制回撥可以巢狀的最大深度
強制函式定義中允許的最大引數數
強制函式塊中允許的最大語句數
要求建構函式名稱以大寫字母開頭
禁止使用 alert、confirm 和 prompt
禁止使用 Array 建構函式
🔧 修復
💡 建議
禁止使用按位運算子
禁止使用 arguments.caller 或 arguments.callee
禁止在 case 子句中進行詞法宣告
✅ 擴充套件
💡 建議
禁止使用 console
💡 建議
❄️ 凍結
禁止使用 continue 語句
禁止刪除變數
✅ 擴充套件
❄️ 凍結
禁止在正則表示式的開頭明確使用等號
🔧 修復
❄️ 凍結
禁止在 if 語句中 return 語句之後使用 else 塊
🔧 修復
禁止空塊語句
✅ 擴充套件
💡 建議
禁止空函式
💡 建議
禁止空靜態塊
✅ 擴充套件
💡 建議
禁止在沒有型別檢查運算子的情況下與 null 進行比較
禁止使用 eval()
禁止擴充套件原生型別
禁止不必要的 .bind() 呼叫
🔧 修復
❄️ 凍結
禁止不必要的布林值轉換
✅ 擴充套件
🔧 修復
❄️ 凍結
禁止不必要的標籤
🔧 修復
禁止將賦值分配給原生物件或只讀全域性變數
✅ 擴充套件
❄️ 凍結
禁止簡寫型別轉換
🔧 修復
💡 建議
禁止在全域性範圍內進行宣告
禁止使用類似 eval() 的方法
❄️ 凍結
禁止在程式碼之後使用行內註釋
禁止在 this 的值為 undefined 的上下文中使用 this
禁止使用 __iterator__ 屬性
❄️ 凍結
禁止標籤與變數同名
❄️ 凍結
禁止使用標籤語句
禁止不必要的巢狀塊
❄️ 凍結
禁止在 else 塊中將 if 語句作為唯一語句
🔧 修復
禁止在迴圈語句內部包含不安全引用的函式宣告
❄️ 凍結
禁止使用魔術數字
禁止使用鏈式賦值表示式
❄️ 凍結
禁止多行字串
❄️ 凍結
禁止否定條件
❄️ 凍結
禁止巢狀三元表示式
禁止在賦值或比較之外使用 new 運算子
禁止使用 Function 物件建立 new 運算子
禁止使用 String、Number 和 Boolean 物件建立 new 運算子
禁止在字串字面量中使用 \8 和 \9 轉義序列
✅ 擴充套件
💡 建議
禁止呼叫不帶引數的 Object 建構函式
💡 建議
禁止使用八進位制字面量
✅ 擴充套件
禁止在字串字面量中使用八進位制轉義序列
禁止重新分配函式引數
❄️ 凍結
禁止使用一元運算子 ++ 和 --
禁止使用 __proto__ 屬性
禁止變數重新宣告
✅ 擴充套件
禁止正則表示式中出現多個空格
✅ 擴充套件
🔧 修復
禁止在匯出中使用指定名稱
禁止使用指定的全域性變數
禁止在 import 載入時使用指定的模組
禁止在某些物件上使用某些屬性
禁止使用指定的語法
禁止在 return 語句中使用賦值運算子
禁止使用 javascript: URL
禁止使用逗號運算子
禁止變數宣告遮蔽外部作用域中宣告的變數
禁止識別符號遮蔽受限名稱
✅ 擴充套件
❄️ 凍結
禁止使用三元運算子
禁止將字面量作為異常丟擲
❄️ 凍結
禁止將變數初始化為 undefined
🔧 修復
❄️ 凍結
禁止將 undefined 作為識別符號使用
❄️ 凍結
禁止識別符號中使用懸垂下劃線
❄️ 凍結
禁止在存在更簡單替代方案時使用三元運算子
🔧 修復
禁止使用未使用的表示式
禁止使用未使用的標籤
✅ 擴充套件
🔧 修復
禁止不必要的 .call() 和 .apply() 呼叫
禁止不必要的 catch 子句
✅ 擴充套件
❄️ 凍結
禁止在物件和類中使用不必要的計算屬性鍵
🔧 修復
❄️ 凍結
禁止不必要的字面量或模板字面量的連線
禁止不必要的建構函式
💡 建議
禁止不必要的跳脫字元
✅ 擴充套件
💡 建議
禁止將匯入、匯出和解構賦值重新命名為相同名稱
🔧 修復
禁止冗餘的 return 語句
🔧 修復
要求使用 let 或 const 代替 var
🔧 修復
❄️ 凍結
禁止使用 void 運算子
❄️ 凍結
禁止在註釋中使用指定的警告詞語
禁止使用 with 語句
✅ 擴充套件
❄️ 凍結
要求或禁止物件字面量中使用方法和屬性簡寫語法
🔧 修復
❄️ 凍結
強制在函式中變數要麼一起宣告,要麼分開宣告
🔧 修復
❄️ 凍結
要求或禁止在可能的情況下使用賦值運算子簡寫
🔧 修復
❄️ 凍結
要求使用箭頭函式作為回撥函式
🔧 修復
要求對聲明後從未重新分配的變數使用 const 宣告
🔧 修復
❄️ 凍結
要求從陣列和/或物件進行解構
🔧 修復
禁止使用 Math.pow,而推薦使用 ** 運算子
🔧 修復
強制在正則表示式中使用命名捕獲組
💡 建議
❄️ 凍結
禁止使用 parseInt() 和 Number.parseInt(),而推薦使用二進位制、八進位制和十六進位制字面量
🔧 修復
禁止使用 Object.prototype.hasOwnProperty.call(),而推薦使用 Object.hasOwn()
🔧 修復
❄️ 凍結
禁止使用物件字面量作為第一個引數的 Object.assign,而推薦使用物件展開運算子
🔧 修復
要求使用 Error 物件作為 Promise 拒絕的原因
禁止使用 RegExp 建構函式,而推薦使用正則表示式字面量
💡 建議
要求使用剩餘引數代替 arguments
❄️ 凍結
要求使用展開運算子代替 .apply()
❄️ 凍結
要求使用模板字面量代替字串連線
🔧 修復
禁止在重新丟擲自定義錯誤時丟失原始捕獲的錯誤
✅ 擴充套件
💡 建議
強制在使用 parseInt() 時使用基數引數
💡 建議
禁止沒有 await 表示式的非同步函式
💡 建議
強制在正則表示式中使用 u 或 v 標誌
💡 建議
要求生成器函式包含 yield
✅ 擴充套件
❄️ 凍結
強制模組內 import 宣告排序
🔧 修復
❄️ 凍結
要求物件鍵排序
❄️ 凍結
要求在同一宣告塊中變數排序
🔧 修復
要求或禁止嚴格模式指令
🔧 修復
要求符號描述
❄️ 凍結
要求 var 宣告放置在其包含作用域的頂部
❄️ 凍結
要求或禁止“Yoda”條件
🔧 修復
這些規則關注程式碼的外觀,而不是程式碼的執行方式
要求或禁止 Unicode 位元組順序標記 (BOM)
🔧 修復
這些規則已根據 棄用策略 棄用,並由更新的規則取代
array-bracket-newline 已棄用
❌
🔧 修復
array-bracket-spacing 已棄用
❌
🔧 修復
array-element-newline 已棄用
❌
🔧 修復
arrow-parens 已棄用
由 arrow-parens 在 @stylistic/eslint-plugin 中取代
❌
🔧 修復
arrow-spacing 已棄用
❌
🔧 修復
block-spacing 已棄用
❌
🔧 修復
brace-style 已棄用
由 brace-style 在 @stylistic/eslint-plugin 中取代
❌
🔧 修復
callback-return 已棄用
由 callback-return 在 eslint-plugin-n 中取代
❌
comma-dangle 已棄用
由 comma-dangle 在 @stylistic/eslint-plugin 中取代
❌
🔧 修復
comma-spacing 已棄用
❌
🔧 修復
comma-style 已棄用
由 comma-style 在 @stylistic/eslint-plugin 中取代
❌
🔧 修復
computed-property-spacing 已棄用
❌
🔧 修復
dot-location 已棄用
由 dot-location 在 @stylistic/eslint-plugin 中取代
❌
🔧 修復
eol-last 已棄用
由 eol-last 在 @stylistic/eslint-plugin 中取代
❌
🔧 修復
func-call-spacing 已棄用
❌
🔧 修復
function-call-argument-newline 已棄用
由 function-call-argument-newline 在 @stylistic/eslint-plugin 中取代
❌
🔧 修復
function-paren-newline 已棄用
❌
🔧 修復
generator-star-spacing 已棄用
❌
🔧 修復
global-require 已棄用
由 global-require 在 eslint-plugin-n 中取代
❌
handle-callback-err 已棄用
由 handle-callback-err 在 eslint-plugin-n 中取代
❌
id-blacklist 已棄用
由 id-denylist 取代
❌
implicit-arrow-linebreak 已棄用
❌
🔧 修復
indent 已棄用
由 indent 在 @stylistic/eslint-plugin 中取代
❌
🔧 修復
indent-legacy 已棄用
由 indent 在 @stylistic/eslint-plugin 中取代
❌
🔧 修復
jsx-quotes 已棄用
由 jsx-quotes 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
key-spacing 已棄用
由 key-spacing 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
keyword-spacing 已棄用
❌
🔧 修復
line-comment-position 已棄用
❌
linebreak-style 已棄用
❌
🔧 修復
lines-around-comment 已棄用
❌
🔧 修復
lines-around-directive 已棄用
由 padding-line-between-statements 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
lines-between-class-members 已棄用
由 lines-between-class-members 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
max-len 已棄用
由 max-len 在 @stylistic/eslint-plugin 中替代
❌
max-statements-per-line 已棄用
❌
multiline-comment-style 已棄用
❌
🔧 修復
multiline-ternary 已棄用
❌
🔧 修復
new-parens 已棄用
由 new-parens 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
newline-after-var 已棄用
由 padding-line-between-statements 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
newline-before-return 已棄用
由 padding-line-between-statements 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
newline-per-chained-call 已棄用
❌
🔧 修復
no-buffer-constructor 已棄用
由 no-deprecated-api 在 eslint-plugin-n 中替代
❌
no-catch-shadow 已棄用
由 no-shadow 替代
❌
no-confusing-arrow 已棄用
❌
🔧 修復
no-extra-parens 已棄用
❌
🔧 修復
no-extra-semi 已棄用
❌
🔧 修復
no-floating-decimal 已棄用
❌
🔧 修復
no-mixed-operators 已棄用
❌
no-mixed-requires 已棄用
由 no-mixed-requires 在 eslint-plugin-n 中替代
❌
no-mixed-spaces-and-tabs 已棄用
❌
no-multi-spaces 已棄用
❌
🔧 修復
no-multiple-empty-lines 已棄用
❌
🔧 修復
no-native-reassign 已棄用
由 no-global-assign 替代
❌
no-negated-in-lhs 已棄用
由 no-unsafe-negation 替代
❌
no-new-object 已棄用
❌
no-new-require 已棄用
由 no-new-require 在 eslint-plugin-n 中替代
❌
no-new-symbol 已棄用
❌
no-path-concat 已棄用
由 no-path-concat 在 eslint-plugin-n 中替代
❌
no-process-env 已棄用
由 no-process-env 在 eslint-plugin-n 中替代
❌
no-process-exit 已棄用
由 no-process-exit 在 eslint-plugin-n 中替代
❌
no-restricted-modules 已棄用
由 no-restricted-require 在 eslint-plugin-n 中替代
❌
no-return-await 已棄用
❌
💡 建議
no-spaced-func 已棄用
❌
🔧 修復
no-sync 已棄用
由 no-sync 在 eslint-plugin-n 中替代
❌
no-tabs 已棄用
由 no-tabs 在 @stylistic/eslint-plugin 中替代
❌
no-trailing-spaces 已棄用
❌
🔧 修復
no-whitespace-before-property 已棄用
由 no-whitespace-before-property 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
nonblock-statement-body-position 已棄用
由 nonblock-statement-body-position 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
object-curly-newline 已棄用
❌
🔧 修復
object-curly-spacing 已棄用
❌
🔧 修復
object-property-newline 已棄用
❌
🔧 修復
one-var-declaration-per-line 已棄用
由 one-var-declaration-per-line 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
operator-linebreak 已棄用
❌
🔧 修復
padded-blocks 已棄用
❌
🔧 修復
padding-line-between-statements 已棄用
由 padding-line-between-statements 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
prefer-reflect 已棄用
❌
quote-props 已棄用
由 quote-props 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
quotes 已棄用
由 quotes 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
rest-spread-spacing 已棄用
❌
🔧 修復
semi 已棄用
由 semi 在 @stylistic/eslint-plugin 中替代
❌
🔧 修復
semi-spacing 已棄用
由 semi-spacing 在 @stylistic/eslint-plugin 中替換
❌
🔧 修復
semi-style 已棄用
由 semi-style 在 @stylistic/eslint-plugin 中替換
❌
🔧 修復
space-before-blocks 已棄用
❌
🔧 修復
space-before-function-paren 已棄用
由 space-before-function-paren 在 @stylistic/eslint-plugin 中替換
❌
🔧 修復
space-in-parens 已棄用
❌
🔧 修復
space-infix-ops 已棄用
❌
🔧 修復
space-unary-ops 已棄用
❌
🔧 修復
spaced-comment 已棄用
❌
🔧 修復
switch-colon-spacing 已棄用
❌
🔧 修復
template-curly-spacing 已棄用
❌
🔧 修復
template-tag-spacing 已棄用
❌
🔧 修復
wrap-iife 已棄用
由 wrap-iife 在 @stylistic/eslint-plugin 中替換
❌
🔧 修復
wrap-regex 已棄用
由 wrap-regex 在 @stylistic/eslint-plugin 中替換
❌
🔧 修復
yield-star-spacing 已棄用
❌
🔧 修復
這些規則來自較早版本的 ESLint(在 棄用策略 存在之前)已被新規則替換
generator-star 已移除
global-strict 已移除
由 strict 替換
no-arrow-condition 已移除
no-comma-dangle 已移除
由 comma-dangle 替換
no-empty-class 已移除
no-empty-label 已移除
由 no-labels 替換
no-extra-strict 已移除
由 strict 替換
no-reserved-keys 已移除
由 quote-props 替換
no-space-before-semi 已移除
由 semi-spacing 替換
no-wrap-func 已移除
由 no-extra-parens 替換
space-after-function-name 已移除
space-after-keywords 已移除
由 keyword-spacing 替換
space-before-function-parentheses 已移除
space-before-keywords 已移除
由 keyword-spacing 替換
space-in-brackets 已移除
由 object-curly-spacing 或
array-bracket-spacing 或
computed-property-spacing
space-return-throw-case 已移除
由 keyword-spacing 替換
space-unary-word-ops 已移除
由 space-unary-ops 替換
spaced-line-comment 已移除
由 spaced-comment 替換
valid-jsdoc 已移除
require-jsdoc 已移除