Rule proposal: `prefer-json-parse-buffer`
See original GitHub issueWhen parsing a json file, there is no need to read it as string, because JSON.parse
can parse Buffer
. Real world case
Fail
JSON.parse(await fs.readFile(file, 'utf8'));
Pass
JSON.parse(await fs.readFile(file));
JSON.parse(await fs.readFile(file, 'gbk'));
This is also faster when use fsPromises
, but this is bug, should not be the main reason for this rule. https://github.com/nodejs/node/issues/37583
Issue Analytics
- State:
- Created 2 years ago
- Reactions:6
- Comments:22 (6 by maintainers)
Top Results From Across the Web
eslint-config-ash-nazg - npm
ash-nazg aims to offer defaults which adhere to norms, build upon productive restrictions, and in a few cases, offer greater latitude where some ......
Read more >sindresorhus/eslint-plugin-unicorn (Raised $2856.00)
Rule proposal : Expiring TODO comments. Rewarded#238created bysindresorhus. 1 pull request. $100.00. Rule proposal: No default parameter options.
Read more >Comparing main...next · prettier/prettier · GitHub
Note: This method does **not** offer a way to _extend_ the configuration to overwrite some properties from the shared configuration. If you need...
Read more >JavaScript/TypeScript linter (ESLint wrapper) with great defaults
Uses ESLint underneath, so issues regarding rules should be opened over there. JSX is supported by default, but you'll need eslint-config-xo-react for React ......
Read more >Yet another GitHub proxy running on Cloudflare Workers
template-indent : Set the rule error instead of warn in recommended preset (#1781) 09923af; prefer-json-parse-buffer : Remove from ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Sorry to disagree, but typescript JSON.parse() does not accept anything but a string. See microsoft/TypeScript #44944. The only solution for me is to disable this rule.
This rule is still usefully to me, but I agree the reason behind this rule is arguable. Maybe we should disable this rule in
recommend
?