Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit fcac2e0

Browse filesBrowse files
aduh95targos
authored andcommitted
lib: harden lint checks for globals
PR-URL: #38419 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Darshan Sen <raisinten@gmail.com>
1 parent 9c06103 commit fcac2e0
Copy full SHA for fcac2e0

File tree

Expand file treeCollapse file tree

14 files changed

+77
-9
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

14 files changed

+77
-9
lines changed
Open diff view settings
Collapse file

‎lib/.eslintrc.yaml‎

Copy file name to clipboardExpand all lines: lib/.eslintrc.yaml
+52-2Lines changed: 52 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,16 +27,65 @@ rules:
2727
message: "Use 'overrideStackTrace' from 'lib/internal/errors.js' instead of 'Error.prepareStackTrace'."
2828
no-restricted-globals:
2929
- error
30-
- name: globalThis
31-
message: "Use `const { globalThis } = primordials;` instead of the global."
30+
- name: AbortController
31+
message: "Use `const { AbortController } = require('internal/abort_controller');` instead of the global."
32+
- name: AbortSignal
33+
message: "Use `const { AbortSignal } = require('internal/abort_controller');` instead of the global."
34+
# Atomics is not available in primordials because it can be
35+
# disabled with --no-harmony-atomics CLI flag.
36+
- name: Atomics
37+
message: "Use `const { Atomics } = globalThis;` instead of the global."
38+
- name: Buffer
39+
message: "Use `const { Buffer } = require('buffer');` instead of the global."
40+
- name: Event
41+
message: "Use `const { Event } = require('internal/event_target');` instead of the global."
42+
- name: EventTarget
43+
message: "Use `const { EventTarget } = require('internal/event_target');` instead of the global."
44+
# Intl is not available in primordials because it can be
45+
# disabled with --without-intl build flag.
46+
- name: Intl
47+
message: "Use `const { Intl } = globalThis;` instead of the global."
48+
- name: MessageChannel
49+
message: "Use `const { MessageChannel } = require('internal/worker/io');` instead of the global."
50+
- name: MessageEvent
51+
message: "Use `const { MessageEvent } = require('internal/worker/io');` instead of the global."
52+
- name: MessagePort
53+
message: "Use `const { MessagePort } = require('internal/worker/io');` instead of the global."
54+
# SharedArrayBuffer is not available in primordials because it can be
55+
# disabled with --no-harmony-sharedarraybuffer CLI flag.
56+
- name: SharedArrayBuffer
57+
message: "Use `const { SharedArrayBuffer } = globalThis;` instead of the global."
58+
- name: TextDecoder
59+
message: "Use `const { TextDecoder } = require('internal/encoding');` instead of the global."
60+
- name: TextEncoder
61+
message: "Use `const { TextEncoder } = require('internal/encoding');` instead of the global."
62+
- name: URL
63+
message: "Use `const { URL } = require('internal/url');` instead of the global."
64+
- name: URLSearchParams
65+
message: "Use `const { URLSearchParams } = require('internal/url');` instead of the global."
66+
# WebAssembly is not available in primordials because it can be
67+
# disabled with --jitless CLI flag.
68+
- name: WebAssembly
69+
message: "Use `const { WebAssembly } = globalThis;` instead of the global."
70+
- name: atob
71+
message: "Use `const { atob } = require('buffer');` instead of the global."
72+
- name: btoa
73+
message: "Use `const { btoa } = require('buffer');` instead of the global."
3274
- name: global
3375
message: "Use `const { globalThis } = primordials;` instead of `global`."
76+
- name: globalThis
77+
message: "Use `const { globalThis } = primordials;` instead of the global."
78+
- name: performance
79+
message: "Use `const { performance } = require('perf_hooks');` instead of the global."
80+
- name: queueMicrotask
81+
message: "Use `const { queueMicrotask } = require('internal/process/task_queues');` instead of the global."
3482
# Custom rules in tools/eslint-rules
3583
node-core/lowercase-name-for-primitive: error
3684
node-core/non-ascii-character: error
3785
node-core/no-array-destructuring: error
3886
node-core/prefer-primordials:
3987
- error
88+
- name: AggregateError
4089
- name: Array
4190
- name: ArrayBuffer
4291
- name: BigInt
@@ -76,6 +125,7 @@ rules:
76125
into: Number
77126
- name: parseInt
78127
into: Number
128+
- name: Proxy
79129
- name: Promise
80130
- name: RangeError
81131
- name: ReferenceError
Collapse file

‎lib/internal/blob.js‎

