Skip to content

Commit

Permalink
💥 update no-unsupported-features/node-builtins for Node 12
Browse files Browse the repository at this point in the history
  • Loading branch information
mysticatea committed May 2, 2019
1 parent 7e0c2c5 commit 5d79f2d
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 33 deletions.
44 changes: 35 additions & 9 deletions docs/rules/no-unsupported-features/node-builtins.md
Expand Up @@ -8,7 +8,7 @@ Editor integrations of ESLint would be useful to know it in real-time.

## Rule Details

This rule reports APIs of Node.js built-in APIs on the basis of [Node.js v11.0.0 Documentation](https://nodejs.org/docs/v11.0.0/api/).
This rule reports APIs of Node.js built-in APIs on the basis of [Node.js v12.0.0 Documentation](https://nodejs.org/docs/v12.0.0/api/).

### Configured Node.js version range

Expand All @@ -22,19 +22,19 @@ For example of `package.json`:
"name": "your-module",
"version": "1.0.0",
"engines": {
"node": ">=6.0.0"
"node": ">=8.0.0"
}
}
```

If you omit the [engines] field, this rule chooses `>=6.0.0` as the configured Node.js version since `6` is the minimum version the community is maintaining (see also [Node.js Release Working Group](https://github.com/nodejs/Release#readme)).
If you omit the [engines] field, this rule chooses `>=8.0.0` as the configured Node.js version since `8` is the minimum version the community is maintaining (see also [Node.js Release Working Group](https://github.com/nodejs/Release#readme)).

### Options

```json
{
"node/no-unsupported-features/node-builtins": ["error", {
"version": ">=6.0.0",
"version": ">=8.0.0",
"ignores": []
}]
}
Expand Down Expand Up @@ -82,6 +82,7 @@ The `"ignores"` option accepts an array of the following strings.
- `"console.timeStamp"`
- `"console.timeline"`
- `"console.timelineEnd"`
- `"process.allowedNodeEnvironmentFlags"`
- `"process.argv0"`
- `"process.channel"`
- `"process.cpuUsage"`
Expand All @@ -92,9 +93,14 @@ The `"ignores"` option accepts an array of the following strings.
- `"process.hrtime.bigint"`
- `"process.ppid"`
- `"process.release"`
- `"process.report"`
- `"process.setegid"`
- `"process.seteuid"`
- `"process.setUncaughtExceptionCaptureCallback"`
- `"process.stdout.getColorDepth"`
- `"process.stdout.hasColor"`
- `"process.stderr.getColorDepth"`
- `"process.stderr.hasColor"`
- `"queueMicrotask"`
- `"require.resolve.paths"`

Expand Down Expand Up @@ -151,6 +157,10 @@ The `"ignores"` option accepts an array of the following strings.
- `"crypto.Certificate.exportChallenge"`
- `"crypto.Certificate.exportPublicKey"`
- `"crypto.Certificate.verifySpkac"`
- `"crypto.KeyObject"`
- `"crypto.createPrivateKey"`
- `"crypto.createPublicKey"`
- `"crypto.createSecretKey"`
- `"crypto.constants"`
- `"crypto.fips"`
- `"crypto.generateKeyPair"`
Expand All @@ -164,14 +174,21 @@ The `"ignores"` option accepts an array of the following strings.
- `"crypto.scrypt"`
- `"crypto.scryptSync"`
- `"crypto.setFips"`
- `"crypto.sign"`
- `"crypto.timingSafeEqual"`
- `"crypto.verify"`

**`dns` module:**

- `"dns.Resolver"`
- `"dns.resolvePtr"`
- `"dns.promises"`

**`events` module:**

- `"events.EventEmitter.once"`
- `"events.once"`

**`fs` module:**

- `"fs.Dirent"`
Expand Down Expand Up @@ -211,6 +228,7 @@ The `"ignores"` option accepts an array of the following strings.
**`perf_hooks` module:**

- `"perf_hooks"`
- `"perf_hooks.monitorEventLoopDelay"`

**`process` module:**

Expand All @@ -225,9 +243,14 @@ The `"ignores"` option accepts an array of the following strings.
- `"process.hrtime.bigint"`
- `"process.ppid"`
- `"process.release"`
- `"process.report"`
- `"process.setegid"`
- `"process.seteuid"`
- `"process.setUncaughtExceptionCaptureCallback"`
- `"process.stdout.getColorDepth"`
- `"process.stdout.hasColor"`
- `"process.stderr.getColorDepth"`
- `"process.stderr.hasColor"`

**`stream` module:**

Expand All @@ -252,6 +275,7 @@ The `"ignores"` option accepts an array of the following strings.
- `"util.getSystemErrorName"`
- `"util.inspect.custom"`
- `"util.inspect.defaultOptions"`
- `"util.inspect.replDefaults"`
- `"util.isDeepStrictEqual"`
- `"util.promisify"`
- `"util.TextDecoder"`
Expand All @@ -262,14 +286,16 @@ The `"ignores"` option accepts an array of the following strings.
**`v8` module:**

- `"v8"`
- `"v8.DefaultDeserializer"`
- `"v8.DefaultSerializer"`
- `"v8.Deserializer"`
- `"v8.Serializer"`
- `"v8.cachedDataVersionTag"`
- `"v8.deserialize"`
- `"v8.getHeapSnapshot"`
- `"v8.getHeapSpaceStatistics"`
- `"v8.serialize"`
- `"v8.deserialize"`
- `"v8.Serializer"`
- `"v8.Deserializer"`
- `"v8.DefaultSerializer"`
- `"v8.DefaultDeserializer"`
- `"v8.writeHeapSnapshot"`

**`vm` module:**

Expand Down
65 changes: 48 additions & 17 deletions lib/rules/no-unsupported-features/node-builtins.js
Expand Up @@ -11,7 +11,9 @@ const enumeratePropertyNames = require("../../util/enumerate-property-names")
/*eslint-disable camelcase */
const trackMap = {
globals: {
queueMicrotask: { [READ]: { supported: "11.0.0" } },
queueMicrotask: {
[READ]: { supported: "12.0.0", experimental: "11.0.0" },
},
require: {
resolve: {
paths: { [READ]: { supported: "8.9.0" } },
Expand Down Expand Up @@ -72,6 +74,10 @@ const trackMap = {
exportPublicKey: { [READ]: { supported: "9.0.0" } },
verifySpkac: { [READ]: { supported: "9.0.0" } },
},
KeyObject: { [READ]: { supported: "11.6.0" } },
createPrivateKey: { [READ]: { supported: "11.6.0" } },
createPublicKey: { [READ]: { supported: "11.6.0" } },
createSecretKey: { [READ]: { supported: "11.6.0" } },
constants: { [READ]: { supported: "6.3.0" } },
fips: { [READ]: { supported: "6.0.0" } },
generateKeyPair: { [READ]: { supported: "10.12.0" } },
Expand All @@ -85,14 +91,22 @@ const trackMap = {
scrypt: { [READ]: { supported: "10.5.0" } },
scryptSync: { [READ]: { supported: "10.5.0" } },
setFips: { [READ]: { supported: "10.0.0" } },
sign: { [READ]: { supported: "12.0.0" } },
timingSafeEqual: { [READ]: { supported: "6.6.0" } },
verify: { [READ]: { supported: "12.0.0" } },
},
dns: {
Resolver: { [READ]: { supported: "8.3.0" } },
resolvePtr: { [READ]: { supported: "6.0.0" } },
promises: {
[READ]: { supported: "10.6.0" },
[READ]: { supported: "11.14.0", experimental: "10.6.0" },
},
},
events: {
EventEmitter: {
once: { [READ]: { supported: "11.13.0" } },
},
once: { [READ]: { supported: "11.13.0" } },
},
fs: {
Dirent: { [READ]: { supported: "10.10.0" } },
Expand All @@ -107,7 +121,7 @@ const trackMap = {
native: { [READ]: { supported: "9.2.0" } },
},
promises: {
[READ]: { supported: "10.1.0" },
[READ]: { supported: "11.14.0", experimental: "10.1.0" },
},
},
http2: {
Expand All @@ -134,6 +148,7 @@ const trackMap = {
},
perf_hooks: {
[READ]: { supported: "8.5.0" },
monitorEventLoopDelay: { [READ]: { supported: "11.10.0" } },
},
process: {
allowedNodeEnvironmentFlags: { [READ]: { supported: "10.10.0" } },
Expand All @@ -151,11 +166,20 @@ const trackMap = {
},
ppid: { [READ]: { supported: "9.2.0" } },
release: { [READ]: { supported: "3.0.0" } },
report: { [READ]: { supported: null, experimental: "11.8.0" } },
setegid: { [READ]: { supported: "2.0.0" } },
seteuid: { [READ]: { supported: "2.0.0" } },
setUncaughtExceptionCaptureCallback: {
[READ]: { supported: "9.3.0" },
},
stdout: {
getColorDepth: { [READ]: { supported: "9.9.0" } },
hasColor: { [READ]: { supported: "11.13.0" } },
},
stderr: {
getColorDepth: { [READ]: { supported: "9.9.0" } },
hasColor: { [READ]: { supported: "11.13.0" } },
},
},
stream: {
finished: { [READ]: { supported: "10.0.0" } },
Expand All @@ -177,6 +201,7 @@ const trackMap = {
inspect: {
custom: { [READ]: { supported: "6.6.0" } },
defaultOptions: { [READ]: { supported: "6.4.0" } },
replDefaults: { [READ]: { supported: "11.12.0" } },
},
isDeepStrictEqual: { [READ]: { supported: "9.0.0" } },
promisify: { [READ]: { supported: "8.0.0" } },
Expand All @@ -189,38 +214,44 @@ const trackMap = {
},
v8: {
[READ]: { supported: "1.0.0" },
DefaultDeserializer: { [READ]: { supported: "8.0.0" } },
DefaultSerializer: { [READ]: { supported: "8.0.0" } },
Deserializer: { [READ]: { supported: "8.0.0" } },
Serializer: { [READ]: { supported: "8.0.0" } },
cachedDataVersionTag: { [READ]: { supported: "8.0.0" } },
deserialize: { [READ]: { supported: "8.0.0" } },
getHeapSnapshot: { [READ]: { supported: "11.13.0" } },
getHeapSpaceStatistics: { [READ]: { supported: "6.0.0" } },
serialize: { [READ]: { supported: "8.0.0" } },
deserialize: { [READ]: { supported: "8.0.0" } },
Serializer: { [READ]: { supported: "8.0.0" } },
Deserializer: { [READ]: { supported: "8.0.0" } },
DefaultSerializer: { [READ]: { supported: "8.0.0" } },
DefaultDeserializer: { [READ]: { supported: "8.0.0" } },
writeHeapSnapshot: { [READ]: { supported: "11.13.0" } },
},
vm: {
Module: { [READ]: { supported: "9.6.0" } },
compileFunction: { [READ]: { supported: "10.10.0" } },
},
worker_threads: {
[READ]: { supported: "10.5.0" },
[READ]: { supported: null, experimental: "10.5.0" },
},
},
}
Object.assign(trackMap.globals, {
Buffer: trackMap.modules.buffer.Buffer,
TextDecoder: Object.assign({}, trackMap.modules.util.TextDecoder, {
TextDecoder: {
...trackMap.modules.util.TextDecoder,
[READ]: { supported: "11.0.0" },
}),
TextEncoder: Object.assign({}, trackMap.modules.util.TextEncoder, {
},
TextEncoder: {
...trackMap.modules.util.TextEncoder,
[READ]: { supported: "11.0.0" },
}),
URL: Object.assign({}, trackMap.modules.url.URL, {
},
URL: {
...trackMap.modules.url.URL,
[READ]: { supported: "10.0.0" },
}),
URLSearchParams: Object.assign({}, trackMap.modules.url.URLSearchParams, {
},
URLSearchParams: {
...trackMap.modules.url.URLSearchParams,
[READ]: { supported: "10.0.0" },
}),
},
console: trackMap.modules.console,
process: trackMap.modules.process,
})
Expand Down
12 changes: 5 additions & 7 deletions lib/util/check-unsupported-builtins.js
Expand Up @@ -31,9 +31,7 @@ function parseOptions(context) {
*/
module.exports = function checkUnsupportedBuiltins(context, trackMap) {
const options = parseOptions(context)
const tracker = new ReferenceTracker(context.getScope(), {
mode: "legacy",
})
const tracker = new ReferenceTracker(context.getScope(), { mode: "legacy" })
const references = [
...tracker.iterateCjsReferences(trackMap.modules || {}),
...tracker.iterateEsmReferences(trackMap.modules || {}),
Expand All @@ -42,11 +40,11 @@ module.exports = function checkUnsupportedBuiltins(context, trackMap) {

for (const { node, path, info } of references) {
const name = path.join(".")
const supported = options.version.intersects(
getSemverRange(`<${info.supported}`)
)
const supported =
Boolean(info.supported) &&
!options.version.intersects(getSemverRange(`<${info.supported}`))

if (supported && !options.ignores.has(name)) {
if (!supported && !options.ignores.has(name)) {
context.report({
node,
messageId: "unsupported",
Expand Down

0 comments on commit 5d79f2d

Please sign in to comment.