{"id":16259161,"url":"https://github.com/dword-design/eslint-plugin-import-alias","last_synced_at":"2026-01-03T02:17:15.392Z","repository":{"id":42018651,"uuid":"272398997","full_name":"dword-design/eslint-plugin-import-alias","owner":"dword-design","description":"An ESLint plugin that enforces the use of import aliases. Also supports autofixing.","archived":false,"fork":false,"pushed_at":"2025-04-10T05:10:44.000Z","size":2422,"stargazers_count":75,"open_issues_count":10,"forks_count":11,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-10T06:26:53.960Z","etag":null,"topics":["alias","aliases","autofix","babel","babel-plugin-module-resolver","enforce","eslint","fix","import","lint","module","module-resolver","nuxt","nuxtjs","plugin","prefer","replace","require","rule"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/dword-design.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"custom":["buymeacoffee.com/dword","paypal.me/SebastianLandwehr"],"github":"dword-design","patreon":"dworddesign"}},"created_at":"2020-06-15T09:39:56.000Z","updated_at":"2025-04-10T05:06:49.000Z","dependencies_parsed_at":"2024-01-22T05:31:52.722Z","dependency_job_id":"55bca8f4-b119-4fe6-a94f-0cd41e7b696c","html_url":"https://github.com/dword-design/eslint-plugin-import-alias","commit_stats":{"total_commits":252,"total_committers":12,"mean_commits":21.0,"dds":0.623015873015873,"last_synced_commit":"55956a3921c0402c640807695610f1d93bdf4038"},"previous_names":[],"tags_count":54,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dword-design%2Feslint-plugin-import-alias","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dword-design%2Feslint-plugin-import-alias/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dword-design%2Feslint-plugin-import-alias/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dword-design%2Feslint-plugin-import-alias/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dword-design","download_url":"https://codeload.github.com/dword-design/eslint-plugin-import-alias/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248597006,"owners_count":21130796,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["alias","aliases","autofix","babel","babel-plugin-module-resolver","enforce","eslint","fix","import","lint","module","module-resolver","nuxt","nuxtjs","plugin","prefer","replace","require","rule"],"created_at":"2024-10-10T16:01:10.239Z","updated_at":"2026-01-03T02:17:15.384Z","avatar_url":"https://github.com/dword-design.png","language":"JavaScript","funding_links":["buymeacoffee.com/dword","paypal.me/SebastianLandwehr","https://github.com/sponsors/dword-design","https://patreon.com/dworddesign","https://www.buymeacoffee.com/dword","https://paypal.me/SebastianLandwehr","https://www.patreon.com/dworddesign"],"categories":["TypeScript"],"sub_categories":[],"readme":"\u003c!-- TITLE/ --\u003e\n# @dword-design/eslint-plugin-import-alias\n\u003c!-- /TITLE --\u003e\n\n\u003c!-- BADGES/ --\u003e\n\u003cp\u003e\n  \u003ca href=\"https://npmjs.org/package/@dword-design/eslint-plugin-import-alias\"\u003e\n    \u003cimg\n      src=\"https://img.shields.io/npm/v/@dword-design/eslint-plugin-import-alias.svg\"\n      alt=\"npm version\"\n    \u003e\n  \u003c/a\u003e\u003cimg src=\"https://img.shields.io/badge/os-linux%20%7C%C2%A0macos%20%7C%C2%A0windows-blue\" alt=\"Linux macOS Windows compatible\"\u003e\u003ca href=\"https://github.com/dword-design/eslint-plugin-import-alias/actions\"\u003e\n    \u003cimg\n      src=\"https://github.com/dword-design/eslint-plugin-import-alias/workflows/build/badge.svg\"\n      alt=\"Build status\"\n    \u003e\n  \u003c/a\u003e\u003ca href=\"https://codecov.io/gh/dword-design/eslint-plugin-import-alias\"\u003e\n    \u003cimg\n      src=\"https://codecov.io/gh/dword-design/eslint-plugin-import-alias/branch/master/graph/badge.svg\"\n      alt=\"Coverage status\"\n    \u003e\n  \u003c/a\u003e\u003ca href=\"https://david-dm.org/dword-design/eslint-plugin-import-alias\"\u003e\n    \u003cimg src=\"https://img.shields.io/david/dword-design/eslint-plugin-import-alias\" alt=\"Dependency status\"\u003e\n  \u003c/a\u003e\u003cimg src=\"https://img.shields.io/badge/renovate-enabled-brightgreen\" alt=\"Renovate enabled\"\u003e\u003cbr/\u003e\u003ca href=\"https://gitpod.io/#https://github.com/dword-design/eslint-plugin-import-alias\"\u003e\n    \u003cimg\n      src=\"https://gitpod.io/button/open-in-gitpod.svg\"\n      alt=\"Open in Gitpod\"\n      width=\"114\"\n    \u003e\n  \u003c/a\u003e\u003ca href=\"https://www.buymeacoffee.com/dword\"\u003e\n    \u003cimg\n      src=\"https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-2.svg\"\n      alt=\"Buy Me a Coffee\"\n      width=\"114\"\n    \u003e\n  \u003c/a\u003e\u003ca href=\"https://paypal.me/SebastianLandwehr\"\u003e\n    \u003cimg\n      src=\"https://sebastianlandwehr.com/images/paypal.svg\"\n      alt=\"PayPal\"\n      width=\"163\"\n    \u003e\n  \u003c/a\u003e\u003ca href=\"https://www.patreon.com/dworddesign\"\u003e\n    \u003cimg\n      src=\"https://sebastianlandwehr.com/images/patreon.svg\"\n      alt=\"Patreon\"\n      width=\"163\"\n    \u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\u003c!-- /BADGES --\u003e\n\n\u003c!-- DESCRIPTION/ --\u003e\nAn ESLint plugin that enforces the use of import aliases. Also supports autofixing.\n\u003c!-- /DESCRIPTION --\u003e\n\nAliases are a great thing to make imports more readable and you do not have to change import paths that often when a file path is changed.\n\n```js\nimport foo from '../../model/sub/foo';\nimport bar from '../other/bar';\n```\n\nchanges to\n\n```js\nimport foo from '@/model/sub/foo';\nimport bar from '@/sub/other/bar';\n```\n\nNow what if you are in a bigger team or you have a lot of projects to update. Or you just want to make sure that everything is consistent. This is where a linter comes into the play. This rule allows you to detect inconsistent imports and even autofix them. This works by matching alias paths agains the imports and replacing the import paths with the first matching aliased path.\n\n\u003c!-- INSTALL/ --\u003e\n## Install\n\n```bash\n# npm\n$ npm install @dword-design/eslint-plugin-import-alias\n\n# Yarn\n$ yarn add @dword-design/eslint-plugin-import-alias\n```\n\u003c!-- /INSTALL --\u003e\n\n## Usage\n\nAdd the plugin to your ESLint config:\n\n```ts\n// eslint.config.ts\n\nimport { defineConfig } from 'eslint/config';\nimport importAlias from '@dword-design/import-alias';\n\nexport default defineConfig([\n  importAlias.configs.recommended,\n]);\n```\n\nOptions can be passed by setting them in the `prefer-alias` rule:\n\n```ts\n// eslint.config.ts\n\nimport { defineConfig } from 'eslint/config';\nimport importAlias from '@dword-design/import-alias';\n\nexport default defineConfig([\n  importAlias.configs.recommended,\n  {\n    rules: {\n      '@dword-design/import-alias/prefer-alias': ['error', /* options */],\n    },\n  },\n]);\n```\n\nNow you have multiple ways to tell the plugin about aliases.\n\n### `tsconfig.json` `paths` setting\n\nIf you are a TypeScript user and you have aliases configured in your `tsconfig.json` via the `paths` setting, they will automatically be loaded. You can disable this behavior by setting `shouldReadTsConfig` to `false` in the plugin options.\n\n### [babel-plugin-module-resolver](https://www.npmjs.com/package/babel-plugin-module-resolver)\n\nIf you are already using [babel-plugin-module-resolver](https://www.npmjs.com/package/babel-plugin-module-resolver), the plugin will load the Babel config and extract the `alias` and `resolvePath` options. You can disable this behavior by setting `shouldReadBabelConfig` to `false` in the plugin options.\n\n```json\n// .babelrc.json\n\n{\n  \"plugins\": {\n    [\"module-resolver\", {\n      \"alias\": {\n        \"@\": \".\",\n      },\n    }]\n  }\n}\n```\n\n### Plugin `alias` option\n\nYou can also just pass the aliases to the plugin as an option.\n\n```ts\n// eslint.config.ts\n\nimport { defineConfig } from 'eslint/config';\nimport importAlias from '@dword-design/import-alias';\n\nexport default defineConfig([\n  importAlias.configs.recommended,\n  {\n    rules: {\n      '@dword-design/import-alias/prefer-alias': [\n        'error',\n        {\n          'alias': {\n            '@': './src',\n            '@components': './src/components',\n          },\n        },\n      ],\n    },\n  },\n]);\n```\n\n## Alias resolution\n\nBy default, the plugin will convert parent paths to aliases (like `../model/foo`), but will keep subpath imports relative. You can change that to also convert subpaths to aliased imports by passing the `aliasForSubpaths` option to the rule like so:\n\n```ts\nrules: {\n  '@dword-design/import-alias/prefer-alias': ['error', { aliasForSubpaths: true }],\n}\n```\n\nAlso, inner alias paths are preferred to outer ones. Example:\n\n```ts\nrules: {\n  '@dword-design/import-alias/prefer-alias': ['error', { alias: { '@': './app', '@@': '.' }],\n}\n```\n\nIf an import resolves to a file insode `app`, `@` will be preferred over `@@` although both aliases match. This is convenient for the use case where you have a lot of aliases for top-level folders like `components`, `utils` etc where you usually want those instead of a generic root alias. If you have other use cases, please let me know.\n\n\u003c!-- LICENSE/ --\u003e\n## Contribute\n\nAre you missing something or want to contribute? Feel free to file an [issue](https://github.com/dword-design/eslint-plugin-import-alias/issues) or a [pull request](https://github.com/dword-design/eslint-plugin-import-alias/pulls)! ⚙️\n\n## Support\n\nHey, I am Sebastian Landwehr, a freelance web developer, and I love developing web apps and open source packages. If you want to support me so that I can keep packages up to date and build more helpful tools, you can donate here:\n\n\u003cp\u003e\n  \u003ca href=\"https://www.buymeacoffee.com/dword\"\u003e\n    \u003cimg\n      src=\"https://www.buymeacoffee.com/assets/img/guidelines/download-assets-sm-2.svg\"\n      alt=\"Buy Me a Coffee\"\n      width=\"114\"\n    \u003e\n  \u003c/a\u003e\u0026nbsp;If you want to send me a one time donation. The coffee is pretty good 😊.\u003cbr/\u003e\n  \u003ca href=\"https://paypal.me/SebastianLandwehr\"\u003e\n    \u003cimg\n      src=\"https://sebastianlandwehr.com/images/paypal.svg\"\n      alt=\"PayPal\"\n      width=\"163\"\n    \u003e\n  \u003c/a\u003e\u0026nbsp;Also for one time donations if you like PayPal.\u003cbr/\u003e\n  \u003ca href=\"https://www.patreon.com/dworddesign\"\u003e\n    \u003cimg\n      src=\"https://sebastianlandwehr.com/images/patreon.svg\"\n      alt=\"Patreon\"\n      width=\"163\"\n    \u003e\n  \u003c/a\u003e\u0026nbsp;Here you can support me regularly, which is great so I can steadily work on projects.\n\u003c/p\u003e\n\nThanks a lot for your support! ❤️\n\n## License\n\n[MIT License](https://opensource.org/license/mit/) © [Sebastian Landwehr](https://sebastianlandwehr.com)\n\u003c!-- /LICENSE --\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdword-design%2Feslint-plugin-import-alias","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdword-design%2Feslint-plugin-import-alias","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdword-design%2Feslint-plugin-import-alias/lists"}