Skip to content

[eslint-factory] require-mkdirsync-try-catch: pass allowUnboundFsIdentifier: true to match sibling require-fs-sync-try-catch #46735

Description

@github-actions

Rule

eslint-factory/src/rules/require-mkdirsync-try-catch.ts

Problem (consistency / false-negative)

The two sibling fs-sync rules configure the shared resolver differently:

// require-fs-sync-try-catch.ts:32
const resolveFsSyncMethod = createFsSyncMethodResolver(sourceCode, FS_SYNC_METHODS, { allowUnboundFsIdentifier: true });

// require-mkdirsync-try-catch.ts:28
const resolveFsSyncMethod = createFsSyncMethodResolver(sourceCode, FS_SYNC_METHODS);

In try-catch-rule-utils.ts:222-223, allowUnboundFsIdentifier lets the resolver match fs.<method>(...) when the receiver is literally named fs even if fs cannot be resolved to a local require('fs')/import binding:

const canUseUnboundFsIdentifier = options.allowUnboundFsIdentifier === true && callee.object.name === "fs";
if (!canUseUnboundFsIdentifier && !isIdentifierBoundToFsModule(callee.object.name, callee.object)) return null;

So require-fs-sync-try-catch flags an unwrapped fs.readFileSync(p) even when the fs binding isn't visible, but require-mkdirsync-try-catch silently ignores the analogous unwrapped fs.mkdirSync(dir, { recursive: true }). Same receiver, same protective intent, different behavior.

Grounding

Ungrounded in the current corpus: every non-test .cjs mkdirSync site binds const fs = require("fs") locally and is already wrapped in try/catch, and setupGlobals does not inject a global fs. This is a latent inconsistency/robustness gap, not a live miss — but it makes the mkdir rule strictly weaker than its sibling for no stated reason.

Why tests don't catch it

The rule's "non-fs objects" valid tests only use differently-named receivers (mockFs, storage, myObj); there is no test for an unresolved receiver literally named fs, so the divergence from the sibling rule is untested.

Acceptance criteria

  • Change require-mkdirsync-try-catch.ts:28 to createFsSyncMethodResolver(sourceCode, FS_SYNC_METHODS, { allowUnboundFsIdentifier: true }).
  • Add an invalid test: fs.mkdirSync(dir, { recursive: true }); with no fs binding in scope → missingTryCatch.
  • Confirm the existing mockFs/storage/myObj cases stay valid (unaffected — allowUnboundFsIdentifier only relaxes for receiver name fs).
  • Alternatively, if the stricter behavior is intentional for mkdir, document why the two sibling rules diverge and pin it with a test.

Filed by ESLint Refiner (daily rule-refinement pass). Verified against rule sources + shared resolver.

Generated by 🤖 ESLint Refiner · 786.5 AIC · ⌖ 10.8 AIC · ⊞ 4.6K ·

  • expires on Jul 26, 2026, 10:35 PM UTC-08:00

Metadata

Metadata

Labels

cookieIssue Monster Loves Cookies!eslint

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions