-
-
Notifications
You must be signed in to change notification settings - Fork 389
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
Rule proposal: prefer-json-parse-buffer
#1273
Comments
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
That seems like a non-standard extension |
I think it's not, |
It does not generally seem to work with byte arrays: JSON.parse((new TextEncoder()).encode("{}"))
// Uncaught SyntaxError: Unexpected token , in JSON at position 3 Anyways, I think it's a good rule to have for a node-specific optimization. |
This is now accepted. |
It works just because |
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. |
I guess you'll have to disable in TS file. |
Or better, in the |
I don't know why this is preferable. I assume the argument is simply: shorter code is preferable. This rule forces/strongly encourages developers to chase down this GH thread to realize Why not go a step further, if we want short code, encourage using some sort of fs-extras |
Mentioned in the description
|
Main reason we are reading JSON files a lot is because we can't |
JSON modules are unflagged since nodejs/node#41736, fyi. |
Wow~ But, without |
Yeah, assertion still required, I'm not sure I like it. |
Reading a file as a |
I'm content with this being the main reason for this rule:
@addaleax do you mind providing some insight why A benchmark could assume json files are less than 10 pages, where a page is around 100 lines. |
I came here hoping for a data-driven explanation for this rule but the best reason so far is a bug that may already be fixed and @fisker's personal preference. If there's actually a performance benefit, can benchmarks be referenced? If there's no justification for this beyond preference, can this be a |
This rule is still usefully to me, but I agree the reason behind this rule is arguable. Maybe we should disable this rule in |
@fisker Should I open an new issue to request |
Send a PR, I'll approve. |
When parsing a json file, there is no need to read it as string, because
JSON.parse
can parseBuffer
. Real world caseFail
Pass
This is also faster when use
fsPromises
, but this is bug, should not be the main reason for this rule. nodejs/node#37583The text was updated successfully, but these errors were encountered: