noVar
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
¥Diagnostic Category:
lint/suspicious/noVar -
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "suspicious": { "noVar": "error" } } }}¥Description
禁止使用 var
¥Disallow the use of var
ECMAScript 6 允许程序员使用 let 和 const 关键字创建具有块作用域而不是函数作用域的变量。
¥ECMAScript 6 allows programmers to create variables with block scope instead of function scope using the let and const keywords.
块范围在许多其他编程语言中很常见,可辅助程序员避免错误。
¥Block scope is common in many other programming languages and helps programmers avoid mistakes.
¥Examples
¥Invalid
var foo = 1;code-block.js:1:1 lint/suspicious/noVar FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Use let or const instead of var.
> 1 │ var foo = 1;
│ ^^^^^^^^^^^
2 │
ℹ A variable declared with var is accessible in the whole module. Thus, the variable can be accessed before its initialization and outside the block where it is declared.
ℹ See MDN web docs for more details.
ℹ Unsafe fix: Use ‘const’ instead.
1 │ - var·foo·=·1;
1 │ + const·foo·=·1;
2 2 │
¥Valid
const foo = 1;let bar = 1;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号