ESLint plugin that autofixes relative imports to use TypeScript or JavaScript path aliases. Current stable version is 1.1.1. Released with moderate cadence; supports both ESLint 9 flat config (with typescript-eslint) and legacy ESLint 8 config. Key differentiator: auto-fixable rules that replace relative paths with configured aliases from tsconfig.json (ts-imports) or manual webpack-like alias map (js-imports), rather than just reporting violations. Requires Node >=16 and ships TypeScript types.
npm install eslint-plugin-preferred-importNo compatibility data collected yet for this library.
Verified import paths — ran on the pinned version, not inferred.
Flat ESLint 9 configuration enabling ts-imports rule to autofix relative imports to tsconfig aliases.
Ensure tsconfig has basePath and paths configured; provide project or projectService in parserOptions.
Verify that the alias resolves to the actual file; if not, the import will be incorrect after autofix.
For ESLint 9, use the flat config import and plugins object; for ESLint 8, use plugins array and overrides.
Run npm install eslint-plugin-preferred-import --save-dev.
Ensure plugin is imported and registered under the key 'preferred-import' (exact string); rules must be 'preferred-import/ts-imports'.
Use 'error' (string) is allowed? Actually ESLint flat config accepts string; if using @eslint/js, may need to use 'error' or 2. Check ESLint version.
Replace parserOptions.project with parserOptions.projectService: true in flat config.