Skip to content

Commit e19478a

Browse files
aduh95targos
authored andcommitted
tools,lib: recommend using safe primordials
Make the linter recommend replacing `globalThis.Map` by `primordials.SafeMap`, and similar for `Set`, `WeakSet`, and `WeakMap`. PR-URL: #36026 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: Michaël Zasso <targos@protonmail.com> Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
1 parent 5f848a6 commit e19478a

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/.eslintrc.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ rules:
5555
into: Number
5656
- name: JSON
5757
- name: Map
58+
into: Safe
5859
- name: Math
5960
- name: Number
6061
- name: Object
@@ -68,6 +69,7 @@ rules:
6869
- name: Reflect
6970
- name: RegExp
7071
- name: Set
72+
into: Safe
7173
- name: String
7274
- name: Symbol
7375
- name: SyntaxError
@@ -78,7 +80,9 @@ rules:
7880
- name: Uint8ClampedArray
7981
- name: URIError
8082
- name: WeakMap
83+
into: Safe
8184
- name: WeakSet
85+
into: Safe
8286
globals:
8387
Intl: false
8488
# Parameters passed to internal modules

test/parallel/test-eslint-prefer-primordials.js

+9
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ new RuleTester({
7777
`,
7878
options: [{ name: 'Reflect' }],
7979
},
80+
{
81+
code: 'const { Map } = primordials; new Map()',
82+
options: [{ name: 'Map', into: 'Safe' }],
83+
},
8084
],
8185
invalid: [
8286
{
@@ -154,5 +158,10 @@ new RuleTester({
154158
options: [{ name: 'Reflect' }],
155159
errors: [{ message: /const { ReflectOwnKeys } = primordials/ }]
156160
},
161+
{
162+
code: 'new Map()',
163+
options: [{ name: 'Map', into: 'Safe' }],
164+
errors: [{ message: /const { SafeMap } = primordials/ }]
165+
},
157166
]
158167
});

0 commit comments

Comments
 (0)