-
-
Notifications
You must be signed in to change notification settings - Fork 21.7k
chore: enforce explicit Buffer import and add lint rule
#6525
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
chore: enforce explicit Buffer import and add lint rule
#6525
Conversation
|
I'm not sure this is a good practice, Buffer is a global property |
Node.js docs say:
This sentence replaced the previous
in nodejs/node#39043, but I can't find any arguments for why it is recommended. I think that it's just a cosmetic change for compatibility (or explicit incompatibility) reasons with other environments, but that's just a guess. |
|
@krzysdz Thanks for the references |
wesleytodd
left a comment
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.
It would be good to keep consistency, so if anyone is willing I think we have a bunch of other packages that could use this change.
FWIW, it is a cosmetic change but is still worth it to do because it sets a good example for anyone reading this code to learn from.
|
@shivarm Could you please update all occurrences of @wesleytodd If we want to keep that consistent we should add a lint rule to prevent usage of global Buffer: rules:
no-restricted-globals:
- error
- name: Buffer
message: Use `import { Buffer } from "node:buffer"` instead of the global Buffer. |
Phillip9587
left a comment
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.
See comment above
I am against one off lint rule discussions on principal, but I agree it would be best if we had these things enforced by linting. Since we have an eslint config already in the repo, I am not opposed to adding one as a temporary step until we get a better setup overall. @shivarm you could add this rule so that you can find and fix all the other implicit global usage. |
Signed-off-by: Shivam Sharma <[email protected]>
7611815 to
bb8ac68
Compare
|
@wesleytodd Done 👍 |
nodejs best practiceBuffer import and add lint rule
Hardanish-Singh
left a comment
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.
LGTM!
explicitly import Buffer using
const { Buffer } = require('node:buffer')for clarity and future compatibility, following Node.js best practices.