Skip to content

Commit 6042cce

Browse files
committed
Fix mistake in the new-for-builtins rule
`Symbol` should *not* be used with `new`.
1 parent 81625e5 commit 6042cce

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

docs/rules/new-for-builtins.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ Enforces the use of `new` for following builtins.
2222
- `WeakSet`
2323
- `Promise`
2424
- `RegExp`
25-
- `Symbol`
2625
- `Uint8Array`
2726
- `Uint16Array`
2827
- `Uint32Array`
@@ -33,6 +32,7 @@ Disallows the use of `new` for following builtins.
3332
- `String`
3433
- `Number`
3534
- `Boolean`
35+
- `Symbol`
3636

3737
> These should not use `new` as that would create object wrappers for the primitive values, which is not what you want. However, without `new` they can be useful for coercing a value to that type.
3838

rules/new-for-builtins.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ const enforceNew = new Set([
1818
'WeakSet',
1919
'Promise',
2020
'RegExp',
21-
'Symbol',
2221
'Uint8Array',
2322
'Uint16Array',
2423
'Uint32Array',
@@ -28,7 +27,8 @@ const enforceNew = new Set([
2827
const disallowNew = new Set([
2928
'Boolean',
3029
'Number',
31-
'String'
30+
'String',
31+
'Symbol'
3232
]);
3333

3434
const create = context => {

test/new-for-builtins.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ ruleTester.run('new-for-builtins', rule, {
3939
`const foo = new WeakSet()`,
4040
`const foo = new Promise()`,
4141
`const foo = new RegExp()`,
42-
`const foo = new Symbol()`,
4342
`const foo = new UInt8Array()`,
4443
`const foo = new UInt16Array()`,
4544
`const foo = new UInt32Array()`,
4645
`const foo = new Uint8ClampedArray()`,
4746
`const foo = Boolean()`,
4847
`const foo = Number()`,
49-
`const foo = String()`
48+
`const foo = String()`,
49+
`const foo = Symbol()`
5050
],
5151
invalid: [
5252
{
@@ -149,11 +149,6 @@ ruleTester.run('new-for-builtins', rule, {
149149
errors: [enforceNewError('RegExp')],
150150
output: `const foo = new RegExp()`
151151
},
152-
{
153-
code: `const foo = Symbol()`,
154-
errors: [enforceNewError('Symbol')],
155-
output: `const foo = new Symbol()`
156-
},
157152
{
158153
code: `const foo = Uint8Array()`,
159154
errors: [enforceNewError('Uint8Array')],
@@ -193,6 +188,11 @@ ruleTester.run('new-for-builtins', rule, {
193188
code: `const foo = new String()`,
194189
errors: [disallowNewError('String')],
195190
output: `const foo = String()`
191+
},
192+
{
193+
code: `const foo = new Symbol()`,
194+
errors: [disallowNewError('Symbol')],
195+
output: `const foo = Symbol()`
196196
}
197197
]
198198
});

0 commit comments

Comments
 (0)