Copy file name to clipboardExpand all lines: lib/internal/blob.js
+2Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ const {
2020
FixedSizeBlobCopyJob,
2121
} = internalBinding('buffer');
2222

23+
const { TextDecoder } = require('internal/encoding');
24+
2325
const {
2426
JSTransferable,
2527
kClone,
Collapse file

‎lib/internal/bootstrap/node.js‎

Copy file name to clipboardExpand all lines: lib/internal/bootstrap/node.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ const {
4646
ObjectGetPrototypeOf,
4747
ObjectPreventExtensions,
4848
ObjectSetPrototypeOf,
49+
Proxy,
4950
ReflectGet,
5051
ReflectSet,
5152
SymbolToStringTag,
Collapse file

‎lib/internal/crypto/webcrypto.js‎

Copy file name to clipboardExpand all lines: lib/internal/crypto/webcrypto.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ const {
2626
validateString,
2727
} = require('internal/validators');
2828

29-
const { TextDecoder } = require('internal/encoding');
29+
const { TextDecoder, TextEncoder } = require('internal/encoding');
3030

3131
const {
3232
codes: {
Collapse file

‎lib/internal/freeze_intrinsics.js‎

Copy file name to clipboardExpand all lines: lib/internal/freeze_intrinsics.js
+9-1Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// https://github.com/google/caja/blob/master/src/com/google/caja/ses/repairES5.js
2020
// https://github.com/tc39/proposal-ses/blob/e5271cc42a257a05dcae2fd94713ed2f46c08620/shim/src/freeze.js
2121

22-
/* global WebAssembly, SharedArrayBuffer, console */
22+
/* global console */
2323
'use strict';
2424

2525
const {
@@ -78,6 +78,7 @@ const {
7878
ObjectPrototypeHasOwnProperty,
7979
Promise,
8080
PromisePrototype,
81+
Proxy,
8182
RangeError,
8283
RangeErrorPrototype,
8384
ReferenceError,
@@ -124,6 +125,13 @@ const {
124125
globalThis,
125126
} = primordials;
126127

128+
const {
129+
Atomics,
130+
Intl,
131+
SharedArrayBuffer,
132+
WebAssembly
133+
} = globalThis;
134+
127135
module.exports = function() {
128136
const {
129137
clearImmediate,
Collapse file

‎lib/internal/http2/compat.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/compat.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
ObjectCreate,
1010
ObjectKeys,
1111
ObjectPrototypeHasOwnProperty,
12+
Proxy,
1213
ReflectApply,
1314
ReflectGetPrototypeOf,
1415
StringPrototypeIncludes,
Collapse file

‎lib/internal/http2/core.js‎

Copy file name to clipboardExpand all lines: lib/internal/http2/core.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const {
1818
ObjectPrototypeHasOwnProperty,
1919
Promise,
2020
PromisePrototypeCatch,
21+
Proxy,
2122
ReflectApply,
2223
ReflectGet,
2324
ReflectGetPrototypeOf,
Collapse file

‎lib/internal/main/worker_thread.js‎

Copy file name to clipboardExpand all lines: lib/internal/main/worker_thread.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ const {
99
ArrayPrototypeSplice,
1010
ObjectDefineProperty,
1111
PromisePrototypeCatch,
12+
globalThis: { Atomics },
1213
} = primordials;
1314

1415
const {
Collapse file

‎lib/internal/modules/cjs/loader.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/cjs/loader.js
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ const {
4545
ObjectPrototype,
4646
ObjectPrototypeHasOwnProperty,
4747
ObjectSetPrototypeOf,
48+
Proxy,
4849
ReflectApply,
4950
ReflectSet,
5051
RegExpPrototypeTest,
Collapse file

‎lib/internal/modules/esm/translators.js‎

Copy file name to clipboardExpand all lines: lib/internal/modules/esm/translators.js
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
'use strict';
22

3-
/* global WebAssembly */
4-
53
const {
64
ArrayPrototypeForEach,
75
ArrayPrototypeMap,
@@ -21,6 +19,7 @@ const {
2119
StringPrototypeSplit,
2220
StringPrototypeStartsWith,
2321
SyntaxErrorPrototype,
22+
globalThis: { WebAssembly },
2423
} = primordials;
2524

2625
let _TYPES = null;
@@ -63,6 +62,7 @@ const experimentalImportMetaResolve =
6362
getOptionValue('--experimental-import-meta-resolve');
6463
const asyncESM = require('internal/process/esm_loader');
6564
const { emitWarningSync } = require('internal/process/warning');
65+
const { TextDecoder } = require('internal/encoding');
6666

6767
let cjsParse;
6868
async function initCJSParse() {

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.