Skip to content

eslint/no-obj-calls Correctness ​

✅ This rule is turned on by default.

What it does ​

Disallow calling some global objects as functions

Why is this bad? ​

Some global objects are not intended to be called as functions. Calling them as functions will usually result in a TypeError being thrown.

Example ​

Examples of incorrect code for this rule:

javascript
let math = Math();
let newMath = new Math();

let json = JSON();
let newJson = new JSON();

let atomics = Atomics();
let newAtomics = new Atomics();

let intl = Intl();
let newIntl = new Intl();

let reflect = Reflect();
let newReflect = new Reflect();

Examples of correct code for this rule:

javascript
let area = (r) => 2 * Math.PI * r * r;
let object = JSON.parse("{}");
let first = Atomics.load(sharedArray, 0);
let segmenterFrom = Intl.Segmenter("fr", { granularity: "word" });

How to use ​

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny no-obj-calls
json
{
  "rules": {
    "no-obj-calls": "error"
  }
}

References ​

Released under the MIT License.