Linter · Rules
no-obj-calls
Disallow calling Math, JSON, Reflect, Atomics, Intl and Temporal as functions
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
Reported:
const random = Math();
const parser = new JSON();
const format = Intl;
const text = format("en-US");
const now = globalThis.Reflect();
Not reported:
const random = Math.random();
const data = JSON.parse(body);
const text = new Intl.NumberFormat("en-US").format(total);