noGlobalAssign
¥Summary
-
规则生效日期:
v1.5.0¥Rule available since:
v1.5.0 -
诊断类别:
lint/suspicious/noGlobalAssign¥Diagnostic Category:
lint/suspicious/noGlobalAssign -
此规则为推荐规则,默认启用。
¥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:
-
与
no-global-assign相同¥Same as
no-global-assign
-
¥How to configure
{ "linter": { "rules": { "suspicious": { "noGlobalAssign": "error" } } }}¥Description
禁止分配给原生对象和只读全局变量。
¥Disallow assignments to native objects and read-only global variables.
JavaScript 的环境包含许多内置的全局变量,例如浏览器中的 window 和 Node.js 中的 process。为这些全局变量赋值可能会出现问题,因为它可能会覆盖基本功能。
¥JavaScript’s environments contain numerous built-in global variables, such as window in browsers and process in Node.js.
Assigning values to these global variables can be problematic as it can override essential functionality.
¥Examples
¥Invalid
Object = null;code-block.js:1:1 lint/suspicious/noGlobalAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ A global variable should not be reassigned.
> 1 │ Object = null;
│ ^^^^^^
2 │
ℹ Assigning to a global variable can override essential functionality.
window = {};code-block.js:1:1 lint/suspicious/noGlobalAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ A global variable should not be reassigned.
> 1 │ window = {};
│ ^^^^^^
2 │
ℹ Assigning to a global variable can override essential functionality.
undefined = true;code-block.js:1:1 lint/suspicious/noGlobalAssign ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ A global variable should not be reassigned.
> 1 │ undefined = true;
│ ^^^^^^^^^
2 │
ℹ Assigning to a global variable can override essential functionality.
¥Valid
a = 0;let window;window = {};¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号