-
Notifications
You must be signed in to change notification settings - Fork 30.4k
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
tools: add buffer-constructor eslint rule #5740
Conversation
This custom rule isn't working for me, but maybe I'm misunderstanding what it is supposed to capture. Can you provide a code sample that this should flag? I've been assuming something like this is what you're trying to avoid:
|
'or Buffer.from()'; | ||
|
||
function test(context, node, which) { | ||
if (node.type === which && node.callee.name === 'Buffer') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's possible for node.type === which
to be false
in this situation. I don't think you need the which
variable at all.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
@Trott .. thank you for that, I'm afraid I'm not that familiar with eslint yet so those comments were very helpful. As for the rule itself, yes, it should catch uses of The rule appears to be working just fine for me on this end. If I add a
Changing that to |
Updated to address that feedback :-) |
LGTM |
Now that the Buffer.alloc, allocUnsafe, and from methods have landed, add a linting rule that requires their use within lib. Tests and benchmarks are explicitly excluded by the rule.
CI is green. |
LGTM, but perhaps you should try getting this upstreamed to help the community. |
That's a possibility. I'd want to get this landed here first tho. If it did hit upstream we could revert and use that later. |
Opened an issue to get this upstreamed. Will land this now. If/When it lands up stream we can update to use that version |
Now that the Buffer.alloc, allocUnsafe, and from methods have landed, add a linting rule that requires their use within lib. Tests and benchmarks are explicitly excluded by the rule. PR-URL: #5740 Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Landed in 9e30129 |
Pull Request check-list
make -j8 test
(UNIX) orvcbuild test nosign
(Windows) pass withthis change (including linting)?
test (or a benchmark) included?
existing APIs, or introduces new ones)?
Affected core subsystem(s)
tools (eslint)
Description of change
Now that the Buffer.alloc, allocUnsafe, and from methods have landed,
add a linting rule that requires their use within lib. Tests and
benchmarks are explicitly excluded by the rule.
Requires: #4682
/cc @Trott @ChALkeR @nodejs/testing