2.3.2 β’ Published 2 years ago
@putout/plugin-remove-useless-new v2.3.2
@putout/plugin-remove-useless-new
πPutout plugin adds ability to remove useless operator 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 |
---|---|---|
π Putout | remove-useless-new | β |
π¦ ESLint | no-new-wrappers | β |
β | no-new-object | β |
β | no-array-constructor | β |
β | no-new-symbol | β |
License
MIT