Enforce use of defined aliases in TSConfig/JSConfig through ESLint.
- Automatic imports by tsserver resolve to relative paths that can be normalized.
- It's easier to refactor by finding and replacing an absolute module path
without worrying about crafting the regex for
../and./
- Node 14+
npm install --save-dev @limegrass/eslint-plugin-import-alias eslintThis plugin relies on an alias configuration in tsconfig.json, jsconfig.json,
or a config with the same schema and a path given as aliasConfigPath in its rules
settings. See the rules documentation for more detail.
This plugin supports multiple configuration parameters which can affect how it handles relative paths, base URLs, and more. Check the rules documentation and example configurations for more detailed configurations.
The configuration above is also equivalent to
// .eslintrc
{
"extends": [
// ... - your other extends, such as `"eslint:recommended"`
"plugin:@limegrass/import-alias/recommended",
],
}Note that while the above is for the deprecated .eslintrc format,
this package does support ESLint@^9 and its flat config format.
See the flat-config example for details.