Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Re-enable prefer-json-parse-buffer #2565

Open
fisker opened this issue Feb 19, 2025 · 1 comment
Open

Re-enable prefer-json-parse-buffer #2565

fisker opened this issue Feb 19, 2025 · 1 comment

Comments

@fisker
Copy link
Collaborator

fisker commented Feb 19, 2025

Description

This rule actually makes sense to JavaScript users, but it's disabled due to compatibility with TypeScript, how about rename to consistent-json-file-read, and default to read as string, but add option to allow read it as buffer?

Examples

// ❌
JOSN.parse(await fs.readFile('/path/to/file.json'));

// ✅
JOSN.parse(await fs.readFile('/path/to/file.json', 'utf8'));
// ❌
// eslint unicorn/consistent-json-file-read: ["error", "buffer"]
JOSN.parse(await fs.readFile('/path/to/file.json', 'utf8'));

// ✅
// eslint unicorn/consistent-json-file-read: ["error", "buffer"]
JOSN.parse(await fs.readFile('/path/to/file.json'));

Additional Info

We may want check other cases in the future, since there are more way to read a JSON file now.

createRequire(import.meta.url)('/path/to/file.json');
await import('./path/to/file.json', {with:{type:'json'}});
@sindresorhus
Copy link
Owner

how about rename to consistent-json-file-read, and default to read as string, but add option to allow read it as buffer?

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants