question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Rule proposal: no-buffer-constructor

See original GitHub issue

In the upcoming Node.js v6 release, the existing Buffer() constructors are being soft-deprecated (docs-only deprecation) and replaced with new Buffer.alloc(), Buffer.allocUnsafe() and Buffer.from() alternatives. I am adding a rule to Node.js’ own eslint configuration to flag uses of the deprecated constructors (see: https://github.com/nodejs/node/pull/5740). The point has been raised that it may be worthwhile upstreaming this rule so that it can be of benefit to the ecosystem as a whole. Currently the rule is pretty simplistic and can be made a bit more robust if necessary.

The rule catches uses of the Buffer() constructor either as new Buffer(...) or simply Buffer(...) (without the new) and suggests using one of the new constructors instead.

If it is worthwhile, I can open a pull request to submit the rule here.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:7
  • Comments:34 (30 by maintainers)

github_iconTop GitHub Comments

5reactions
ferosscommented, Mar 17, 2017

I think preventing usage of deprecated APIs which have security implications is probably one of the few cases where it makes sense to add another node-related rule in ESLint core. Preventing the anti-pattern where Buffer(var) accidentally returns uninitialized program memory fits in with other similar ESLint rules that prevent unintended program behavior.

Even if it’s not included in eslint:recommended, I believe the mere inclusion in ESLint will have a significant effect on the visibility of the rule.

I’m really keen to see community tooling (like standard and hopefully ESLint) step up and discourage soon-to-be-deprecated Node.js APIs. That way, when deprecation finally happens most modules are upgraded and it’s a lot less painful for the community.

That said, I understand the maintenance burden that adding another rule entails, so I’ll respect the team’s decision. 👍

4reactions
not-an-aardvarkcommented, Apr 5, 2017

I’ll champion this.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SEC Proposed Rules
SEC Proposed Rules · Regulation NMS: Minimum Pricing Increments, Access Fees, and Transparency of Better Priced Orders · File No: S7-30-22 · Comments...
Read more >
Order Approving a Proposed Rule Change, as Modified by ...
On October 11, 2022, the Commission extended the time period for approving or disapproving the proposal to December 15, 2022.
Read more >
eslint | Yarn - Package Manager
A bug fix in a rule that results in ESLint reporting fewer linting errors. A bug fix to the CLI or core (including...
Read more >
disallow reassigning exceptions in catch clauses (no-ex- ...
Since there is no arguments object to offer alternative access to this data, assignment of ... This rule disallows reassigning exceptions in catch...
Read more >
Code Issues
We have discovered some checks and rules for C#. ... other class will use it, therefore, you want (or need) to offer a...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found