noInvalidBuiltinInstantiation
¥Summary
-
规则生效日期:
v1.7.2¥Rule available since:
v1.7.2 -
诊断类别:
lint/correctness/noInvalidBuiltinInstantiation¥Diagnostic Category:
lint/correctness/noInvalidBuiltinInstantiation -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则包含 unsafe 修复程序。
¥This rule has an unsafe fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
¥Same as
unicorn/new-for-builtins -
与
no-new-native-nonconstructor相同¥Same as
no-new-native-nonconstructor
-
¥How to configure
{ "linter": { "rules": { "correctness": { "noInvalidBuiltinInstantiation": "error" } } }}¥Description
确保内置函数正确实例化。
¥Ensure that builtins are correctly instantiated.
以下内置函数需要实例化 new:
¥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
相反,以下内置函数不能用 new 建立:
¥Conversely, the following builtins cannot be instaiated with new:
-
BigInt
-
符号
¥Symbol
¥Examples
¥Invalid
const 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
const text = BigInt(1);const map = new Map([ ['foo', 'bar']]);¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号