From e19478aa7669c1fa8324a4b02aea68bb1eef736f 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 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Michaƫl Zasso Reviewed-By: Shingo Inoue --- 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 0fb39d56b2f584..deea6bf4fb05ae 100644 --- a/lib/.eslintrc.yaml +++ b/lib/.eslintrc.yaml @@ -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 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/ }] + }, ] });