Skip to content

feat: add codemod for DEP0162 fs write coercion#416

Open
syhstanley wants to merge 5 commits intonodejs:mainfrom
syhstanley:feat/fs-write-coercion-codemod
Open

feat: add codemod for DEP0162 fs write coercion#416
syhstanley wants to merge 5 commits intonodejs:mainfrom
syhstanley:feat/fs-write-coercion-codemod

Conversation

@syhstanley
Copy link
Copy Markdown

Summary

Adds a codemod for DEP0162 — implicit coercion of objects in fs.write() and fs.writeFileSync().

  • Wraps the data parameter with String() for fs.writeFile(), fs.writeFileSync(), fs.appendFile(), fs.appendFileSync(), fs.write(), and their fs/promises variants
  • Skips already-safe types: string literals, template literals, Buffer.from(), new Uint8Array(), .toString(), String() wrappers
  • Handles both CommonJS require('fs') and ESM import { writeFile } from 'node:fs/promises'
  • Handles destructured imports

Test plan

Closes #412

🤖 Generated with Claude Code

stanleyshen2003 and others added 2 commits March 30, 2026 03:42
Add explicit String() conversion for objects passed as the data
parameter to fs.writeFile(), fs.writeFileSync(), fs.appendFile(),
fs.appendFileSync(), fs.write(), and their promises variants.

Closes nodejs#412

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Add missing README.md (required per CONTRIBUTING.md)
- Add yaml-language-server schema comment to workflow.yaml
- Sort include file patterns alphabetically
- Fix isSafeType: remove dead template literal check, tighten String() match
- Add isLikelyBufferOverload guard for fs.write() buffer overload
- Support float numeric literals in isSafeType
- Normalize test file naming (file-02 → file-2)

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not too bad but:

for you info you have to use this structure of testing

Codemod leverages a before ("input") + after ("expected") snapshot comparison. Codemod supports 2 options:

  • 👍 Single-file fixtures
    tests/
      some-test-case-description/
        input.ts
        expected.ts
      another-test-case-description/
        input.ts
        expected.ts
    
  • 👎 Directory snapshot fixtures
    tests/
      input/
        some-test-case-description.ts
        another-test-case-description.ts
      expected
        some-test-case-description.ts
        another-test-case-description.ts
    

Use the Single-file fixtures option.

@AugustinMauroy AugustinMauroy added the awaiting author Reviewer has requested something from the author label Mar 31, 2026
stanleyshen2003 and others added 2 commits April 1, 2026 16:45
- Migrate tests to single-file fixture structure (input.ts + expected.ts per case)
- Use getModuleDependencies utility instead of separate import/require helpers
- Remove unnecessary escapeRegex() wrapper for identifier matching

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@syhstanley
Copy link
Copy Markdown
Author

Thanks for your review! Please check the new commits.

Change test fixture path from ./ to ./tests to match single-file fixture structure.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Copy link
Copy Markdown
Member

@AugustinMauroy AugustinMauroy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT !

@AugustinMauroy AugustinMauroy added awaiting reviewer Author has responded and needs action from the reviewer and removed awaiting author Reviewer has requested something from the author labels Apr 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting reviewer Author has responded and needs action from the reviewer ⚠️ fully-AI-generated

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fs.write() and fs.writeFileSync() coercion to string

3 participants