biome correctness/noGlobalDirnameFilename: fix changes program behavior
Hypothesis Nemotron 3 Super predicted to fire fired 1×
The fix does not preserve trailing comments on the line if the replacement alters whitespace in a way that moves or drops line comments
Program
Output
(no stdout) ReferenceError: __dirname is not defined in ES module scope
(no stdout)
- fired
- 1 before · 0 after
- runs
- each version twice, same file name, no network
Judge Nemotron 3 Ultra advisory program-bug · low
The program runs as an ES module where __dirname is undefined, causing a ReferenceError before the fix. The rewrite to import.meta.dirname is the documented ES-module replacement, so the behavior change stems from the module system environment, not a flaw in the fix itself.
Explanation Nemotron 3 Super unverified
The original code uses `__dirname`, which is undefined in ES modules, causing a ReferenceError. The replacement `import.meta.dirname` provides the directory name of the current module file in ES module scope, resolving the error. Since the behavior changes from throwing an exception to executing successfully, the rewrite alters program semantics despite preserving the comment. This change is not semantics-preserving because it modifies the program’s execution outcome.
Reproduce
- file
prog.js(the before program)- minimized program
- r1-p006.js
- evidence sheet
- r1-p006.md
- regression fixture
- r1-p006.js the minimized program with a header stating the observed change, for the tool's test suite
node prog.js bunx @biomejs/biome lint --only=correctness/noGlobalDirnameFilename --write prog.js node prog.js
Upstream search GitHub issues Tavily Nemotron 3 Super + Ultra
noGlobalDirnameFilename fix · __dirname usage in ES modules · noGlobalDirnameFilename linting pattern · import.meta.dirname replacement behavior
- duplicate biomejs/biome/issues/11028 same rule (noGlobalDirnameFilename) and same construct (__dirname rewrite in module context)
Details
- program
- __dirname; // comment - tests trailing comment preservation
- hazard
- The fix does not preserve trailing comments on the line if the replacement alters whitespace in a way that moves or drops line comments
- oracle
exit 1 → 0 stderr before: ReferenceError: __dirname is not defined in ES module scope stderr after: (none)- run
- 2026-10-17T20-16-26-722Z-l85y-biome-correctness_noGlobalDirnameFilename
generated program (3 lines) and the fix's diff
--- orig.js 2026-10-17 16:16:41.117029086 -0400 +++ fixed.js 2026-10-17 16:16:41.383025839 -0400 @@ -1,3 +1,3 @@ // Hazard 6 -__dirname; // this comment must stay +import.meta.dirname; // this comment must stay console.log('ok');
rule documentation given to the models
Summary
- Name: noGlobalDirnameFilename
- Fix: safe
- Default severity: info
- Available from version: 2.0.0
- Diagnostic category: lint/correctness/noGlobalDirnameFilename
Description
Disallow the use of `__dirname` and `__filename` in the global scope.
They are [not available in ES modules](https://nodejs.org/api/esm.html#esm_no_filename_or_dirname).
Starting with Node.js 20.11, `import.meta.dirname` and `import.meta.filename` have been introduced in ES modules, providing identical functionality to `__dirname` and `__filename` in CommonJS (CJS).
Examples
Invalid
```js,expect_diagnostic
const dirname = __dirname;
```
```js,expect_diagnostic
const filename = __filename;
```
``` js,expect_diagnostic
const foo = { __filename }
```
```js,expect_diagnostic
if (__dirname.startsWith("/project/src/")) {}
```
Valid
```js
const dirname = import.meta.dirname
const filename = import.meta.filename
const foo = {__filename: import.meta.filename };
if (import.meta.dirname.startsWith("/project/src/")) {}
```