forked from mysticatea/eslint-plugin-node
-
-
Notifications
You must be signed in to change notification settings - Fork 43
/
Copy pathnode-builtins.js
66 lines (62 loc) · 1.97 KB
/
node-builtins.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @author Toru Nagashima
* See LICENSE file in root directory for full license.
*/
"use strict"
const {
checkUnsupportedBuiltins,
messages,
} = require("../../util/check-unsupported-builtins")
const enumeratePropertyNames = require("../../util/enumerate-property-names")
const getConfiguredNodeVersion = require("../../util/get-configured-node-version")
const {
NodeBuiltinGlobals,
NodeBuiltinModules,
} = require("../../unsupported-features/node-builtins.js")
const traceMap = {
globals: NodeBuiltinGlobals,
modules: NodeBuiltinModules,
}
/** @type {import('eslint').Rule.RuleModule} */
module.exports = {
meta: {
docs: {
description:
"disallow unsupported Node.js built-in APIs on the specified version",
recommended: true,
url: "https://github.com/eslint-community/eslint-plugin-n/blob/HEAD/docs/rules/no-unsupported-features/node-builtins.md",
},
type: "problem",
fixable: null,
schema: [
{
type: "object",
properties: {
version: getConfiguredNodeVersion.schema,
allowExperimental: { type: "boolean" },
ignores: {
type: "array",
items: {
enum: Array.from(
new Set([
...enumeratePropertyNames(traceMap.globals),
...enumeratePropertyNames(traceMap.modules),
])
),
},
uniqueItems: true,
},
},
additionalProperties: false,
},
],
messages,
},
create(context) {
return {
"Program:exit"() {
checkUnsupportedBuiltins(context, traceMap)
},
}
},
}