From 1807161871ee236b8342ff011a91be12d81431e0 Mon Sep 17 00:00:00 2001 From: Antoine du Hamel Date: Sat, 7 Nov 2020 17:33:51 +0100 Subject: [PATCH] tools,lib: recommend using safe primordials Make the linter recommend replacing `globalThis.Map` by `primordials.SafeMap`, and similar for `Set`, `WeakSet`, and `WeakMap`. --- lib/.eslintrc.yaml | 4 ++++ test/parallel/test-eslint-prefer-primordials.js | 9 +++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/.eslintrc.yaml b/lib/.eslintrc.yaml index 37a43a223af2fd..c95fffd53bc547 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -57,6 +57,7 @@ rules: into: Number - name: JSON - name: Map + into: Safe - name: Math - name: Number - name: Object @@ -70,6 +71,7 @@ rules: - name: Reflect - name: RegExp - name: Set + into: Safe - name: String - name: Symbol - name: SyntaxError @@ -80,7 +82,9 @@ rules: - name: Uint8ClampedArray - name: URIError - name: WeakMap + into: Safe - name: WeakSet + into: Safe globals: Intl: false # Parameters passed to internal modules diff --git a/test/parallel/test-eslint-prefer-primordials.js b/test/parallel/test-eslint-prefer-primordials.js index d9417e857c2089..6a28f541e4de84 100644 --- a/test/parallel/test-eslint-prefer-primordials.js +++ b/test/parallel/test-eslint-prefer-primordials.js @@ -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/ }] + }, ] });