An ESLint plugin that enforces the use of import path aliases instead of relative imports, helping maintain clean and consistent import structures in JavaScript/TypeScript projects. Version 1.2.0 is the latest stable release with no recent updates; it uses regex-based path matching to replace resolved file paths with aliases like '@src' or '@test'. Compared to similar tools like eslint-plugin-import's 'no-relative-parent-imports' rule, this plugin allows more flexible alias configuration with optional relative depth control and capture groups. It requires eslint as a peer dependency and works with both CJS and ESM configurations.
npm install eslint-plugin-import-aliasVerified import paths — ran on the pinned version, not inferred.
Shows ESLint config enabling the import-alias rule with alias configuration for '@src' and '@test'.
Ensure your regex matches the start of the resolved path (e.g., '^src' for paths like '/project/src/...').
If you want to allow same-folder imports, set relativeDepth to 1 or higher.
Use a tool like eslint-plugin-import's 'import/order' with path groups or custom codemods to auto-replace relative imports.
Use `import eslintPluginImportAlias from 'eslint-plugin-import-alias'` then spread its configs if available, or manually specify rules.
Ensure each alias object has exactly 'alias' (string) and 'matcher' (string regex).
Run `npm install --save-dev eslint-plugin-import-alias`.
Remove unknown properties; valid options are 'aliases', 'relativeDepth', and 'rootDir'.
Check that 'matcher' is a valid regex string (e.g., '^src') and that the alias object is properly formed.
Set rootDir to a valid absolute path, e.g., __dirname or process.cwd().