forked from eslint-community/eslint-plugin-n
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-builtins.js
100 lines (96 loc) · 2.95 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @author Toru Nagashima
* See LICENSE file in root directory for full license.
*/
"use strict"
const { READ } = require("@eslint-community/eslint-utils")
const {
checkUnsupportedBuiltins,
messages,
} = require("../../util/check-unsupported-builtins")
const enumeratePropertyNames = require("../../util/enumerate-property-names")
const getConfiguredNodeVersion = require("../../util/get-configured-node-version")
const {
NodeBuiltinModules,
} = require("../../unsupported-features/node-builtins.js")
/**
* @typedef TraceMap
* @property {import('@eslint-community/eslint-utils').TraceMap<boolean>} globals
* @property {import('@eslint-community/eslint-utils').TraceMap<boolean>} modules
*/
const traceMap = {
globals: {
queueMicrotask: {
[READ]: { supported: ["12.0.0"], experimental: ["11.0.0"] },
},
require: {
resolve: {
paths: { [READ]: { supported: ["8.9.0"] } },
},
},
},
modules: NodeBuiltinModules,
}
Object.assign(traceMap.globals, {
Buffer: traceMap.modules.buffer.Buffer,
TextDecoder: {
...traceMap.modules.util.TextDecoder,
[READ]: { supported: ["11.0.0"] },
},
TextEncoder: {
...traceMap.modules.util.TextEncoder,
[READ]: { supported: ["11.0.0"] },
},
URL: {
...traceMap.modules.url.URL,
[READ]: { supported: ["10.0.0"] },
},
URLSearchParams: {
...traceMap.modules.url.URLSearchParams,
[READ]: { supported: ["10.0.0"] },
},
console: traceMap.modules.console,
process: traceMap.modules.process,
})
/** @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,
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)
},
}
},
}