eslint/no-new-native-nonconstructor Correctness ​
What it does ​
Disallow new
operators with global non-constructor functions (Symbol
, BigInt
)
Why is this bad? ​
Both new Symbol
and new BigInt
throw a type error because they are functions and not classes. It is easy to make this mistake by assuming the uppercase letters indicate classes.
Example ​
Examples of incorrect code for this rule:
js
// throws a TypeError
let foo = new Symbol("foo");
// throws a TypeError
let result = new BigInt(9007199254740991);
Examples of correct code for this rule:
js
let foo = Symbol("foo");
let result = BigInt(9007199254740991);
How to use ​
To enable this rule in the CLI or using the config file, you can use:
bash
oxlint --deny no-new-native-nonconstructor
json
{
"rules": {
"no-new-native-nonconstructor": "error"
}
}