no-restricted-imports
Configuration
rslint.config.ts
Rule Details
Disallow specified modules when loaded by import. This rule allows you to specify imports that you don't want to use in your application.
This can be useful if you want to restrict usage of certain modules, enforce alternatives, or prevent accidental use of deprecated APIs.
Examples of incorrect code for this rule with ["error", "fs"]:
Examples of correct code for this rule with ["error", "fs"]:
Options
The rule accepts either an array of strings/objects or an object with paths and patterns properties.
String format
Object format with paths and patterns
Path options
name(required): The module name to restrictmessage: Custom message to displayimportNames: Restrict specific named exportsallowImportNames: Allow only specified named exportsallowTypeImports: Allow type-only imports (TypeScript)
Pattern options
group: Gitignore-style patternsregex: Regular expression patternmessage: Custom message to displaycaseSensitive: Case-sensitive matching (default: false)importNames: Restrict specific named importsimportNamePattern: Regex pattern for import namesallowImportNames: Allow only specified named importsallowImportNamePattern: Regex pattern for allowed import namesallowTypeImports: Allow type-only imports (TypeScript)