no-obj-calls
Disallow calling Math, JSON, Reflect, Atomics, Intl and Temporal as functions
error by default
Math, JSON, Reflect, Atomics, Intl and Temporal start with a capital letter, but they're plain objects that hold functions. Math() and new JSON() throw a TypeError when they run.
The rule follows the object through variables and through globalThis.
This rule is on by default in JavaScript files. It's off in TypeScript files, where TypeScript reports the same mistake.
Configure#
On by default as an error. To turn it off:
bunfig.toml
[lint.rules]
"no-obj-calls" = "off" # or "warn"Examples#
example.js1 problem
const random = Math()Math is not a function.;example.js1 problem
const parser = new JSON()JSON is not a function.;example.js2 problems
const format = Intl;
const text = format("en-US")format is reference to Intl, which is not a function.;
const now = globalThis.Reflect()Reflect is not a function.;example.jsNo problems
const random = Math.random();
const data = JSON.parse(body);
const text = new Intl.NumberFormat("en-US").format(total);