@putout/plugin-remove-useless-new
new
. Which has no sense for BigInt
, Boolean
, String
, Number
, Object
, RegExp
, Error
:
Thus the function call
Error(…)
is equivalent to the object creation expressionnew Error(…)
with the same arguments.(c) https://262.ecma-international.org/12.0/#sec-error-constructor
And Symbol
cannot be used with new
, as it is primitive.
Part of @putout/plugin-new
.
Install
npm i @putout/plugin-remove-useless-new
Rule
{
"rules": {
"remove-useless-new": "on"
}
}
❌ Example of incorrect code
new Error('Something whent wrong');
new new Boolean();
✅ Example of correct code
Error('Something whent wrong');
Boolean();
Comparison
Linter | Rule | Fix |
---|---|---|
|
remove-useless-new |
|
|
no-new-wrappers |
|
⠀ | no-new-object |
|
⠀ | no-array-constructor |
|
⠀ | no-new-symbol |
License
MIT