-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Warning on Buffer(var) and new Buffer(var) #693
Comments
Yeah sounds good! On Tue, Nov 22, 2016 at 6:47 PM Matteo Collina [email protected]
|
Why is This would break a lot of code since I often use dynamic buffer sizes... |
if myvar is undefined bad things could happen On Wed, Nov 23, 2016 at 2:33 AM Daniel Cousens [email protected]
|
One thing we could do is warn when it's being used without |
@LinusU |
I would find it very nice since I'm not using babel :) |
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 |
If this lands, standard should encourage people to use the safe-buffer module. |
Also this is a way better solution that deprecating anything in Node core IMO \o/ |
Yeah! The error message already encourages that! |
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). |
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. |
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. |
@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 |
Just ran the test suite with this rule enabled, and found this:
Almost all the errors were because of the
|
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. |
Yep, here you go: https://gist.github.com/feross/74ca1cf53c7edf7caf13e4020ca8941b |
The ability to ignore individual rules was merged into |
I'd be OK with just disallowing So many explosions will happen though. |
@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. |
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%.
|
I would have a lot of breakage... but, for me, its breakage I want. |
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, |
I take this back; the amount of breakage has been insane... I've had to lock so many packages down, from |
Yea, been locking down deps as well for the same reason. |
@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. |
@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. |
@mcollina the changes are easy... the maintenance of breakage down the chain since you are effectively enforcing node >= |
@dcousens with safe-buffer, I applied those changes easily enough. It's just one line of code more. |
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.
The text was updated successfully, but these errors were encountered: