noInvalidBuiltinInstantiation
Diagnostic Category: lint/correctness/noInvalidBuiltinInstantiation
Since: v1.7.2
Sources:
- Same as: 
unicorn/new-for-builtins - Same as: 
no-new-native-nonconstructor 
Description
Section titled DescriptionEnsure that builtins are correctly instantiated.
The following builtins require new to be instantiate:
- ArrayBuffer
 - BigInt64Array
 - BigUint64Array
 - DataView
 - FinalizationRegistry
 - Float32Array
 - Float64Array
 - Int16Array
 - Int32Array
 - Int8Array
 - Map
 - Promise
 - Proxy
 - Set
 - SharedArrayBuffer
 - Uint16Array
 - Uint32Array
 - Uint8Array
 - Uint8ClampedArray
 - WeakMap
 - WeakRef
 - WeakSet
 
Conversely, the following builtins cannot be instaiated with new:
- BigInt
 - Symbol
 
Examples
Section titled ExamplesInvalid
Section titled Invalidconst text = new BigInt(1);code-block.js:1:14 lint/correctness/noInvalidBuiltinInstantiation  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ Use BigInt() instead of new BigInt().
  
  > 1 │ const text = new BigInt(1);
      │              ^^^^^^^^^^^^^
    2 │ 
  
  ℹ Unsafe fix: Remove new keyword.
  
    1 │ const·text·=·new·BigInt(1);
      │              ----          
const map = Map([  ['foo', 'bar']]);code-block.js:1:13 lint/correctness/noInvalidBuiltinInstantiation  FIXABLE  ━━━━━━━━━━━━━━━━━━━━━━━━
  ✖ Use new Map() instead of Map().
  
  > 1 │ const map = Map([
      │             ^^^^^
  > 2 │   [‘foo’, ‘bar’]
  > 3 │ ]);
      │ ^^
    4 │ 
  
  ℹ Unsafe fix: Add new keyword.
  
    1 │ const·map·=·new·Map([
      │             ++++     
Valid
Section titled Validconst text = BigInt(1);const map = new Map([ ['foo', 'bar']]);How to configure
Section titled How to configure{  "linter": {    "rules": {      "correctness": {        "noInvalidBuiltinInstantiation": "error"      }    }  }}