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"),
  retries = 3;
example.jsNo problems
const fs = require("fs"),
  config = require("./config");

const retries = 3;

Options#

OptionDefaultWhat it does
groupingfalseAlso report a declaration that mixes kinds of modules: Node.js built-ins ("fs"), packages ("lodash"), files ("./config") and computed names (require(name)).
allowCallfalseCount 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 problem
const fs = require("fs"),
  config = require("./config");
example.jswith { "grouping": true }No problems
const 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 problem
const fs = require("node:fs"),
  path = require("path");

Without allowCall, this is reported:

example.js1 problem
const express = require("express"),
  log = require("debug")("app");
example.jswith { "allowCall": true }No problems
const express = require("express"),
  log = require("debug")("app");