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 <[email protected]>
Reviewed-By: Michaël Zasso <[email protected]>
Reviewed-By: Shingo Inoue <[email protected]>
  • Loading branch information
aduh95 authored and targos committed Jun 11, 2021
1 parent 5f848a6 commit e19478a
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 e19478a

Please sign in to comment.