JavaScript 规则
以下是 Biome 支持的规则列表,按组划分。以下是表情符号的图例:
¥Below the list of rules supported by Biome, divided by group. Here’s a legend of the emojis:
-
图标 表示该规则是推荐规则的一部分。
¥The icon indicates that the rule is part of the recommended rules.
-
图标 表示该规则提供了可以安全应用的代码操作(修复)。
¥The icon indicates that the rule provides a code action (fix) that is safe to apply.
-
图标 表示该规则提供了不安全应用的代码操作(修复)。
¥The icon indicates that the rule provides a code action (fix) that is unsafe to apply.
-
图标 表示该规则已实现并计划在下一个版本中发布。
¥The icon indicates that the rule has been implemented and scheduled for the next release.
| 规则名称 | 描述 | 属性 |
|---|---|---|
| noAccessKey | 强制不在任何 HTML 元素上使用 accessKey 属性。 | |
| noAriaHiddenOnFocusable | 强制可聚焦元素上未设置 aria-hidden=“true”。 | |
| noAriaUnsupportedElements | 强制不支持 ARIA 角色、状态和属性的元素不具有这些属性。 | |
| noAutofocus | 强制元素上未使用 autoFocus prop。 | |
| noDistractingElements | 强制不使用分散注意力的元素。 | |
| noHeaderScope | 范围属性应仅用于 <th> 元素。 | |
| noInteractiveElementToNoninteractiveRole | 强制不将非交互式 ARIA 角色分配给交互式 HTML 元素。 | |
| noLabelWithoutControl | 强制标签元素或组件具有文本标签和相关输入。 | |
| noNoninteractiveElementInteractions | 禁止在非交互式元素上使用事件处理程序。 | |
| noNoninteractiveElementToInteractiveRole | 强制不将交互式 ARIA 角色分配给非交互式 HTML 元素。 | |
| noNoninteractiveTabindex | 强制将 tabIndex 分配给具有 的非交互式 HTML 元素。 | |
| noPositiveTabindex | 防止在 tabIndex 属性上使用正整数 | |
| noRedundantAlt | 强制 img alt prop 不包含单词 “image”、“picture” 或 “photo”。 | |
| noRedundantRoles | 强制默认函数参数和可选函数参数位于最后。 | |
| noStaticElementInteractions | 强制具有点击处理程序的静态可见元素(例如 <div>)使用有效的角色属性。 | |
| noSvgWithoutTitle | 强制对 svg 元素使用 title 元素。 | |
| useAltText | 强制所有需要替代文本的元素都具有有意义的信息以传递回终端用户。 | |
| useAnchorContent | 强制锚点具有内容,并且内容可供屏幕阅读器访问。 | |
| useAriaActivedescendantWithTabindex | 强制 tabIndex 元素具有 aria-activedescendant 属性。 | |
| useAriaPropsForRole | 强制具有 ARIA 角色的元素必须具有该角色所需的所有 ARIA 属性。 | |
| useAriaPropsSupportedByRole | 强制 ARIA 属性对于元素支持的角色有效。 | |
| useButtonType | 强制对元素 button 使用属性 type | |
| useFocusableInteractive | 具有交互角色和交互处理程序的元素必须是可聚焦的。 | |
| useHeadingContent | 强制标题元素(h1、h2 等)具有内容,并且内容可供屏幕阅读器访问。可访问意味着它不会使用 aria-hidden 属性隐藏。 | |
| useHtmlLang | 强制 ARIA 状态和属性值有效。 | |
| useIframeTitle | 强制对元素 iframe 使用属性 title。 | |
| useKeyWithClickEvents | 强制整个代码库的所有内容的命名约定。onKeyUp, onKeyDown, onKeyPress. | |
| useKeyWithMouseEvents | 强制 onMouseOver / onMouseOut 伴随 onFocus / onBlur。 | |
| useMediaCaption | 强制 audio 和 video 元素必须具有 track 作为标题。 | |
| useSemanticElements | 它检测 JSX 元素中 role 属性的使用并建议改用语义元素。 | |
| useValidAnchor | 强制所有锚点有效,并且它们是可导航元素。 | |
| useValidAriaProps | 确保 ARIA 属性 aria-* 全部有效。 | |
| useValidAriaRole | 具有 ARIA 角色的元素必须使用有效的非抽象 ARIA 角色。 | |
| useValidAriaValues | 强制正确使用 和 。 | |
| useValidAutocomplete | 对 input 元素上的 autocomplete 属性使用有效值。 | |
| useValidLang | 确保传递给 lang 属性的属性是正确的 ISO 语言和/或国家/地区。 |
complexity
Section titled “complexity”| 规则名称 | 描述 | 属性 |
|---|---|---|
| noAdjacentSpacesInRegex | 禁止在正则表达式文字中不明确地使用连续空格字符 | |
| noArguments | 禁止使用 arguments。 | |
| noBannedTypes | 禁止原始类型别名和误导性类型。 | |
| noCommaOperator | 禁止逗号运算符。 | |
| noEmptyTypeParameters | 禁止类型别名和接口中的空类型参数。 | |
| noExcessiveCognitiveComplexity | 禁止超过给定认知复杂性分数的函数。 | |
| noExcessiveLinesPerFunction | 限制函数中的代码行数。 | |
| noExcessiveNestedTestSuites | 此规则强制测试文件中嵌套 describe() 的最大深度。 | |
| noExtraBooleanCast | 禁止不必要的布尔转换 | |
| noFlatMapIdentity | 禁止在 flatMap 上使用不必要的回调。 | |
| noForEach | 首选 for...of 语句而不是 Array.forEach。 | |
| noImplicitCoercions | 禁止使用简写类型转换。 | |
| noStaticOnlyClass | 此规则报告类没有非静态成员的情况,例如专门用作静态命名空间的类。 | |
| noThisInStatic | 禁止在 static 上下文中使用 this 和 super。 | |
| noUselessCatch | 禁止不必要的 catch 子句。 | |
| noUselessConstructor | 禁止不必要的构造函数。 | |
| noUselessContinue | 避免使用不必要的 continue。 | |
| noUselessEmptyExport | 禁止在模块文件中不更改任何内容的空导出。 | |
| noUselessEscapeInRegex | 禁止在正则表达式文字中使用不必要的转义序列。 | |
| noUselessFragments | 禁止不必要的片段 | |
| noUselessLabel | 禁止不必要的标签。 | |
| noUselessLoneBlockStatements | 禁止不必要的嵌套块语句。 | |
| noUselessRename | 禁止将导入、导出和解构分配重命名为同一名称。 | |
| noUselessStringConcat | 禁止不必要的字符串或模板文字连接。 | |
| noUselessStringRaw | 禁止在模板字符串字面量中使用不必要的 String.raw 函数(不带任何转义序列)。 | |
| noUselessSwitchCase | 禁止在 switch 语句中使用无用的 case。 | |
| noUselessTernary | 当存在更简单的替代方案时,禁止使用三元运算符。 | |
| noUselessThisAlias | 禁止无用的 this 别名。 | |
| noUselessTypeConstraint | 禁止使用 any 或 unknown 作为类型约束。 | |
| noUselessUndefinedInitialization | 禁止将变量初始化为 undefined。 | |
| noVoid | 禁止使用 void 运算符,因为它不是一个熟悉的运算符。 | |
| useArrowFunction | 在函数表达式上使用箭头函数。 | |
| useDateNow | 使用 Date.now() 获取自 Unix 纪元以来的毫秒数。 | |
| useFlatMap | 提倡在 map().flat() 一起使用时使用 .flatMap()。 | |
| useIndexOf | 查找项目索引时,优先使用 Array#{indexOf,lastIndexOf}() 而不是 Array#{findIndex,findLastIndex}()。 | |
| useLiteralKeys | 强制使用文字访问属性而不是计算属性访问。 | |
| useNumericLiterals | 禁止 parseInt() 和 Number.parseInt(),转而使用二进制、八进制和十六进制文字 | |
| useOptionalChain | 强制使用简洁的可选链而不是链式逻辑表达式。 | |
| useRegexLiterals | 如果可能,强制使用正则表达式文字而不是 RegExp 构造函数。 | |
| useSimpleNumberKeys | 禁止使用非十进制或以下划线作为分隔符的数字字面量对象成员名称。 | |
| useSimplifiedLogicExpression | 从逻辑表达式中丢弃冗余术语。 | |
| useWhile | 当不需要初始化程序和更新表达式时,强制使用 while 循环而不是 for 循环。 |
correctness
Section titled “correctness”| 规则名称 | 描述 | 属性 |
|---|---|---|
| noChildrenProp | 防止将子组件作为 props 传递。 | |
| noConstAssign | 防止重新分配 const 变量。 | |
| noConstantCondition | 禁止在条件中使用常量表达式 | |
| noConstantMathMinMaxClamp | 禁止使用 Math.min 和 Math.max 来限制结果本身为常数的值。 | |
| noConstructorReturn | 禁止从 constructor 返回值。 | |
| noEmptyCharacterClassInRegex | 禁止正则表达式文字中的空字符类。 | |
| noEmptyPattern | 禁止空的解构模式。 | |
| noGlobalDirnameFilename | 禁止在全局作用域中使用 __dirname 和 __filename。 | |
| noGlobalObjectCalls | 禁止将全局对象属性作为函数调用 | |
| noInnerDeclarations | 禁止在其块外可访问的 function 和 var 声明。 | |
| noInvalidBuiltinInstantiation | 确保内置函数正确实例化。 | |
| noInvalidConstructorSuper | 防止在类中错误使用 super()。它还检查扩展其他构造函数的类中是否缺少调用 super()。 | |
| noInvalidUseBeforeDeclaration | 禁止在声明之前使用变量、函数参数、类和枚举。 | |
| noNestedComponentDefinitions | 禁止在其他组件内部定义 React 组件。 | |
| noNodejsModules | 禁止使用 Node.js 内置模块。 | |
| noNonoctalDecimalEscape | 禁止字符串文字中的 \8 和 \9 转义序列。 | |
| noPrecisionLoss | 禁止丢失精度的文字数字 | |
| noPrivateImports | 限制导入私有导出项。 | |
| noProcessGlobal | 禁止使用全局变量 process。 | |
| noQwikUseVisibleTask | 禁止在 Qwik 组件中使用 useVisibleTask$() 函数。 | |
| noReactPropAssignments | 禁止向 React 组件赋值 props。 | |
| noRenderReturnValue | 防止使用 React.render 的返回值。 | |
| noRestrictedElements | 禁止使用已配置的元素。 | |
| noSelfAssign | 禁止在双方完全相同的情况下进行分配。 | |
| noSetterReturn | 禁止从 setter 返回值 | |
| noSolidDestructuredProps | 禁止在 Solid 项目中解构 JSX 组件内的 props。 | |
| noStringCaseMismatch | 禁止比较使用不合规值修改字符串大小写的表达式。 | |
| noSwitchDeclarations | 禁止在 switch 子句中使用词汇声明。 | |
| noUndeclaredDependencies | 禁止使用未在 package.json 中指定的依赖。 | |
| noUndeclaredVariables | 防止使用文档中未声明的变量。 | |
| noUnreachable | 禁止无法访问的代码 | |
| noUnreachableSuper | 如果类具有超类,则确保在访问 this 之前,在类构造函数中的每个代码路径上都只调用一次 super() 构造函数 | |
| noUnsafeFinally | 禁止在 finally 块中控制流语句。 | |
| noUnsafeOptionalChaining | 禁止在未允许使用未定义值的上下文中使用可选链接。 | |
| noUnusedFunctionParameters | 禁止未使用的函数参数。 | |
| noUnusedImports | 禁止未使用的导入。 | |
| noUnusedLabels | 禁止未使用的标签。 | |
| noUnusedPrivateClassMembers | 禁止未使用的私有类成员 | |
| noUnusedVariables | 禁止未使用的变量。 | |
| noVoidElementsWithChildren | 此规则防止空元素(又称自关闭元素)有子元素。 | |
| noVoidTypeReturn | 禁止从返回类型为 ‘void’ 的函数返回值 | |
| useExhaustiveDependencies | 强制 React Hooks 中正确使用依赖。 | |
| useHookAtTopLevel | 强制所有 React 钩子都从顶层组件函数调用。 | |
| useImageSize | 强制 <img> 元素同时具有 width 和 height 属性。 | |
| useImportExtensions | 强制显式比较值的 、、 或 属性。 | |
| useIsNan | 要求在检查 NaN 时调用 isNaN()。 | |
| useJsonImportAttributes | 强制 JSON 模块导入使用 with { type: "json" }。 | |
| useJsxKeyInIterable | 禁止在迭代器/集合文字中缺少关键属性。 | |
| useParseIntRadix | 强制要求在使用 parseInt() 时始终使用基数参数。 | |
| useQwikClasslist | 建议使用 class 属性作为类列表,而不是 classnames 辅助函数。 | |
| useSingleJsDocAsterisk | 强制 JSDoc 注释行以单个星号开头,第一个星号除外。 | |
| useUniqueElementIds | 防止在元素上使用静态字符串字面量 id 属性。 | |
| useValidForDirection | 强制 “for” 循环更新子句将计数器移向正确的方向。 | |
| useValidTypeof | 此规则检查 typeof 表达式的结果是否与有效值进行比较。 | |
| useYield | 要求生成器函数包含 yield。 |
nursery
Section titled “nursery”| 规则名称 | 描述 | 属性 |
|---|---|---|
| noAmbiguousAnchorText | 禁止使用含义模糊的锚点描述。 | |
| noContinue | 禁止使用 continue 语句。 | |
| noDeprecatedImports | 限制导入已弃用的导出项。 | |
| noDuplicatedSpreadProps | 禁止 JSX prop 多次展开相同的标识符。 | |
| noEmptySource | 禁止使用空源。 | |
| noEqualsToNull | 要求使用 === 或 !== 与 null 进行比较。 | |
| noFloatingPromises | 要求正确处理类似 Promise 的语句。 | |
| noForIn | 禁止使用 for-in 循环进行迭代。 | |
| noImportCycles | 防止循环导入。 | |
| noIncrementDecrement | 禁止使用一元运算符 ++ 和 —。 | |
| noJsxLiterals | 禁止在 JSX 元素中使用字符串字面量。 | |
| noLeakedRender | 防止渲染有问题的泄漏值。 | |
| noMisusedPromises | 禁止在几乎可以肯定是错误的地方使用 Promise。 | |
| noMultiStr | 禁止通过转义换行符创建多行字符串。 | |
| noNextAsyncClientComponent | 防止客户端组件是异步函数。 | |
| noParametersOnlyUsedInRecursion | 禁止使用仅在递归调用中使用的函数参数。 | |
| noProto | 禁止使用已弃用的 __proto__ 对象属性。 | |
| noReactForwardRef | 将 forwardRef 的使用替换为将 ref 作为 prop 传递。 | |
| noScriptUrl | 禁止使用 javascript: URL。 | |
| noShadow | 禁止变量声明覆盖外部作用域中声明的变量。 | |
| noSyncScripts | 防止使用同步脚本。 | |
| noTernary | 禁止使用三元运算符。 | |
| noUndeclaredEnvVars | 禁止使用未声明的环境变量。 | |
| noUnknownAttribute | 禁止使用未知的 DOM 属性。 | |
| noUnnecessaryConditions | 禁止使用静态方法判断为冗余的、不必要的基于类型的条件。 | |
| noUnresolvedImports | 导入不存在的导出文件时会发出警告。 | |
| noUnusedExpressions | 禁止使用既不是函数调用也不是赋值的表达式语句。 | |
| noUselessCatchBinding | 禁止使用未使用的 catch 绑定。 | |
| noUselessUndefined | 禁止使用无用的 undefined 指令。 | |
| noVueDataObjectDeclaration | 强制要求 Vue 组件的 data 选项声明为函数。 | |
| noVueDuplicateKeys | 禁止在 Vue 组件的数据、方法、计算属性和其他选项中使用重复的键。 | |
| noVueReservedKeys | 禁止在 Vue 组件数据和计算属性中使用保留键。 | |
| noVueReservedProps | 禁止将保留名称用作 props。 | |
| noVueSetupPropsReactivityLoss | 禁止在 Vue 项目中解构传递给 setup 的 props。 | |
| useArraySortCompare | 要求 Array#sort 和 Array#toSorted 调用始终提供 compareFunction。 | |
| useAwaitThenable | 强制要求 await 仅用于 Promise 值。 | |
| useConsistentArrowReturn | 强制箭头函数体保持一致。 | |
| useDestructuring | 要求从数组和/或对象中解构赋值。 | |
| useExhaustiveSwitchCases | 要求 switch-case 语句必须穷尽所有情况。 | |
| useExplicitType | 强制在函数、方法、变量和参数中使用类型。 | |
| useFind | 强制使用 Array.prototype.find() 而不是 Array.prototype.filter() 后跟 [0] 来查找单个结果。 | |
| useMaxParams | 强制函数定义中参数的最大数量。 | |
| useQwikMethodUsage | 禁止在 Qwik 应用中使用 component$ 之外的 use* 钩子或其他 use* 钩子。 | |
| useQwikValidLexicalScope | 禁止在 Qwik 美元 ($) 作用域中使用不可序列化的表达式。 | |
| useRegexpExec | 如果未提供全局标志,则强制使用 RegExp#exec 而不是 String#match。 | |
| useSortedClasses | 强制对 CSS 实用程序类进行排序。 | |
| useSpread | 强制使用扩展运算符而不是 .apply()。 | |
| useVueDefineMacrosOrder | 强制要求 Vue 编译器宏的特定顺序。 | |
| useVueMultiWordComponentNames | 强制要求 Vue 组件使用多词组件名称。 |
performance
Section titled “performance”| 规则名称 | 描述 | 属性 |
|---|---|---|
| noAccumulatingSpread | 禁止在累加器上使用扩展 (...) 语法。 | |
| noAwaitInLoops | 禁止在循环中使用 await。 | |
| noBarrelFile | 禁止使用 barrel 文件。 | |
| noDelete | 禁止使用 delete 运算符。 | |
| noDynamicNamespaceImportAccess | 禁止动态访问命名空间导入。 | |
| noImgElement | 防止在 Next.js 项目中使用 <img> 元素。 | |
| noNamespaceImport | 禁止使用命名空间导入。 | |
| noReExportAll | 避免重新导出所有内容。 | |
| noUnwantedPolyfillio | 防止从 Polyfill.io 引入重复的 polyfill。 | |
| useGoogleFontPreconnect | 确保在使用 Google Fonts 时使用 preconnect 属性。 | |
| useSolidForComponent | 强制使用 Solid 的 <For /> 组件将数组映射到 JSX 元素。 | |
| useTopLevelRegex | 要求在顶层声明正则表达式文字。 |
security
Section titled “security”| 规则名称 | 描述 | 属性 |
|---|---|---|
| noBlankTarget | 禁止在没有 rel="noopener" 的情况下使用 target="_blank" 属性。 | |
| noDangerouslySetInnerHtml | 防止使用危险的 JSX props | |
| noDangerouslySetInnerHtmlWithChildren | 报告 DOM 元素或组件同时使用 children 和 dangerouslySetInnerHTML prop 的情况。 | |
| noGlobalEval | 禁止使用全局 eval()。 | |
| noSecrets | 禁止使用敏感数据,例如 API 密钥和令牌。 |
| 规则名称 | 描述 | 属性 |
|---|---|---|
| noCommonJs | 禁止使用 CommonJs 模块系统,转而使用 ESM 样式导入。 | |
| noDefaultExport | 禁止默认导出。 | |
| noDoneCallback | 禁止在异步测试和钩子中使用回调。 | |
| noEnum | 禁止 TypeScript 枚举。 | |
| noExportedImports | 禁止导出导入的变量。 | |
| noHeadElement | 防止在 Next.js 项目中使用 <head> 元素。 | |
| noImplicitBoolean | 禁止在 JSX 布尔属性上允许隐式 true 值 | |
| noInferrableTypes | 禁止使用文字表达式初始化的变量、参数和类属性的类型注释。 | |
| noMagicNumbers | 报告 “魔数” 的使用情况 - 直接使用数字,而不是将其赋值给命名常量。 | |
| noNamespace | 禁止使用 TypeScript 的 namespace。 | |
| noNegationElse | 如果 if 语句有 else 子句,则禁止在 if 语句的条件中使用否定。 | |
| noNestedTernary | 禁止使用嵌套的三元表达式。 | |
| noNonNullAssertion | 禁止使用 ! 后缀运算符进行非空断言。 | |
| noParameterAssign | 禁止重新分配 function 参数。 | |
| noParameterProperties | 禁止在类构造函数中使用参数属性。 | |
| noProcessEnv | 禁止使用 process.env。 | |
| noRestrictedGlobals | 此规则允许你指定不想在应用中使用的全局变量名称。 | |
| noRestrictedImports | 当通过 import 或 require 加载时,禁止指定模块。 | |
| noRestrictedTypes | 禁止用户定义的类型。 | |
| noShoutyConstants | 禁止使用其值为名称大写版本的常量。 | |
| noSubstr | 强制使用 String.slice() 而不是 String.substr() 和 String.substring()。 | |
| noUnusedTemplateLiteral | 如果不需要插值和特殊字符处理,则禁止使用模板文字 | |
| noUselessElse | 当 if 块提前中断时禁止 else 块。 | |
| noYodaExpression | 禁止使用 yoda 表达式。 | |
| useArrayLiterals | 禁止数组构造函数。 | |
| useAsConstAssertion | 强制使用 as const 而不是文字类型和类型注释。 | |
| useAtIndex | 使用 at() 代替整数索引访问。 | |
| useBlockStatements | 要求遵循大括号约定。 | |
| useCollapsedElseIf | 强制使用 else if 而不是嵌套在 else 子句中的 if。 | |
| useCollapsedIf | 强制使用单个 if 子句而不是嵌套的 if 子句。 | |
| useComponentExportOnlyModules | 强制仅在仅导出 React Components 的模块中声明组件。 | |
| useConsistentArrayType | 要求一致使用 T[] 或 Array<T> | |
| useConsistentBuiltinInstantiation | 强制所有内置命令使用 new,String、Number 和 Boolean 除外。 | |
| useConsistentCurlyBraces | 此规则强制在 JSX 属性和 JSX 子项内一致使用大括号。 | |
| useConsistentMemberAccessibility | 要求在类属性和方法上使用一致的可访问性修饰符。 | |
| useConsistentObjectDefinitions | 要求对象字面量声明方式一致。默认使用显式定义。 | |
| useConsistentTypeDefinitions | 强制类型定义始终使用 interface 或 type。 | |
| useConst | 要求仅分配一次的变量进行 const 声明。 | |
| useDefaultParameterLast | 强制 switch 语句中的默认子句位于最后 | |
| useDefaultSwitchClause | 要求 switch 语句中有 default 子句。 | |
| useEnumInitializers | 要求每个枚举成员值都明确初始化。 | |
| useExplicitLengthCheck | 强制显式 length 属性与元素上的隐式/默认角色属性不同。 | |
| useExponentiationOperator | 禁止使用 Math.pow,而使用 ** 运算符。 | |
| useExportType | 提倡使用 export type 作为类型。 | |
| useExportsLast | 要求所有导出语句必须在所有非导出语句之后声明。 | |
| useFilenamingConvention | 强制相对导入的文件扩展名。 | |
| useForOf | 尽可能优先使用 for...of 循环而不是标准的 for 循环。 | |
| useFragmentSyntax | 此规则强制使用 <>...</> 而不是 <Fragment>...</Fragment>。 | |
| useGroupedAccessorPairs | 强制要求在类和对象定义中,同一属性的 getter 和 setter 必须相邻。 | |
| useImportType | 提倡使用 import type 作为类型。 | |
| useLiteralEnumMembers | 要求所有枚举成员都是文字值。 | |
| useNamingConvention | 强制 JavaScript 和 TypeScript 文件名的命名约定。 | |
| useNodeAssertStrict | 提倡使用 node:assert/strict 而不是 node:assert。 | |
| useNodejsImportProtocol | 强制使用 node: 协议来处理 Node.js 内置模块。 | |
| useNumberNamespace | 使用 Number 属性而不是全局属性。 | |
| useNumericSeparators | 强制在数值字面量中使用数字分隔符。 | |
| useObjectSpread | 构建新对象时,优先使用 Object.assign() 对象展开。 | |
| useReactFunctionComponents | 强制要求组件定义为函数,而不能定义为类。 | |
| useReadonlyClassProperties | 强制要求将成员标记为 readonly,前提是成员在构造函数之外从未被修改。 | |
| useSelfClosingElements | 防止为没有子元素的组件添加额外的闭合标签。 | |
| useShorthandAssign | 尽可能要求赋值运算符简写。 | |
| useShorthandFunctionType | 强制使用函数类型而不是带有调用签名的对象类型。 | |
| useSingleVarDeclarator | 禁止在同一个变量语句中声明多个变量 | |
| useSymbolDescription | 要求 Symbol() 指令包含描述参数。 | |
| useTemplate | 首选模板文字而不是字符串连接。 | |
| useThrowNewError | 抛出错误时需要 new。 | |
| useThrowOnlyError | 禁止抛出非 Error 值。 | |
| useTrimStartEnd | 强制使用 String.trimStart() 和 String.trimEnd() 而不是 String.trimLeft() 和 String.trimRight()。 | |
| useUnifiedTypeSignatures | 禁止使用可以合并为单个签名的重载签名。 |
suspicious
Section titled “suspicious”| 规则名称 | 描述 | 属性 |
|---|---|---|
| noAlert | 禁止使用 alert、confirm 和 prompt。 | |
| noApproximativeNumericConstant | 使用标准常量而不是近似文字。 | |
| noArrayIndexKey | 不鼓励在键中使用数组索引。 | |
| noAssignInExpressions | 禁止表达式中的赋值。 | |
| noAsyncPromiseExecutor | 禁止使用异步函数作为 Promise 执行器。 | |
| noBitwiseOperators | 禁止使用位运算符。 | |
| noCatchAssign | 禁止在 catch 子句中重新分配异常。 | |
| noClassAssign | 禁止重新分配类成员。 | |
| noCommentText | 防止注释作为文本节点插入 | |
| noCompareNegZero | 禁止与 -0 进行比较 | |
| noConfusingLabels | 禁止非循环的标记语句。 | |
| noConfusingVoidType | 禁止在通用或返回类型之外使用 void 类型。 | |
| noConsole | 禁止使用 console。 | |
| noConstEnum | 禁止 TypeScript const enum | |
| noConstantBinaryExpressions | 禁止使用操作不影响值的表达式。 | |
| noControlCharactersInRegex | 防止正则表达式字面量中包含控制字符和某些与控制字符匹配的转义序列。 | |
| noDebugger | 禁止使用 debugger | |
| noDocumentCookie | 禁止直接向 document.cookie 赋值。 | |
| noDocumentImportInPage | 防止在 Next.js 项目中从 pages/_document.jsx 之外导入 next/document。 | |
| noDoubleEquals | 需要使用 === 和 !==。 | |
| noDuplicateCase | 禁止重复的案例标签。 | |
| noDuplicateClassMembers | 禁止重复的类成员。 | |
| noDuplicateElseIf | 禁止 if-else-if 链中的重复条件 | |
| noDuplicateJsxProps | 防止多次分配 JSX 属性。 | |
| noDuplicateObjectKeys | 禁止在对象内部使用两个同名的键。 | |
| noDuplicateParameters | 禁止重复的函数参数名称。 | |
| noDuplicateTestHooks | describe 块不应包含重复的钩子。 | |
| noEmptyBlockStatements | 禁止空块语句和静态块。 | |
| noEmptyInterface | 禁止声明空接口。 | |
| noEvolvingTypes | 禁止变量通过重新分配演变为 any 类型。 | |
| noExplicitAny | 禁止使用 any 类型。 | |
| noExportsInTest | 禁止在包含测试的文件中 使用 export 或 module.exports | |
| noExtraNonNullAssertion | 防止在 TypeScript 文件中错误使用非空断言运算符 (!)。 | |
| noFallthroughSwitchClause | 禁止 switch 子句的 fallthrough。 | |
| noFocusedTests | 禁止重点测试。 | |
| noFunctionAssign | 禁止重新分配函数声明。 | |
| noGlobalAssign | 禁止分配给原生对象和只读全局变量。 | |
| noGlobalIsFinite | 使用 Number.isFinite 而不是全局 isFinite。 | |
| noGlobalIsNan | 使用 Number.isNaN 而不是全局 isNaN。 | |
| noHeadImportInDocument | 防止在 Next.js 项目中使用 pages/_document.js 中的 next/head 模块。 | |
| noImplicitAnyLet | 禁止在变量声明中使用隐式 any 类型。 | |
| noImportAssign | 禁止分配给导入的绑定 | |
| noIrregularWhitespace | 禁止使用不规则的空格字符。 | |
| noLabelVar | 禁止与变量共享名称的标签 | |
| noMisleadingCharacterClass | 禁止在字符类语法中使用多个代码点构成的字符。 | |
| noMisleadingInstantiator | 强制在创建内置错误时传递消息值。 | |
| noMisplacedAssertion | 检查正则表达式是否是简单参数时,检查 unicode 宽度而不是字节数。 | |
| noMisrefactoredShorthandAssign | 当变量出现在两侧时,禁止简写赋值。 | |
| noNonNullAssertedOptionalChain | 禁止在可选链式表达式后使用非空断言。 | |
| noOctalEscape | 禁止在字符串字面量中使用八进制转义序列 | |
| noPrototypeBuiltins | 禁止直接使用 Object.prototype 内置函数。 | |
| noReactSpecificProps | 防止使用 React 特定的 JSX 属性。 | |
| noRedeclare | 禁止在同一范围内重新声明变量、函数、类和类型。 | |
| noRedundantUseStrict | 防止有多余的 "use strict"。 | |
| noSelfCompare | 禁止在双方完全相同的情况下进行比较。 | |
| noShadowRestrictedNames | 禁止标识符隐藏受限名称。 | |
| noSkippedTests | 禁止禁用测试。 | |
| noSparseArray | 防止使用稀疏数组(带空位的数组)。 | |
| noSuspiciousSemicolonInJsx | 它检测 JSX 元素内可能的 “wrong” 分号。 | |
| noTemplateCurlyInString | 禁止在普通字符串中使用模板字面量占位符语法。 | |
| noThenProperty | 禁止 then 属性。 | |
| noTsIgnore | 防止使用 TypeScript 指令 @ts-ignore。 | |
| noUnassignedVariables | 禁止读取但从未赋值的 let 或 var 变量。 | |
| noUnsafeDeclarationMerging | 禁止接口和类之间不安全的声明合并。 | |
| noUnsafeNegation | 禁止使用不安全的否定。 | |
| noUselessEscapeInString | 禁止在字符串字面量中使用不必要的转义。 | |
| noUselessRegexBackrefs | 禁止在正则表达式字面量中使用始终匹配空字符串的无用反向引用。 | |
| noVar | 禁止使用 var | |
| noWith | 禁止在非严格上下文中使用 with 语句。 | |
| useAdjacentOverloadSignatures | 禁止使用不相邻的过载签名。 | |
| useAwait | 确保 async 函数使用 await。 | |
| useDefaultSwitchClauseLast | 强制原始类型的一致名称 | |
| useErrorMessage | 强制 onClick 至少伴随以下之一: | |
| useGetterReturn | 强制 get 方法始终返回一个值。 | |
| useGoogleFontDisplay | 强制 Google Fonts 使用推荐的 display 策略。 | |
| useGuardForIn | 要求 for-in 循环包含 if 语句。 | |
| useIsArray | 使用 Array.isArray() 而不是 instanceof Array。 | |
| useIterableCallbackReturn | 强制可迭代回调函数返回值保持一致。 | |
| useNamespaceKeyword | 要求使用 namespace 关键字而不是 module 关键字来声明 TypeScript 命名空间。 | |
| useNumberToFixedDigitsArgument | 强制使用带有 Number#toFixed() 的数字参数。 | |
| useStaticResponseMethods | 尽可能使用静态 Response 方法而不是 new Response() 构造函数。 | |
| useStrictMode | 强制在脚本文件中使用指令 "use strict"。 |
¥Recommended rules
-
noAccessKey(严重性:error)
¥noAccessKey (Severity: error)
-
noAriaHiddenOnFocusable(严重性:error)
¥noAriaHiddenOnFocusable (Severity: error)
-
noAriaUnsupportedElements(严重性:error)
¥noAriaUnsupportedElements (Severity: error)
-
noAutofocus(严重性:error)
¥noAutofocus (Severity: error)
-
noDistractingElements(严重性:error)
¥noDistractingElements (Severity: error)
-
noHeaderScope(严重性:error)
¥noHeaderScope (Severity: error)
-
noInteractiveElementToNoninteractiveRole(严重性:error)
¥noInteractiveElementToNoninteractiveRole (Severity: error)
-
noLabelWithoutControl(严重性:error)
¥noLabelWithoutControl (Severity: error)
-
noNoninteractiveElementToInteractiveRole(严重性:error)
¥noNoninteractiveElementToInteractiveRole (Severity: error)
-
noNoninteractiveTabindex(严重性:error)
¥noNoninteractiveTabindex (Severity: error)
-
noPositiveTabindex(严重性:error)
¥noPositiveTabindex (Severity: error)
-
noRedundantAlt(严重性:error)
¥noRedundantAlt (Severity: error)
-
noRedundantRoles(严重性:error)
¥noRedundantRoles (Severity: error)
-
noStaticElementInteractions(严重性:error)
¥noStaticElementInteractions (Severity: error)
-
noSvgWithoutTitle(严重性:error)
¥noSvgWithoutTitle (Severity: error)
-
useAltText(严重性:error)
¥useAltText (Severity: error)
-
useAnchorContent(严重性:error)
¥useAnchorContent (Severity: error)
-
useAriaActivedescendantWithTabindex(严重性:error)
¥useAriaActivedescendantWithTabindex (Severity: error)
-
useAriaPropsForRole(严重性:error)
¥useAriaPropsForRole (Severity: error)
-
useAriaPropsSupportedByRole(严重性:error)
¥useAriaPropsSupportedByRole (Severity: error)
-
useButtonType(严重性:error)
¥useButtonType (Severity: error)
-
useFocusableInteractive(严重性:error)
¥useFocusableInteractive (Severity: error)
-
useHeadingContent(严重性:error)
¥useHeadingContent (Severity: error)
-
useHtmlLang(严重性:error)
¥useHtmlLang (Severity: error)
-
useIframeTitle(严重性:error)
¥useIframeTitle (Severity: error)
-
useKeyWithClickEvents(严重性:error)
¥useKeyWithClickEvents (Severity: error)
-
useKeyWithMouseEvents(严重性:error)
¥useKeyWithMouseEvents (Severity: error)
-
useMediaCaption(严重性:error)
¥useMediaCaption (Severity: error)
-
useSemanticElements(严重性:error)
¥useSemanticElements (Severity: error)
-
useValidAnchor(严重性:error)
¥useValidAnchor (Severity: error)
-
useValidAriaProps(严重性:error)
¥useValidAriaProps (Severity: error)
-
useValidAriaRole(严重性:error)
¥useValidAriaRole (Severity: error)
-
useValidAriaValues(严重性:error)
¥useValidAriaValues (Severity: error)
-
useValidAutocomplete(严重性:error)
¥useValidAutocomplete (Severity: error)
-
useValidLang(严重性:error)
¥useValidLang (Severity: error)
-
noAdjacentSpacesInRegex(严重性:warning)
¥noAdjacentSpacesInRegex (Severity: warning)
-
noArguments(严重性:warning)
¥noArguments (Severity: warning)
-
noBannedTypes(严重性:warning)
¥noBannedTypes (Severity: warning)
-
noCommaOperator(严重性:warning)
¥noCommaOperator (Severity: warning)
-
noEmptyTypeParameters(严重性:warning)
¥noEmptyTypeParameters (Severity: warning)
-
noExtraBooleanCast(严重性:information)
¥noExtraBooleanCast (Severity: information)
-
noFlatMapIdentity(严重性:information)
¥noFlatMapIdentity (Severity: information)
-
noStaticOnlyClass(严重性:warning)
¥noStaticOnlyClass (Severity: warning)
-
noThisInStatic(严重性:warning)
¥noThisInStatic (Severity: warning)
-
noUselessCatch(严重性:information)
¥noUselessCatch (Severity: information)
-
noUselessConstructor(严重性:information)
¥noUselessConstructor (Severity: information)
-
noUselessContinue(严重性:information)
¥noUselessContinue (Severity: information)
-
noUselessEmptyExport(严重性:information)
¥noUselessEmptyExport (Severity: information)
-
noUselessEscapeInRegex(严重性:information)
¥noUselessEscapeInRegex (Severity: information)
-
noUselessFragments(严重性:information)
¥noUselessFragments (Severity: information)
-
noUselessLabel(严重性:information)
¥noUselessLabel (Severity: information)
-
noUselessLoneBlockStatements(严重性:information)
¥noUselessLoneBlockStatements (Severity: information)
-
noUselessRename(严重性:information)
¥noUselessRename (Severity: information)
-
noUselessStringRaw(严重性:information)
¥noUselessStringRaw (Severity: information)
-
noUselessSwitchCase(严重性:information)
¥noUselessSwitchCase (Severity: information)
-
noUselessTernary(严重性:information)
¥noUselessTernary (Severity: information)
-
noUselessThisAlias(严重性:information)
¥noUselessThisAlias (Severity: information)
-
noUselessTypeConstraint(严重性:information)
¥noUselessTypeConstraint (Severity: information)
-
noUselessUndefinedInitialization(严重性:information)
¥noUselessUndefinedInitialization (Severity: information)
-
useArrowFunction(严重性:warning)
¥useArrowFunction (Severity: warning)
-
useDateNow(严重性:warning)
¥useDateNow (Severity: warning)
-
useFlatMap(严重性:information)
¥useFlatMap (Severity: information)
-
useIndexOf(严重性:information)
¥useIndexOf (Severity: information)
-
useLiteralKeys(严重性:information)
¥useLiteralKeys (Severity: information)
-
useNumericLiterals(严重性:warning)
¥useNumericLiterals (Severity: warning)
-
useOptionalChain(严重性:warning)
¥useOptionalChain (Severity: warning)
-
useRegexLiterals(严重性:warning)
¥useRegexLiterals (Severity: warning)
-
useSimpleNumberKeys(严重性:warning)
¥useSimpleNumberKeys (Severity: warning)
-
noConstAssign(严重性:error)
¥noConstAssign (Severity: error)
-
noConstantCondition(严重性:error)
¥noConstantCondition (Severity: error)
-
noConstantMathMinMaxClamp(严重性:error)
¥noConstantMathMinMaxClamp (Severity: error)
-
noConstructorReturn(严重性:error)
¥noConstructorReturn (Severity: error)
-
noEmptyCharacterClassInRegex(严重性:error)
¥noEmptyCharacterClassInRegex (Severity: error)
-
noEmptyPattern(严重性:error)
¥noEmptyPattern (Severity: error)
-
noGlobalObjectCalls(严重性:error)
¥noGlobalObjectCalls (Severity: error)
-
noInnerDeclarations(严重性:error)
¥noInnerDeclarations (Severity: error)
-
noInvalidBuiltinInstantiation(严重性:error)
¥noInvalidBuiltinInstantiation (Severity: error)
-
noInvalidConstructorSuper(严重性:error)
¥noInvalidConstructorSuper (Severity: error)
-
noInvalidUseBeforeDeclaration(严重性:error)
¥noInvalidUseBeforeDeclaration (Severity: error)
-
noNonoctalDecimalEscape(严重性:error)
¥noNonoctalDecimalEscape (Severity: error)
-
noPrecisionLoss(严重性:error)
¥noPrecisionLoss (Severity: error)
-
noSelfAssign(严重性:error)
¥noSelfAssign (Severity: error)
-
noSetterReturn(严重性:error)
¥noSetterReturn (Severity: error)
-
noStringCaseMismatch(严重性:error)
¥noStringCaseMismatch (Severity: error)
-
noSwitchDeclarations(严重性:error)
¥noSwitchDeclarations (Severity: error)
-
noUnreachable(严重性:error)
¥noUnreachable (Severity: error)
-
noUnreachableSuper(严重性:error)
¥noUnreachableSuper (Severity: error)
-
noUnsafeFinally(严重性:error)
¥noUnsafeFinally (Severity: error)
-
noUnsafeOptionalChaining(严重性:error)
¥noUnsafeOptionalChaining (Severity: error)
-
noUnusedFunctionParameters(严重性:warning)
¥noUnusedFunctionParameters (Severity: warning)
-
noUnusedImports(严重性:warning)
¥noUnusedImports (Severity: warning)
-
noUnusedLabels(严重性:warning)
¥noUnusedLabels (Severity: warning)
-
noUnusedPrivateClassMembers(严重性:warning)
¥noUnusedPrivateClassMembers (Severity: warning)
-
noUnusedVariables(严重性:warning)
¥noUnusedVariables (Severity: warning)
-
noVoidElementsWithChildren(严重性:error)
¥noVoidElementsWithChildren (Severity: error)
-
noVoidTypeReturn(严重性:error)
¥noVoidTypeReturn (Severity: error)
-
useParseIntRadix(严重性:information)
¥useParseIntRadix (Severity: information)
-
useValidForDirection(严重性:error)
¥useValidForDirection (Severity: error)
-
useValidTypeof(严重性:error)
¥useValidTypeof (Severity: error)
-
noAccumulatingSpread(严重性:warning)
¥noAccumulatingSpread (Severity: warning)
-
noDynamicNamespaceImportAccess(严重性:warning)
¥noDynamicNamespaceImportAccess (Severity: warning)
-
noBlankTarget(严重性:error)
¥noBlankTarget (Severity: error)
-
noGlobalEval(严重性:error)
¥noGlobalEval (Severity: error)
-
noNonNullAssertion(严重性:warning)
¥noNonNullAssertion (Severity: warning)
-
useArrayLiterals(严重性:information)
¥useArrayLiterals (Severity: information)
-
useExponentiationOperator(严重性:information)
¥useExponentiationOperator (Severity: information)
-
useExportType(严重性:warning)
¥useExportType (Severity: warning)
-
useImportType(严重性:warning)
¥useImportType (Severity: warning)
-
useLiteralEnumMembers(严重性:warning)
¥useLiteralEnumMembers (Severity: warning)
-
useNodejsImportProtocol(严重性:information)
¥useNodejsImportProtocol (Severity: information)
-
useShorthandFunctionType(严重性:information)
¥useShorthandFunctionType (Severity: information)
-
useTemplate(严重性:information)
¥useTemplate (Severity: information)
-
noApproximativeNumericConstant(严重性:warning)
¥noApproximativeNumericConstant (Severity: warning)
-
noAssignInExpressions(严重性:error)
¥noAssignInExpressions (Severity: error)
-
noAsyncPromiseExecutor(严重性:error)
¥noAsyncPromiseExecutor (Severity: error)
-
noCatchAssign(严重性:warning)
¥noCatchAssign (Severity: warning)
-
noClassAssign(严重性:error)
¥noClassAssign (Severity: error)
-
noCommentText(严重性:error)
¥noCommentText (Severity: error)
-
noCompareNegZero(严重性:error)
¥noCompareNegZero (Severity: error)
-
noConfusingLabels(严重性:warning)
¥noConfusingLabels (Severity: warning)
-
noConfusingVoidType(严重性:warning)
¥noConfusingVoidType (Severity: warning)
-
noConstEnum(严重性:warning)
¥noConstEnum (Severity: warning)
-
noControlCharactersInRegex(严重性:error)
¥noControlCharactersInRegex (Severity: error)
-
noDebugger(严重性:error)
¥noDebugger (Severity: error)
-
noDocumentCookie(严重性:warning)
¥noDocumentCookie (Severity: warning)
-
noDoubleEquals(严重性:error)
¥noDoubleEquals (Severity: error)
-
noDuplicateCase(严重性:error)
¥noDuplicateCase (Severity: error)
-
noDuplicateClassMembers(严重性:error)
¥noDuplicateClassMembers (Severity: error)
-
noDuplicateElseIf(严重性:error)
¥noDuplicateElseIf (Severity: error)
-
noDuplicateJsxProps(严重性:error)
¥noDuplicateJsxProps (Severity: error)
-
noDuplicateObjectKeys(严重性:error)
¥noDuplicateObjectKeys (Severity: error)
-
noDuplicateParameters(严重性:error)
¥noDuplicateParameters (Severity: error)
-
noEmptyInterface(严重性:error)
¥noEmptyInterface (Severity: error)
-
noExplicitAny(严重性:warning)
¥noExplicitAny (Severity: warning)
-
noExtraNonNullAssertion(严重性:warning)
¥noExtraNonNullAssertion (Severity: warning)
-
noFallthroughSwitchClause(严重性:error)
¥noFallthroughSwitchClause (Severity: error)
-
noFunctionAssign(严重性:error)
¥noFunctionAssign (Severity: error)
-
noGlobalAssign(严重性:error)
¥noGlobalAssign (Severity: error)
-
noGlobalIsFinite(严重性:warning)
¥noGlobalIsFinite (Severity: warning)
-
noGlobalIsNan(严重性:warning)
¥noGlobalIsNan (Severity: warning)
-
noImplicitAnyLet(严重性:error)
¥noImplicitAnyLet (Severity: error)
-
noImportAssign(严重性:error)
¥noImportAssign (Severity: error)
-
noIrregularWhitespace(严重性:warning)
¥noIrregularWhitespace (Severity: warning)
-
noLabelVar(严重性:error)
¥noLabelVar (Severity: error)
-
noMisleadingCharacterClass(严重性:error)
¥noMisleadingCharacterClass (Severity: error)
-
noMisleadingInstantiator(严重性:error)
¥noMisleadingInstantiator (Severity: error)
-
noMisrefactoredShorthandAssign(严重性:error)
¥noMisrefactoredShorthandAssign (Severity: error)
-
noNonNullAssertedOptionalChain(严重性:error)
¥noNonNullAssertedOptionalChain (Severity: error)
-
noOctalEscape(严重性:warning)
¥noOctalEscape (Severity: warning)
-
noPrototypeBuiltins(严重性:warning)
¥noPrototypeBuiltins (Severity: warning)
-
noRedeclare(严重性:error)
¥noRedeclare (Severity: error)
-
noRedundantUseStrict(严重性:warning)
¥noRedundantUseStrict (Severity: warning)
-
noSelfCompare(严重性:error)
¥noSelfCompare (Severity: error)
-
noShadowRestrictedNames(严重性:error)
¥noShadowRestrictedNames (Severity: error)
-
noSparseArray(严重性:error)
¥noSparseArray (Severity: error)
-
noSuspiciousSemicolonInJsx(严重性:warning)
¥noSuspiciousSemicolonInJsx (Severity: warning)
-
noTemplateCurlyInString(严重性:warning)
¥noTemplateCurlyInString (Severity: warning)
-
noThenProperty(严重性:error)
¥noThenProperty (Severity: error)
-
noTsIgnore(严重性:warning)
¥noTsIgnore (Severity: warning)
-
noUnsafeDeclarationMerging(严重性:error)
¥noUnsafeDeclarationMerging (Severity: error)
-
noUnsafeNegation(严重性:error)
¥noUnsafeNegation (Severity: error)
-
noUselessEscapeInString(严重性:warning)
¥noUselessEscapeInString (Severity: warning)
-
noUselessRegexBackrefs(严重性:warning)
¥noUselessRegexBackrefs (Severity: warning)
-
useAdjacentOverloadSignatures(严重性:warning)
¥useAdjacentOverloadSignatures (Severity: warning)
-
useDefaultSwitchClauseLast(严重性:warning)
¥useDefaultSwitchClauseLast (Severity: warning)
-
useGetterReturn(严重性:error)
¥useGetterReturn (Severity: error)
-
useGoogleFontDisplay(严重性:warning)
¥useGoogleFontDisplay (Severity: warning)
-
useIsArray(严重性:warning)
¥useIsArray (Severity: warning)
-
useIterableCallbackReturn(严重性:error)
¥useIterableCallbackReturn (Severity: error)
-
useNamespaceKeyword(严重性:error)
¥useNamespaceKeyword (Severity: error)
缺少规则?请通过 contributing 至 analyzer 或创建规则建议 此处 来帮助我们。
¥Missing a rule? Help us by contributing to the analyzer or create a rule suggestion here.
Biome v2.1 中文网 - 粤ICP备13048890号