noProcessGlobal
Summary
Section titled “Summary”- Rule available since:
v2.0.0
- Diagnostic Category:
lint/correctness/noProcessGlobal
- This rule has a safe fix.
- The default severity of this rule is information.
- Sources:
- Same as
deno-lint/no-process-global
- Same as
How to configure
Section titled “How to configure”{ "linter": { "rules": { "correctness": { "noProcessGlobal": "error" } } }}
Description
Section titled “Description”Disallow the use of process
global.
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
Section titled “Examples”Invalid
Section titled “Invalid”const foo = process.env.FOO;<pre class="language-text"><code class="language-text">code-block.js:1:13 <a href="https://biomejs.dev/linter/rules/no-process-global">lint/correctness/noProcessGlobal</a> <span style="color: #000; background-color: #ddd;"> FIXABLE </span> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━<br /><br /> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Usage of the `process` global is discouraged.</span><br /> <br /> <strong><span style="color: Tomato;">></span></strong> <strong>1 │ </strong>const foo = process.env.FOO;<br /> <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><br /> <strong>2 │ </strong><br /> <br /> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">`process` global is hard for tools to statically analyze, so code should not assume they are available.</span><br /> <br /> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Safe fix</span><span style="color: lightgreen;">: </span><span style="color: lightgreen;">Add `import process from "node:process";` to this file's imports.</span><br /> <br /> <strong>1</strong><strong> │ </strong><span style="color: MediumSeaGreen;">+</span> <span style="color: MediumSeaGreen;"><strong>i</strong></span><span style="color: MediumSeaGreen;"><strong>m</strong></span><span style="color: MediumSeaGreen;"><strong>p</strong></span><span style="color: MediumSeaGreen;"><strong>o</strong></span><span style="color: MediumSeaGreen;"><strong>r</strong></span><span style="color: MediumSeaGreen;"><strong>t</strong></span><span style="color: MediumSeaGreen;"><span style="opacity: 0.8;"><strong>·</strong></span></span><span style="color: MediumSeaGreen;"><strong>p</strong></span><span style="color: MediumSeaGreen;"><strong>r</strong></span><span style="color: MediumSeaGreen;"><strong>o</strong></span><span style="color: MediumSeaGreen;"><strong>c</strong></span><span style="color: MediumSeaGreen;"><strong>e</strong></span><span style="color: MediumSeaGreen;"><strong>s</strong></span><span style="color: MediumSeaGreen;"><strong>s</strong></span><span style="color: MediumSeaGreen;"><span style="opacity: 0.8;"><strong>·</strong></span></span><span style="color: MediumSeaGreen;"><strong>f</strong></span><span style="color: MediumSeaGreen;"><strong>r</strong></span><span style="color: MediumSeaGreen;"><strong>o</strong></span><span style="color: MediumSeaGreen;"><strong>m</strong></span><span style="color: MediumSeaGreen;"><span style="opacity: 0.8;"><strong>·</strong></span></span><span style="color: MediumSeaGreen;"><strong>"</strong></span><span style="color: MediumSeaGreen;"><strong>n</strong></span><span style="color: MediumSeaGreen;"><strong>o</strong></span><span style="color: MediumSeaGreen;"><strong>d</strong></span><span style="color: MediumSeaGreen;"><strong>e</strong></span><span style="color: MediumSeaGreen;"><strong>:</strong></span><span style="color: MediumSeaGreen;"><strong>p</strong></span><span style="color: MediumSeaGreen;"><strong>r</strong></span><span style="color: MediumSeaGreen;"><strong>o</strong></span><span style="color: MediumSeaGreen;"><strong>c</strong></span><span style="color: MediumSeaGreen;"><strong>e</strong></span><span style="color: MediumSeaGreen;"><strong>s</strong></span><span style="color: MediumSeaGreen;"><strong>s</strong></span><span style="color: MediumSeaGreen;"><strong>"</strong></span><span style="color: MediumSeaGreen;"><strong>;</strong></span><br /> <strong>1</strong> <strong>2</strong><strong> │ </strong> const foo = process.env.FOO;<br /> <strong>2</strong> <strong>3</strong><strong> │ </strong> <br /> <br /></code></pre>
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
Section titled “Related links”Copyright (c) 2023-present Biome Developers and Contributors.