Skip to content

Commit

Permalink
tools,lib: recommend using safe primordials
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
aduh95 authored and danielleadams committed Nov 10, 2020
1 parent 7a37590 commit f8098c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions lib/.eslintrc.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ rules:
into: Number
- name: JSON
- name: Map
into: Safe
- name: Math
- name: Number
- name: Object
Expand All @@ -68,6 +69,7 @@ rules:
- name: Reflect
- name: RegExp
- name: Set
into: Safe
- name: String
- name: Symbol
- name: SyntaxError
Expand All @@ -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
Expand Down
9 changes: 9 additions & 0 deletions test/parallel/test-eslint-prefer-primordials.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,10 @@ new RuleTester({
`,
options: [{ name: 'Reflect' }],
},
{
code: 'const { Map } = primordials; new Map()',
options: [{ name: 'Map', into: 'Safe' }],
},
],
invalid: [
{
Expand Down Expand Up @@ -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/ }]
},
]
});

0 comments on commit f8098c3

Please sign in to comment.