noWith
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
¥Diagnostic Category:
lint/suspicious/noWith -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "suspicious": { "noWith": "error" } } }}¥Description
禁止在非严格上下文中使用 with 语句。
¥Disallow with statements in non-strict contexts.
with 语句可能会出现问题,因为它会将对象的成员添加到当前范围,从而无法判断块内的变量实际上指的是什么。
¥The with statement is potentially problematic because it adds members of an object to the current
scope, making it impossible to tell what a variable inside the block actually refers to.
¥Examples
¥Invalid
function f() { with (point) { r = Math.sqrt(x * x + y * y); // is r a member of point? }}code-block.cjs:2:3 lint/suspicious/noWith ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ Unexpected use of with statement.
1 │ function f() {
> 2 │ with (point) {
│ ^^^^^^^^^^^^^^
> 3 │ r = Math.sqrt(x * x + y * y); // is r a member of point?
> 4 │ }
│ ^
5 │ }
6 │
ℹ The with statement is potentially problematic because it adds members of an object to the current
scope, making it impossible to tell what a variable inside the block actually refers to.
¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号