Comments (16)
I want to take this one if that's ok?
from eslint-plugin-unicorn.
ESLint can't target specific Node.js versions, right?
You're right, it can't.
Not sure if it makes sense to already create this rule
Well, it can be useful for people who will only target Node >= 6 versions for their app/libraries, so I'd say yes.
I wonder, are there any other similar constructs where new XYZ()
is replaced by a method on XYZ
? I don't know if it would make sense to generalize this.
from eslint-plugin-unicorn.
Buffer.from()
was backported to Node.js 4 (benefits of it being LTS), so we can safely enforce it.
from eslint-plugin-unicorn.
Buffer.from() was backported to Node.js 4 (benefits of it being LTS), so we can safely enforce it.
Oh, didn't know that. Nice!
from eslint-plugin-unicorn.
@SamVerschueren Go ahead 🤘
from eslint-plugin-unicorn.
I wonder, are there any other similar constructs where new XYZ() is replaced by a method on XYZ? I don't know if it would make sense to generalize this.
So this will be a rule specific to Buffer then?
from eslint-plugin-unicorn.
@jfmengels Yes. We can add a more generic rule in the future if use-cases come up.
from eslint-plugin-unicorn.
So this will be a rule specific to Buffer then?
Exactly, no need to add a "complex construct" which might never get used. We can always improve later on.
from eslint-plugin-unicorn.
Okay, sounds good to me.
from eslint-plugin-unicorn.
Make sure to take Buffer.alloc()
into account too. See kevva/to-ico@22b4472.
from eslint-plugin-unicorn.
Aha, good catch @kevva. It's not as simple as finding a NewStatement
with Buffer
and changing that to Buffer.from()
.
from eslint-plugin-unicorn.
Just wanted to point out that eslint-plugin-node has similar rule for deprecated APIs if you need some hints on how to additionally approach this: https://github.com/mysticatea/eslint-plugin-node/blob/master/docs/rules/no-deprecated-api.md
from eslint-plugin-unicorn.
How should we call this rule?
no-new-buffer
new-buffer-deprecated
buffer-deprecated
- ...
from eslint-plugin-unicorn.
@SamVerschueren no-new-buffer
from eslint-plugin-unicorn.
Should we also cover the case that someone could write this? It works perfectly although XO will fail with the new-cap
rule.
const buf = Buffer('foo');
from eslint-plugin-unicorn.
Nah, I've never seen anyone write that, and as you said, it's already covered by the new-cap
rule.
from eslint-plugin-unicorn.
Related Issues (20)
- Export types for use in flat configs
- `unicorn/explicit-length-check` does not report when optional chaining
- `unicorn/no-invalid-remove-event-listener` does not report when optional chaining
- Support `import.meta.dirname` and `import.meta.filename` in `prefer-module` rule HOT 5
- Rule proposal: `no-single-promise-in-promise-methods` HOT 2
- Rule proposal: `no-await-in-promise-methods` HOT 2
- Rule proposal: `no-anonymous-default-export` HOT 2
- `error-message` believes that a joined array is empty when elements are conditionally pushed
- Consider remove autofixing unicorn/prevent-abbreviations HOT 5
- False positive for consistent-destructuring HOT 1
- Rule proposal: avoid loops to create `URLSearchParams` HOT 5
- False positive `array-from-async` in `unicorn/no-unnecessary-polyfills`
- Support `Array.fromAsync()`
- `no-array-callback-reference` false positive HOT 1
- Rule proposal: no-confusing-conditions HOT 1
- `string-content` rule: case insensitive matching
- Switch to flat config HOT 2
- `prefer-array-find` doesn't warn about `.at(0)`
- Change `numeric-separators-style` after decimal point HOT 2
- `unicorn/number-literal-case` conflicts with `prettier/prettier` HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from eslint-plugin-unicorn.