Skip to content
← Back to rules

node/no-mixed-requires Style

What it does

Disallows require calls to be mixed with regular variable declarations.

Why is this bad?

In the Node.js community it is often customary to separate initializations with calls to require modules from other variable declarations, sometimes also grouping them by the type of module.

Examples

Examples of incorrect code for this rule:

js
var fs = require("fs"),
  i = 0;

var async = require("async"),
  debug = require("diagnostics").someFunction("my-module"),
  eslint = require("eslint");

Examples of correct code for this rule:

js
var eventEmitter = require("events").EventEmitter,
  myUtils = require("./utils"),
  util = require("util"),
  bar = require(getBarModuleName());

var foo = 42,
  bar = "baz";

Configuration

allowCall

type: boolean

default: false

grouping

type: boolean

default: false

How to use

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

json
{
  "plugins": ["node"],
  "rules": {
    "node/no-mixed-requires": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  plugins: ["node"],
  rules: {
    "node/no-mixed-requires": "error",
  },
});
bash
oxlint --deny node/no-mixed-requires --node-plugin

Version

This rule was added in vnext.

References