# biome correctness/noGlobalDirnameFilename: fix changes program behavior

Internal evidence sheet generated by fixhunt. Not an issue text. A human re-verifies, checks the duplicates
below, and writes the upstream report in their own words following the project's AI policy.

- Tool: biome 2.5.15
- Rule: correctness/noGlobalDirnameFilename (tool labels the fix: safe, this fix reported as safe)
- Oracle: fix-changes-behavior
- Judge (Nemotron 3 Ultra, advisory): program-bug, severity low. The program runs as an ES module where __dirname is not defined, causing a ReferenceError before the fix. The fix correctly rewrites to import.meta.dirname, which is the documented replacement for ES modules. The behavior change is due to the module system environment, not a bug in the rewrite itself.
- Program: minimized from 7 to 5 lines

## Reproducer

```js
class C {
  static dir = __dirname;
  static log() {
  }
}
```

## Commands

```sh
node prog.js
bunx @biomejs/biome lint --only=correctness/noGlobalDirnameFilename --write prog.js
node prog.js
```

## Observed

```
exit 1 → 0
stderr before: ReferenceError: __dirname is not defined in ES module scope
stderr after: (none)
```

## Diff applied by the fix

```diff
--- orig.js	2026-10-22 13:28:10.862717420 -0400
+++ fixed.js	2026-10-22 13:28:11.016719985 -0400
@@ -1,5 +1,5 @@
 class C {
-  static dir = __dirname;
+  static dir = import.meta.dirname;
   static log() {
   }
 }
```

## Why the rewrite is not equivalent (model draft, verify before use)

The original code uses `__dirname`, which is only available in CommonJS modules; running it as an ES module throws a ReferenceError because `__dirname` is undefined. The fix replaces `__dirname` with `import.meta.dirname`, which is valid in ES modules and provides the directory name of the current module file. This change avoids the runtime error, allowing the program to execute successfully where it previously failed, thus altering behavior from throwing an exception to completing normally. The rewrite is not semantics-preserving because it changes the program’s outcome from error to success under ES module execution.

## Upstream search

Queries: "noGlobalDirnameFilename fix", "correctness noGlobalDirnameFilename static field", "biome rule __dirname replacement", "ES module import.meta.dirname usage"

- related: https://github.com/biomejs/biome/issues/8829
  same rule (noGlobalDirnameFilename) but different defect (false negatives vs fix-changes-behavior on static class field)
- related: https://github.com/biomejs/biome/pull/8922
  same rule (noGlobalDirnameFilename) but different artifact (PR revamping rule vs fix-changes-behavior on static class field)
- related: https://github.com/biomejs/biome/issues/11028
  same rule (noGlobalDirnameFilename) but different construct (CommonJS module vs ES module static class field)

<details><summary>All hits</summary>

- [github, open] 💅 `noUnnecessaryConditions`: false positive on an overloaded call with `undefined` as the default argument (Vue `inject`) — https://github.com/biomejs/biome/issues/12040
- [github, open] 💅 noLeakedRender false positive when using useState<boolean> — https://github.com/biomejs/biome/issues/10790
- [github, closed] 💅 `useSimplifiedLogicExpression` "safe" fix breaks code — https://github.com/biomejs/biome/issues/11351
- [github, closed] 💅 `useExplicitLengthCheck` false positive and broken fix — https://github.com/biomejs/biome/issues/11558
- [github, closed] 💅 `useExplicitLengthCheck` false positive — https://github.com/biomejs/biome/issues/11352
- [github, closed] 💅 Corrupted CLI safe fix for `useConsistentArrowReturn` — https://github.com/biomejs/biome/issues/8347
- [github, closed] 💅 lint/nursery/noUselessUndefined fix is unsafe for functions with union return types — https://github.com/biomejs/biome/issues/6906
- [github, closed] 💅 `useConsistentCurlyBraces` not working with string children — https://github.com/biomejs/biome/issues/7579
- [github, closed] 💅 `noLeakedRender` false positives — https://github.com/biomejs/biome/issues/10514
- [github, closed] 💅 2.1.2 broke SolidJS store syntax — https://github.com/biomejs/biome/issues/6998
- [tavily] biome migrate --write accesses the whole filesystem, takes minutes · Issue #7361 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/7361
- [tavily] 💅 useConsistentTypeDefinitions should ignore interfaces in global declarations · Issue #8449 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/8449
- [tavily] 💅 `noProcessGlobal` imports from `node::process` instead of `node:process` · Issue #5778 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/5778
- [tavily] 💅 [v2] Overrides not working when all linter category rules are on · Issue #5456 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/5456
- [tavily] 💅 noNoninteractiveElementInteractions marks `dialog` as non-interactive · Issue #7783 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/7783
- [tavily] 💅 False positive by lint/nursery/noUselessUndefined · Issue #6577 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/6577
- [tavily] 💅 `noUnresolvedImports`: multiple categories of false positives · Issue #9143 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/9143
- [tavily] 💅 `noGlobalDirnameFilename` doesn't work in most scenarios (false negatives) · Issue #8829 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/8829
- [tavily] fix(lint): revamp the `noGlobalDirnameFilename` rule to catch many false negatives by siketyan · Pull Request #8922 · biomejs/biome · GitHub — https://github.com/biomejs/biome/pull/8922
- [tavily] 📎 Biome v2.5 rule promotion plan · Issue #10510 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/10510
- [tavily] 📎 Implement `biome lint --rule=<rule-name>` · Issue #58 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/58
- [tavily] 💅 false positive of `noGlobalDirnameFilename` in CommonJS module · Issue #11028 · biomejs/biome · GitHub — https://github.com/biomejs/biome/issues/11028

</details>
