Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New:
no-unsupported-features/v8
rule (refs #118)
- Loading branch information
1 parent
9992b17
commit 222f6c0
Showing
5 changed files
with
524 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# Disallow unsupported `v8` APIs on the specified version (no-unsupported-features/v8) | ||
|
||
Node.js community is improving built-in modules continuously. | ||
You can check [Node.js Documentation](https://nodejs.org/api/) to know which Node.js version supports each Node.js API. | ||
|
||
This rule reports unsupported `v8` module's APIs on the configured Node.js version as lint errors. | ||
Editor integrations of ESLint would be useful to know it in real-time. | ||
|
||
## Rule Details | ||
|
||
This rule reports APIs of the `v8` module on the basis of [Node.js v10.6.0 Documentation](https://nodejs.org/docs/v10.6.0/api/v8.html). | ||
|
||
### Configured Node.js version range | ||
|
||
This rule reads the [engines] field of `package.json` to detect which Node.js versions your module is supporting. | ||
|
||
I recommend the use of the [engines] field because it's the official way that indicates which Node.js versions your module is supporting. | ||
For example of `package.json`: | ||
|
||
```json | ||
{ | ||
"name": "your-module", | ||
"version": "1.0.0", | ||
"engines": { | ||
"node": ">=6.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)). | ||
|
||
### Options | ||
|
||
```json | ||
{ | ||
"node/no-unsupported-features/v8": ["error", { | ||
"version": ">=6.0.0", | ||
"ignores": [] | ||
}] | ||
} | ||
``` | ||
|
||
#### version | ||
|
||
As mentioned above, this rule reads the [engines] field of `package.json`. | ||
But, you can overwrite the version by `version` option. | ||
|
||
The `version` option accepts [the valid version range of `node-semver`](https://github.com/npm/node-semver#range-grammar). | ||
|
||
#### ignores | ||
|
||
If you are using transpilers, maybe you want to ignore the warnings about some features. | ||
You can use this `ignores` option to ignore the given features. | ||
|
||
The `"ignores"` option accepts an array of the following strings. | ||
|
||
- `"v8"` | ||
- `"v8.cachedDataVersionTag"` | ||
- `"v8.getHeapSpaceStatistics"` | ||
- `"v8.serialize"` | ||
- `"v8.deserialize"` | ||
- `"v8.Serializer"` | ||
- `"v8.Deserializer"` | ||
- `"v8.DefaultSerializer"` | ||
- `"v8.DefaultDeserializer"` | ||
|
||
### Known limitations | ||
|
||
This rule cannot find non-static things. | ||
E.g., the use of instance methods. | ||
|
||
[engines]: https://docs.npmjs.com/files/package.json#engines |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/** | ||
* @author Toru Nagashima | ||
* See LICENSE file in root directory for full license. | ||
*/ | ||
"use strict" | ||
|
||
const { READ } = require("eslint-utils") | ||
const defineUnsupportedModuleHandlers = require("../../util/define-unsupported-module-handlers") | ||
const enumeratePropertyNames = require("../../util/enumerate-property-names") | ||
|
||
const trackMap = { | ||
modules: { | ||
v8: { | ||
[READ]: { supported: "1.0.0" }, | ||
cachedDataVersionTag: { [READ]: { supported: "8.0.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" } }, | ||
}, | ||
}, | ||
} | ||
|
||
module.exports = { | ||
meta: { | ||
docs: { | ||
description: | ||
"disallow unsupported `v8` APIs on the specified version", | ||
category: "Possible Errors", | ||
recommended: true, | ||
url: | ||
"https://github.com/mysticatea/eslint-plugin-node/blob/v6.0.1/docs/rules/no-unsupported-features/v8.md", | ||
}, | ||
fixable: null, | ||
schema: [ | ||
{ | ||
type: "object", | ||
properties: { | ||
version: { | ||
type: "string", | ||
}, | ||
ignores: { | ||
type: "array", | ||
items: { | ||
enum: Array.from( | ||
enumeratePropertyNames(trackMap.modules) | ||
), | ||
}, | ||
uniqueItems: true, | ||
}, | ||
}, | ||
additionalProperties: false, | ||
}, | ||
], | ||
messages: { | ||
unsupported: | ||
"The '{{name}}' is not supported until Node.js {{supported}}. The configured version range is '{{version}}'.", | ||
}, | ||
}, | ||
create(context) { | ||
return defineUnsupportedModuleHandlers(context, trackMap) | ||
}, | ||
} |
Oops, something went wrong.