no-require-imports
What it does
Section titled “What it does”Reports a call of the global require(...) and an import x = require(...). A require that the file declares itself (a parameter, for example) is not reported.
Why it matters
Section titled “Why it matters”require is the CommonJS loader and is not typed like an import: the result is any unless a type is added, and bundlers and the compiler cannot always follow it. An import is checked by the type system and understood by tools.
To fix, use import.
Example
Section titled “Example”...declare module "x" {}declare global {}...const a = require("a"), b = a.require("b");import c = require("c");function local(require: (id: string) => void) { require("d"); }...Configuration
Section titled “Configuration”js: lint: rules: no-require-imports: warn # off (default), warn, errorEnabled by the presets: js/typescript-eslint-recommended.
Suppress one line with sudsy-disable-next-line no-require-imports in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| typescript-eslint | no-require-imports |
partial | the options (allow, allowAsImport) keep their defaults; a require the file declares itself is not reported |