-
-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Labels
good first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededlet's do it
Description
Description
This codemod should validate and convert invalid argument types to fs.existsSync(). It's useful to migrate code that passes invalid argument types which now causes deprecation warnings or errors.
It should validate that fs.existsSync() receives string, Buffer, or URL arguments only. It should convert invalid argument types to valid ones where possible. It should handle both CommonJS and ESM imports. It should add type checks or conversions to ensure argument validity.
Examples
Case 1
Before:
const fs = require("node:fs");
const exists = fs.existsSync(123);
After:
const fs = require("node:fs");
const exists = fs.existsSync(String(123));
Case 2
Before:
const fs = require("node:fs");
function checkFile(path) {
return fs.existsSync(path);
}
After:
const fs = require("node:fs");
function checkFile(path) {
if (typeof path !== 'string' && !Buffer.isBuffer(path) && !(path instanceof URL)) {
path = String(path);
}
return fs.existsSync(path);
}
Case 3
Before:
const fs = require("node:fs");
const fileExists = fs.existsSync(null);
After:
const fs = require("node:fs");
const fileExists = fs.existsSync(String(null || ''));
Case 4
Before:
import { existsSync } from "node:fs";
const exists = existsSync({ path: '/some/file' });
After:
import { existsSync } from "node:fs";
const exists = existsSync(String({ path: '/some/file' }));
REFS
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is neededlet's do it
Type
Projects
Status
🏗 In progress