规则列表
这些 lint 规则由 deno lint
命令提供。您可以通过将它们的标签(例如 recommended
、react
)添加到 lint.rules.tags
数组中,在 deno.json(c)
中启用规则集。
如果未提供标签,则默认启用 recommended
规则集。
推荐
Fresh
JSX
React
JSR
要求重载签名彼此相邻。详情 about undefined
禁止在没有注释的情况下使用 Typescript 指令。详情 about undefined
禁止使用原始包装对象(例如对象
String
是原始类型string
的包装器),以及非显式的Function
类型和被误解的Object
类型。详情 about undefined警告在忽略指令中使用未知规则代码。详情 about undefined
要求
deno-lint-ignore
至少使用一个规则名称进行标注。详情 about undefined要求 TODO 必须使用用户标签(
@user
)或问题引用(#issue
)进行标注。详情 about undefined警告未使用的忽略指令。详情 about undefined
检查
<button>
JSX 元素是否具有有效的type
属性。默认值是"submit"
,这通常不是期望的行为。详情 about undefined强制变量名使用 camelCase 命名法。详情 about undefined
验证构造函数和
super()
调用的正确使用。详情 about undefined强制默认参数在函数签名中位于最后。详情 about undefined
强制使用类型安全的相等运算符
===
和!==
,而不是更容易出错的==
和!=
运算符。详情 about undefined要求所有函数都具有显式的返回类型。详情 about undefined
要求所有模块导出都具有完整的类型声明。详情 about undefined
要求
for
循环控制变量以正确的方向递增。详情 about undefined检查具名 Fresh 中间件导出的正确命名。详情 about undefined
禁止在 Fresh 服务器组件中使用事件处理程序。详情 about undefined
要求所有属性 getter 函数都返回一个值。详情 about undefined
要求
for-in
循环包含if
语句。详情 about undefined强制一致的 JSX 布尔值样式。布尔值
true
可以使用简写语法省略。详情 about undefined强制
<button>
元素具有type
属性。如果<button>
放在<form>
元素内,它将默认作为提交按钮,这可能会出乎意料。详情 about undefined确保 JSX 表达式周围的大括号使用一致。详情 about undefined
在将可迭代对象传递给 JSX 时,确保存在
key
属性。它允许框架优化元素顺序的检查。详情 about undefined将子元素作为 JSX 子元素传递,而不是作为属性。详情 about undefined
文本节点内的 JavaScript 注释在 JSX 中会渲染为纯文本。这通常是出乎意料的。详情 about undefined
禁止重复的 JSX 属性。后面的属性总是会覆盖前面的属性,这通常会导致意外结果。详情 about undefined
在 JSX 中留下
>
或}
字符通常是不希望的,并且难以发现。强制这些字符必须作为字符串传递。详情 about undefined片段只在 JSX“块”的顶部有多个子元素时才需要。在其他情况下不需要片段。详情 about undefined
将相同的表达式展开两次通常是一个错误,并导致不必要的计算。详情 about undefined
确保 HTML 中的空元素没有子元素,因为那不是有效的 HTML。更多信息请参阅 MDN 上的
Void element
文章。详情 about undefined强制使用传统的数组构造方式。详情 about undefined
要求不使用异步 Promise 执行器函数。详情 about undefined
要求在 for 循环体中不使用
await
。详情 about undefined禁止在非异步函数中使用
await
关键字。详情 about undefined要求所有以任意数量的
boolean
字面量作为参数调用的函数,都使用自文档化的常量代替。详情 about undefined要求 switch
case
或default
子句中的词法声明(let
,const
,function
和class
)必须使用大括号进行作用域划分。详情 about undefined禁止修改类声明的变量。详情 about undefined
禁止与负零(
-0
)进行比较。详情 about undefined禁止在条件语句中使用赋值运算符
=
。详情 about undefined禁止使用
console
全局对象。详情 about undefined禁止修改声明为
const
的变量。详情 about undefined禁止在条件测试中使用常量表达式。详情 about undefined
禁止在正则表达式中使用 ASCII 控制字符。详情 about undefined
禁止使用
debugger
语句。详情 about undefined禁止删除变量。详情 about undefined
警告使用已废弃的 Deno API。详情 about undefined
禁止在函数签名中多次使用同一个参数名。详情 about undefined
禁止多次使用同一个类成员函数名。详情 about undefined
禁止在
if
/else if
语句中两次使用相同的条件。详情 about undefined禁止在对象字面量中出现重复的键。详情 about undefined
禁止在 switch 语句中多次使用相同的 case 子句。详情 about undefined
禁止使用空的代码块。详情 about undefined
禁止在正则表达式中使用空字符类。详情 about undefined
禁止声明空枚举。详情 about undefined
禁止声明空接口。详情 about undefined
禁止在解构中使用空模式。详情 about undefined
禁止使用
eval
。详情 about undefined禁止重新赋值异常参数。详情 about undefined
禁止使用
any
类型。详情 about undefined禁止使用外部导入。详情 about undefined
禁止不必要的布尔类型转换。详情 about undefined
禁止不必要的非空断言。详情 about undefined
禁止 case 语句的隐式穿透。详情 about undefined
禁止覆盖/重新赋值现有函数。详情 about undefined
禁止对原生 JavaScript 对象赋值。详情 about undefined
禁止在 ["ambient" 命名空间] 中使用隐式导出。详情 about undefined
禁止对导入属性使用
assert
关键字。详情 about undefined禁止重新赋值导入的模块绑定。详情 about undefined
禁止使用易于推断的类型。详情 about undefined
禁止在嵌套块中定义变量或函数。详情 about undefined
禁止在 RegExp 构造函数中指定无效的正则表达式。详情 about undefined
警告三斜杠引用指令的错误用法。详情 about undefined
禁止使用非空格或非制表符的空白字符。详情 about undefined
禁止为接口定义
constructor
或为类定义new
。详情 about undefined禁止在 TypeScript 代码中使用
namespace
和module
关键字。详情 about undefined禁止对内置
Symbol
使用new
运算符。详情 about undefined禁止使用 NodeJS 全局对象。详情 about undefined
禁止在可选链表达式后使用非空断言。详情 about undefined
禁止使用
!
后缀运算符进行非空断言。详情 about undefined禁止将内置全局对象作为函数调用。详情 about undefined
禁止通过以
0
开头的数字字面量表示八进制数。详情 about undefined禁止使用 NodeJS
process
全局对象。详情 about undefined禁止直接使用
Object.prototype
内置方法。详情 about undefined禁止重复声明同名的变量、函数和参数。详情 about undefined
禁止在正则表达式字面量中出现多个空格。详情 about undefined
禁止自我赋值。详情 about undefined
禁止两边完全相同的比较。详情 about undefined
禁止从 setter 中返回值。详情 about undefined
禁止遮蔽受限制的名称。详情 about undefined
强制在模块说明符中指定显式的路径引用。详情 about undefined
强制使用显式或可以简单推断的类型。详情 about undefined
禁止稀疏数组。详情 about undefined
禁止在异步函数内部使用同步函数。详情 about undefined
禁止将变量赋值给
this
。详情 about undefined禁止在构造函数中调用
super()
之前使用this
或super
。详情 about undefined禁止将字面量作为异常抛出。详情 about undefined
禁止使用顶层 await 表达式。详情 about undefined
禁止使用未声明的变量。详情 about undefined
禁止控制流语句后的不可达代码。详情 about undefined
禁止在
finally
块中使用控制流语句。详情 about undefined禁止将否定运算符
!
作为关系运算符的左操作数使用。详情 about undefined禁止未使用的标签。详情 about undefined
强制所有变量至少使用一次。详情 about undefined
禁止无用的重命名操作,即原始名称和新名称完全相同的情况。这通常是重构过程中的遗留物,可以安全移除。详情 about undefined
强制使用块级作用域变量,而不是更容易出错的函数级作用域变量。块级作用域变量使用
const
和let
关键字定义。详情 about undefined禁止使用
window
对象。详情 about undefined禁止通过
window
对象使用 Web API。详情 about undefined禁止使用
with
语句。详情 about undefined建议使用 const 断言(
as const
)而不是显式指定字面量类型或使用类型断言。详情 about undefined确保代码完全使用 ASCII 字符编写。详情 about undefined
建议使用 [
const
] 而不是 [let
] 声明变量。详情 about undefined建议在声明 TypeScript 模块时使用
namespace
关键字而不是module
关键字。详情 about undefined建议使用
primordials
中的冻结内置对象而不是默认的全局对象。详情 about undefined阻止使用
dangerouslySetInnerHTML
,如果使用不当,可能导致 XSS 漏洞。详情 about undefined将 JSX 子元素与
dangerouslySetInnerHTML
一起使用是无效的,因为它们将被忽略。详情 about undefined确保钩子在 React/Preact 组件中正确调用。它们必须在组件的顶层调用,而不能在条件语句或循环内部。详情 about undefined
禁止没有 await 表达式或 await using 声明的异步函数。详情 about undefined
禁止没有
yield
的生成器函数。详情 about undefined禁止在同一声明语句中定义多个变量。详情 about undefined
禁止使用某些三斜杠指令,而倾向于 ES6 风格的 import 声明。详情 about undefined
禁止与
NaN
进行比较。详情 about undefined将
typeof
运算符的使用限制为特定的字符串字面量集。详情 about undefined强制类型导入声明为类型导入。详情 about undefined