Skip to content

Commit

Permalink
Add BigInt type to the new-for-builtins rule (#310)
Browse files Browse the repository at this point in the history
  • Loading branch information
fisker authored and sindresorhus committed Jun 3, 2019
1 parent 770fe42 commit e17f0fd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/rules/new-for-builtins.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ Disallows the use of `new` for following builtins.
- `Number`
- `Boolean`
- `Symbol`
- `BigInt`

> 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.
Expand Down
1 change: 1 addition & 0 deletions rules/new-for-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const enforceNew = new Set([
]);

const disallowNew = new Set([
'BigInt',
'Boolean',
'Number',
'String',
Expand Down
6 changes: 6 additions & 0 deletions test/new-for-builtins.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ ruleTester.run('new-for-builtins', rule, {
'const foo = new UInt16Array()',
'const foo = new UInt32Array()',
'const foo = new Uint8ClampedArray()',
'const foo = BigInt()',
'const foo = Boolean()',
'const foo = Number()',
'const foo = String()',
Expand Down Expand Up @@ -169,6 +170,11 @@ ruleTester.run('new-for-builtins', rule, {
errors: [enforceNewError('Uint8ClampedArray')],
output: 'const foo = new Uint8ClampedArray()'
},
{
code: 'const foo = new BigInt(123)',
errors: [disallowNewError('BigInt')],
output: 'const foo = BigInt(123)'
},
{
code: 'const foo = new Boolean()',
errors: [disallowNewError('Boolean')],
Expand Down

0 comments on commit e17f0fd

Please sign in to comment.