no-object-constructor
Disallow Object() and new Object() without an argument
has suggestions
new Object() and Object() without an argument make an empty object. {} does the same thing and is shorter.
A call with an argument isn't reported. It converts the argument to an object, which {} can't do.
Configure#
Off by default. To turn it on:
bunfig.toml
[lint.rules]
"no-object-constructor" = "error" # or "warn"Examples#
example.js2 problems
const cache = new Object()The object literal notation {} is preferable.;
const totals = Object()The object literal notation {} is preferable.;example.jsNo problems
const cache = {};
const totals = {};
const wrapped = Object(value);A call to your own Object isn't reported either:
example.jsNo problems
function build(Object) {
return new Object();
}