no-mixed-requires
UnreleasedConfiguration
Rule details
Disallow mixing require() declarations with other variables in the same var, let, or const declaration. Uninitialized variables count as other declarations. Accessing a property of a required module is allowed.
Examples of incorrect code:
Examples of correct code:
Options
grouping(default:false): require declarations in one statement must all load the same kind of module: core, package, file, or computed. File paths start with/,./, or../. Arguments other than string literals, and calls without arguments, are computed.allowCall(default:false): allow calling the result ofrequire()directly, such asrequire("diagnostics")("app"). Calling a property, such asrequire("diagnostics").create("app"), still counts as another declaration. When combined withgrouping, the outer call's first argument determines the group.
The legacy boolean option is also supported: true enables grouping and false disables it. Prefer the object form.
With grouping: true, split different module kinds into separate declarations:
With allowCall: true, a module factory can share a declaration with other requires:
Like upstream, locally defined functions named require are also checked. With grouping: true, require("node:fs") and require("fs/promises") belong to the package group, while require("fs") belongs to the core group.
This rule does not provide automatic fixes or suggestions.