noUndeclaredVariables
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/correctness/noUndeclaredVariables¥Diagnostic Category:
lint/correctness/noUndeclaredVariables -
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "correctness": { "noUndeclaredVariables": "error" } } }}¥Description
防止使用文档中未声明的变量。
¥Prevents the usage of variables that haven’t been declared inside the document.
如果你需要允许列出某些全局绑定,则可以使用 javascript.globals 配置。
¥If you need to allow-list some global bindings, you can use the javascript.globals configuration.
¥Examples
¥Invalid
foobar;code-block.js:1:1 lint/correctness/noUndeclaredVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The foobar variable is undeclared.
> 1 │ foobar;
│ ^^^^^^
2 │
ℹ By default, Biome recognizes browser and Node.js globals.
You can ignore more globals using the javascript.globals configuration.
// throw diagnostic for JavaScript filesPromiseLike;code-block.js:2:1 lint/correctness/noUndeclaredVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The PromiseLike variable is undeclared.
1 │ // throw diagnostic for JavaScript files
> 2 │ PromiseLike;
│ ^^^^^^^^^^^
3 │
ℹ By default, Biome recognizes browser and Node.js globals.
You can ignore more globals using the javascript.globals configuration.
¥Valid
type B<T> = PromiseLike<T>¥Options
checkTypes
Section titled “checkTypes”设置为 true 时,它还会检查未声明的类型。该选项默认值为 false。
¥When set to true, it checks for undeclared types too.
The option defaults to false.
{ "linter": { "rules": { "correctness": { "noUndeclaredVariables": { "options": { "checkTypes": true } } } } }}type A = number extends infer T ? never : T;code-block.ts:1:43 lint/correctness/noUndeclaredVariables ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ The T variable is undeclared.
> 1 │ type A = number extends infer T ? never : T;
│ ^
2 │
ℹ By default, Biome recognizes browser and Node.js globals.
You can ignore more globals using the javascript.globals configuration.
¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号