no-mixed-requires
Disallow require calls mixed with other variables in one declaration
deprecated
A file's require calls are the list of what it depends on. When one const a = .., b = .. declaration holds both require calls and ordinary variables, that list is harder to find and to keep in order.
ESLint has deprecated this rule. Use n/no-mixed-requires instead.
Examples#
example.js1 problem
const fs = require("fs"),Do not mix require and other declarations.
retries = 3;example.jsNo problems
const fs = require("fs"),
config = require("./config");
const retries = 3;Options#
| Option | Default | What it does |
|---|---|---|
grouping | false | Also report a declaration that mixes kinds of modules: Node.js built-ins ("fs"), packages ("lodash"), files ("./config") and computed names (require(name)). |
allowCall | false | Count a module that's called right away, like require("debug")("app"), as a require and not as an ordinary variable. |
A plain true or false instead of the object sets grouping.
example.jswith
{ "grouping": true }1 problemconst fs = require("fs"),Do not mix core, module, file and computed requires.
config = require("./config");example.jswith
{ "grouping": true }No problemsconst fs = require("fs"),
path = require("path");
const config = require("./config");Built-ins are only recognized by their bare names. "node:fs" counts as a package:
example.jswith
{ "grouping": true }1 problemconst fs = require("node:fs"),Do not mix core, module, file and computed requires.
path = require("path");Without allowCall, this is reported:
example.js1 problem
const express = require("express"),Do not mix require and other declarations.
log = require("debug")("app");example.jswith
{ "allowCall": true }No problemsconst express = require("express"),
log = require("debug")("app");