noProcessGlobal
¥Summary
-
规则生效日期:
v2.0.0¥Rule available since:
v2.0.0 -
诊断类别:
lint/correctness/noProcessGlobal¥Diagnostic Category:
lint/correctness/noProcessGlobal -
此规则包含 safe 修复程序。
¥This rule has a safe fix.
-
此规则的默认严重级别为 information。
¥The default severity of this rule is information.
-
来源:
¥Sources:
-
与
no-process-global相同¥Same as
no-process-global
-
¥How to configure
{ "linter": { "rules": { "correctness": { "noProcessGlobal": "error" } } }}¥Description
禁止使用全局变量 process。
¥Disallow the use of process global.
Node.js 和 Deno 会公开全局 process,但工具很难对其进行静态分析,因此代码不应假定它们可用。使用 import process from "node:process"。
¥Node.js and Deno expose process global but they are hard to statically analyze by tools,
so code should not assume they are available. Instead, import process from "node:process".
¥Examples
¥Invalid
const foo = process.env.FOO;code-block.js:1:13 lint/correctness/noProcessGlobal FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
ℹ Usage of the `process` global is discouraged.
> 1 │ const foo = process.env.FOO;
│ ^^^^^^^
2 │
ℹ `process` global is hard for tools to statically analyze, so code should not assume they are available.
ℹ Safe fix: Add `import process from “node:process”;` to this file’s imports.
1 │ + import·process·from·“node:process”;
1 2 │ const foo = process.env.FOO;
2 3 │
¥Valid
import process from "node:process";
const foo = process.env.FOO;该规则无法检测全局对象被别名的情况:
¥The rule is not able to detect cases where the global object is aliased:
const foo = globalThis;const bar = foo.process;¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号