Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upWarning on Buffer(var) and new Buffer(var) #693
Comments
This comment has been minimized.
This comment has been minimized.
|
Yeah sounds good! On Tue, Nov 22, 2016 at 6:47 PM Matteo Collina notifications@github.com
|
This comment has been minimized.
This comment has been minimized.
|
Why is This would break a lot of code since I often use dynamic buffer sizes... |
This comment has been minimized.
This comment has been minimized.
|
if myvar is undefined bad things could happen On Wed, Nov 23, 2016 at 2:33 AM Daniel Cousens notifications@github.com
|
This comment has been minimized.
This comment has been minimized.
|
One thing we could do is warn when it's being used without |
This comment has been minimized.
This comment has been minimized.
|
@LinusU |
This comment has been minimized.
This comment has been minimized.
|
I would find it very nice since I'm not using babel :) |
This comment has been minimized.
This comment has been minimized.
|
I like this idea. It would push people in the right direction without Node core needing to print a deprecation warning in the console. I found an eslint plugin rule @mcollina What do you think about just requiring |
This comment has been minimized.
This comment has been minimized.
|
If this lands, standard should encourage people to use the safe-buffer module. |
This comment has been minimized.
This comment has been minimized.
|
Also this is a way better solution that deprecating anything in Node core IMO \o/ |
This comment has been minimized.
This comment has been minimized.
Yeah! The error message already encourages that! |
This comment has been minimized.
This comment has been minimized.
It really depends. I'm in favor of not adding one more npm dep to support old nodes, but I am ok with suggesting that where I do not think 'disable all deprecated things' is good, I think we should just target each deprecation individually. Domains have no other equivalent, and there are good uses for them. Buffer is special, we would probably need to put out a web page on how to deal with the error anyway (also the one currently in core). |
This comment has been minimized.
This comment has been minimized.
Currently we don't do "warnings". Just "errors" to keep things simple. Users could decide to ignore warnings, and that creates permanent noise in CI if/when they're ignored. So it's all-or-nothing.
Yeah, this is reasonable. However, I'd argue that almost no one should use domains. If someone really needs domains, they can disable the rule with a comment: Also, if we make it semver major, then this would only apply to new code. |
This comment has been minimized.
This comment has been minimized.
My bad, I am too wired in the other discussion. I meant errors.
Agreed. The point is: do we want to automatically discourage any use of things deprecated in core? IMHO those errors are all semver-major changes, and it's better to include them individually. But, let's error on domains. |
This comment has been minimized.
This comment has been minimized.
|
@mcollina Yeah, that's a good question. Given core's trend towards breaking changes, I can see them deprecating something else that is widely used, and then this rule would inherit it automatically, even for people on older (supported) versions of Node, like Node v4. Related: mysticatea/eslint-plugin-node#58 |
This comment has been minimized.
This comment has been minimized.
|
Just ran the test suite with this rule enabled, and found this:
Almost all the errors were because of the
|
feross
added
the
enhancement
label
Nov 23, 2016
This comment has been minimized.
This comment has been minimized.
|
Good. Can you link the full list of offenders on a gist? I still think we should be in control of what we error on. |
This comment has been minimized.
This comment has been minimized.
|
Yep, here you go: https://gist.github.com/feross/74ca1cf53c7edf7caf13e4020ca8941b |
This comment has been minimized.
This comment has been minimized.
|
The ability to ignore individual rules was merged into |
feross
added this to the
standard v9 milestone
Feb 8, 2017
This comment has been minimized.
This comment has been minimized.
|
I'd be OK with just disallowing So many explosions will happen though. |
This comment has been minimized.
This comment has been minimized.
|
@dcousens Yes, I agree. I plan to put this into the v10 beta. It's a new major version, so upgrading will be opt-in and users can wait to do it if they don't want to fix their code right away. One of the things that's nice about having We want to be careful to only warn about deprecations when the replacement code works in Node LTS versions (4 and 6). Otherwise, we'll force users to write code that only works in Node 6, for example, and that goes much too far. Update: this has moved from v9 to the v10 milestone. |
feross
modified the milestones:
standard v9,
standard v10
Feb 9, 2017
feross
added
the
ecosystem impact
label
Feb 9, 2017
This comment has been minimized.
This comment has been minimized.
|
tl;dr: This will be part of the standard v10 beta. The ecosystem impact with this change is extreme (18%).
Despite the large breakage, I believe this is the right thing to do. Tools like
One thing to temper this data... lots of my own modules appear in the tests and I use After fixing all my own modules, the new results are better, at 13%.
|
feross
closed this
Mar 2, 2017
feross
added a commit
to standard/eslint-config-standard
that referenced
this issue
Mar 2, 2017
This comment has been minimized.
This comment has been minimized.
|
I would have a lot of breakage... but, for me, its breakage I want. |
This comment has been minimized.
This comment has been minimized.
Yep, I've actually been meaning to switch all my modules over to the new buffer methods for a while, but this new rule finally provided the impetus. By the way, when Node <4.5.0 support is desired, |
This comment has been minimized.
This comment has been minimized.
I take this back; the amount of breakage has been insane... I've had to lock so many packages down, from |
This comment has been minimized.
This comment has been minimized.
|
Yea, been locking down deps as well for the same reason. |
This comment has been minimized.
This comment has been minimized.
|
@dcousens @mafintosh I totally get it, I did that on a few packages too. I plan to eventually get them onto standard 10 when I have time. I think Node.js is still determined to hard-deprecate buffer (by printing a warning) eventually so I still think it's the right thing to warn maintainers about this before we all get tons of issues from confused users who are using a new Node.js version. Lmk if you disagree. |
This comment has been minimized.
This comment has been minimized.
|
@feross I think adding a little utility that fixes it automatically for strings might be handy. I fixed 300+ instances with a couple of vim macros. |
This comment has been minimized.
This comment has been minimized.
|
@mcollina the changes are easy... the maintenance of breakage down the chain since you are effectively enforcing node >= |
This comment has been minimized.
This comment has been minimized.
|
@dcousens with safe-buffer, I applied those changes easily enough. It's just one line of code more. |
mcollina commentedNov 22, 2016
I think standard should emit a warning for
Buffer(myvar)andnew Buffer(myvar).IMHO safe things are:
Buffer(42)andnew Buffer(42)Buffer(myvar, 'utf8')andnew Buffer(myvar, 'utf8')Buffer('hello')andnew Buffer('hello')All of those can run on any version of node, and provide an additional layer of security even if we do not zero fill, etc.