biome correctness/noProcessGlobal
labelled safe
Analysis Nemotron 3 Super
Flags any direct reference to the `process` global variable.
Fix: Replaces every occurrence of the identifier `process` with an imported binding by adding `import process from 'node:process';` at the top of the file (if not already present) and rewriting the reference to use that imported binding.
8 hazards
- Replacing `process` in a catch clause like `catch (process)` would rename the exception parameter, altering what is caught.
- If a local variable named `process` is declared later in the same scope, the import would hoist above it and cause the local variable to shadow the import instead of the global, changing runtime behavior.
- When `process` is used as a label (e.g., `process: break process;`), the rewrite would break syntax because labels cannot be replaced with imported identifiers.
- In indirect eval calls such as `eval('process.env')`, the string is not rewritten, so the eval would still resolve to the global `process` if it exists, diverging from the direct-reference behavior.
- If the file already contains an import named `process` from a different source (e.g., `import process from './local-process'`), adding another import would cause a duplicate identifier error.
- When `process` is accessed via destructuring with a default value like `{process = fallback} = obj`, the rewrite would fail to produce valid syntax.
- Comments attached to the `process` token (e.g., `process/* TODO */.env`) would be lost because the autofix replaces the entire token without preserving trailing or inline comments.
- In non-ESM environments where `import` statements are not supported (e.g., CommonJS without `type: module`), inserting the import would cause a parse error or runtime failure.
Programs
| id | result | title | hazard |
|---|---|---|---|
| r1-p001 | silent prediction off | Label usage breaks syntax when replaced | When `process` is used as a label (e.g., `process: break process;`), the rewrite would break syntax because labels cannot be replaced with imported identifiers. |
| r1-p002 | silent prediction off | Temporal dead zone after hoisting/reordering | temporal dead zone after code is hoisted or reordered |
| r1-p004 | silent prediction off | Var hoisting and redeclaration inside loops | var hoisting and re-declaration inside loops or after use |
| r1-p005 | silent prediction off | Catch clause parameter renamed alters exception handling | Replacing `process` in a catch clause like `catch (process)` would rename the exception parameter, altering what is caught. |
| r1-p006 | silent prediction off | Local variable later shadows imported binding | If a local variable named `process` is declared later in the same scope, the import would hoist above it and cause the local variable to shadow the import instead of the global, changing runtime behav |
| r1-p007 | fix ok | Inline comments attached to token are lost | Comments attached to the `process` token (e.g., `process/* TODO */.env`) would be lost because the autofix replaces the entire token without preserving trailing or inline comments. |
| r1-p008 | fix ok | Function declarations inside blocks/switch/labeled statements | function declarations inside blocks, switch cases, labeled statements |
| r2-p001 | fix ok | Class field referencing process | class fields, static blocks, private names, super calls |
| r2-p002 | fix ok | Inline comment on process token | Comments attached to the `process` token (e.g., `process/* TODO */.env`) would be lost because the autofix replaces the entire token without preserving trailing or inline comments. |
| r2-p003 | fix ok | Function declaration in switch case | function declarations inside blocks, switch cases, labeled statements |
| r2-p005 | silent prediction off | Local variable process declared after use | If a local variable named `process` is declared later in the same scope, the import would hoist above it and cause the local variable to shadow the import instead of the global, changing runtime behav |
| r2-p006 | fix ok | CommonJS environment without ES modules | In non-ESM environments where `import` statements are not supported (e.g., CommonJS without `type: module`), inserting the import would cause a parse error or runtime failure. |
| r2-p008 | invalid | Strict mode function using process | strict vs sloppy mode semantics |
Sources
r1-p001 · Label usage breaks syntax when replaced
1process: {
2 console.log('inside label block');
3 break process;
4}
5console.log('after label');
inside label block after label
r1-p002 · Temporal dead zone after hoisting/reordering
1console.log(typeof process); // should be 'object' before fix
2let process = { version: 'local' };
3console.log(process.version);
r1-p004 · Var hoisting and redeclaration inside loops
1for (var i = 0; i < 2; i++) {
2 if (typeof process === 'undefined') console.log('undef');
3 else console.log(process.version);
4 var process = { version: 'loop' + i };
5}
undef loop0
r1-p005 · Catch clause parameter renamed alters exception handling
1try {
2 throw { message: 'test' };
3} catch (process) {
4 console.log('caught:', process.message);
5}
6console.log('after catch');
caught: test after catch
r1-p006 · Local variable later shadows imported binding
1if (true) {
2 console.log(process.version); // expects global
3 let process = { version: 'local' };
4 console.log(process.version);
5}
r1-p007 · Inline comments attached to token are lost
1console.log(process/* version */.version);
2console.log('done');
--- orig.js 2026-10-17 16:45:18.826564821 -0400 +++ fixed.js 2026-10-17 16:45:19.131573203 -0400 @@ -1,2 +1,3 @@ +import process from "node:process"; console.log(process/* version */.version); console.log('done');
v26.8.1 done
r1-p008 · Function declarations inside blocks/switch/labeled statements
1switch (1) {
2 case 1:
3 function process() { return 'func'; }
4 console.log(process());
5 break;
6}
7console.log(typeof process);
--- orig.js 2026-10-17 16:45:19.316578284 -0400 +++ fixed.js 2026-10-17 16:45:19.596585973 -0400 @@ -1,3 +1,4 @@ +import process from "node:process"; switch (1) { case 1: function process() { return 'func'; }
func object
r2-p001 · Class field referencing process
1class C {
2 static #p = process;
3 static {
4 console.log(C.#p === process ? 'same' : 'diff');
5 }
6}
--- orig.js 2026-10-17 16:45:23.981706046 -0400 +++ fixed.js 2026-10-17 16:45:24.254713496 -0400 @@ -1,3 +1,4 @@ +import process from "node:process"; class C { static #p = process; static {
same
r2-p002 · Inline comment on process token
1console.log(process/* TODO */.env.NODE_ENV ?? 'unset');
--- orig.js 2026-10-17 16:45:24.428718244 -0400 +++ fixed.js 2026-10-17 16:45:24.695725530 -0400 @@ -1 +1,2 @@ +import process from "node:process"; console.log(process/* TODO */.env.NODE_ENV ?? 'unset');
unset
r2-p003 · Function declaration in switch case
1switch (1) {
2 case 1:
3 function f() { return process.pid; }
4 console.log(f());
5 break;
6}
--- orig.js 2026-10-17 16:45:24.882730632 -0400 +++ fixed.js 2026-10-17 16:45:25.153738022 -0400 @@ -1,3 +1,4 @@ +import process from "node:process"; switch (1) { case 1: function f() { return process.pid; }
2
r2-p005 · Local variable process declared after use
1console.log(typeof process);
2var process = 42;
undefined
r2-p006 · CommonJS environment without ES modules
1console.log(process.pid);
--- orig.js 2026-10-17 16:45:25.570749386 -0400 +++ fixed.js 2026-10-17 16:45:25.837756662 -0400 @@ -1 +1,2 @@ +import process from "node:process"; console.log(process.pid);
2
r2-p008 · Strict mode function using process (generated program is not deterministic)
1"use strict";
2(function() {
3 console.log(process.uptime());
4})();