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: https://github.com/nodejs/node/pull/36026
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Shingo Inoue <leko.noor@gmail.com>
This commit is contained in:
Antoine du Hamel authored and Michaël Zasso committed 2021-06-11 09:28:02 +02:00
1 parent 5f848a612d
commit e19478aa76
2 files changed
+13

No files matched your search

+4
View File
@@ -55,6 +55,7 @@ rules:
into: Number
- name: JSON
- name: Map
into: Safe
- name: Math
- name: Number
- name: Object
@@ -68,6 +69,7 @@ rules:
- name: Reflect
- name: RegExp
- name: Set
into: Safe
- name: String
- name: Symbol
- name: SyntaxError
@@ -78,7 +80,9 @@ rules:
- name: Uint8ClampedArray
- name: URIError
- name: WeakMap
into: Safe
- name: WeakSet
into: Safe
globals:
Intl: false
# Parameters passed to internal modules
@@ -77,6 +77,10 @@ new RuleTester({
`,
options: [{ name: 'Reflect' }],
},
{
code: 'const { Map } = primordials; new Map()',
options: [{ name: 'Map', into: 'Safe' }],
},
],
invalid: [
{
@@ -154,5 +158,10 @@ new RuleTester({
options: [{ name: 'Reflect' }],
errors: [{ message: /const { ReflectOwnKeys } = primordials/ }]
},
{
code: 'new Map()',
options: [{ name: 'Map', into: 'Safe' }],
errors: [{ message: /const { SafeMap } = primordials/ }]
},
]
});