Skip to content

noProcessGlobal

¥Summary

¥How to configure

biome.json
{
"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