{"id":13142,"library":"eslint-plugin-import-typescript","title":"ESLint Plugin for TypeScript Absolute Imports","description":"This ESLint plugin automates the conversion of relative import paths to absolute or path-mapped imports within TypeScript and JavaScript projects. Currently at version 0.0.4, it's an early-stage project focused on providing auto-fixing capabilities for import path management. It directly integrates with `tsconfig.json` (or `jsconfig.json`)'s `baseUrl` and `paths` configurations, addressing a common pain point where TypeScript's compiler understands these settings but does not rewrite the import paths in the compiled output. A key differentiator is its ability to auto-fix rules like `no-relative-parent-imports`, which some other plugins might only flag. It aims to streamline the migration from relative to absolute imports, particularly as project scale increases. There is no explicit release cadence, typical for community-driven ESLint plugins.","status":"active","version":"0.0.4","language":"javascript","source_language":"en","source_url":"https://github.com/hdoan741/eslint-plugin-absolute-imports","tags":["javascript","eslint","imports","absolute","relative","eslint-plugin","typescript","paths"],"install":[{"cmd":"npm install eslint-plugin-import-typescript","lang":"bash","label":"npm"},{"cmd":"yarn add eslint-plugin-import-typescript","lang":"bash","label":"yarn"},{"cmd":"pnpm add eslint-plugin-import-typescript","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Required peer dependency for any ESLint plugin to function within an ESLint environment.","package":"eslint","optional":false}],"imports":[{"note":"When enabling the plugin in your `.eslintrc.js` or `.eslintrc.json`, ensure you use the full npm package name, including the `eslint-plugin-` prefix, in the `plugins` array.","wrong":"plugins: ['import-typescript']","symbol":"ESLint Plugin Configuration","correct":"plugins: ['eslint-plugin-import-typescript']"},{"note":"ESLint rules provided by plugins must be prefixed with the plugin's short name (e.g., `import-typescript/`) followed by the rule name.","wrong":"'no-relative-parent-imports': ['error']","symbol":"Rule: no-relative-parent-imports","correct":"'import-typescript/no-relative-parent-imports': ['error']"},{"note":"Rule options are passed as a plain JavaScript object in the second element of the rule's array configuration. Ensure correct JSON/JavaScript object literal syntax (key-value pairs separated by colons).","wrong":"'import-typescript/no-relative-parent-imports': ['error', { onlyAbsoluteImport = true }]","symbol":"Rule Options: onlyAbsoluteImport","correct":"'import-typescript/no-relative-parent-imports': ['error', { onlyAbsoluteImport: true }]"}],"quickstart":{"code":"{\n  // .eslintrc.js or .eslintrc.json\n  \"root\": true,\n  \"parser\": \"@typescript-eslint/parser\",\n  \"parserOptions\": {\n    // Point to your tsconfig.json for absolute path resolution\n    \"project\": \"./tsconfig.json\",\n    // If tsconfig.json is not in the root, specify its root directory\n    // \"tsconfigRootDir\": \"__dirname\",\n    \"ecmaVersion\": \"latest\",\n    \"sourceType\": \"module\"\n  },\n  \"plugins\": [\n    \"eslint-plugin-import-typescript\",\n    // 'eslint-plugin-import' is generally recommended for any project using imports,\n    // and is crucial for the resolver to work.\n    \"import\"\n  ],\n  \"rules\": {\n    // Enable the primary rule from this plugin to auto-fix relative parent imports.\n    'import-typescript/no-relative-parent-imports': [\n      'error',\n      // Optional: enforce only absolute imports, ignoring 'paths' in tsconfig\n      // { \"onlyAbsoluteImport\": true }\n    ],\n    // Recommended: Enforce no unresolved imports, requires 'eslint-import-resolver-typescript'.\n    'import/no-unresolved': 'error',\n    // Optional: Turn off default relative package rules if they conflict during migration\n    // 'import/no-relative-packages': 'off'\n  },\n  \"settings\": {\n    // Crucial for ESLint and eslint-plugin-import to understand TypeScript's baseUrl and paths\n    \"import/resolver\": {\n      \"typescript\": {\n        // This ensures the resolver uses your project's tsconfig for path resolution\n        \"project\": \"./tsconfig.json\"\n      },\n      // Node resolver is useful for resolving standard Node.js modules or packages\n      \"node\": {\n        \"extensions\": [\".js\", \".jsx\", \".ts\", \".tsx\"]\n      }\n    }\n  }\n}","lang":"typescript","description":"This configuration demonstrates the basic setup for `eslint-plugin-import-typescript` in a TypeScript project, enabling its `no-relative-parent-imports` rule for automatic fixing. It also includes the necessary `parserOptions` for TypeScript and `import/resolver` settings for `eslint-plugin-import` to correctly interpret `baseUrl` and `paths` from `tsconfig.json`."},"warnings":[{"fix":"Integrate `tsconfig-paths` for runtime resolution (e.g., `node -r tsconfig-paths/register your-app.js`) or `tsc-alias` into your build process (e.g., `tsc && tsc-alias`). For Jest, configure `moduleNameMapper` and potentially `tsconfig-paths` for `globalSetup` scripts.","message":"TypeScript's `baseUrl` and `paths` configurations are primarily for compile-time module resolution and do not automatically rewrite import paths in the transpiled JavaScript output. For Node.js runtime, you will need tools like `tsconfig-paths` or `tsc-alias` to make absolute imports work correctly at runtime or build time.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Install `npm install --save-dev eslint-plugin-import eslint-import-resolver-typescript` and add the `import/resolver` setting to your `.eslintrc.js` file: `settings: { 'import/resolver': { typescript: { project: './tsconfig.json' } } }`.","message":"To ensure ESLint correctly understands `paths` defined in your `tsconfig.json` (or `jsconfig.json`) and avoids 'Unable to resolve path' errors, you must install and configure `eslint-import-resolver-typescript` alongside `eslint-plugin-import`.","severity":"gotcha","affected_versions":">=0.0.1"},{"fix":"Add or verify the `baseUrl` property in your `tsconfig.json` (e.g., `compilerOptions: { 'baseUrl': '.' }`).","message":"This plugin requires `baseUrl` to be explicitly defined in your `tsconfig.json` or `jsconfig.json` for its rules to function. If `baseUrl` is missing, the plugin will not be able to resolve absolute import paths.","severity":"breaking","affected_versions":">=0.0.1"},{"fix":"Monitor the GitHub repository for updates and breaking changes. Contribute bug reports or feature requests if issues are encountered. Consider this plugin for new projects or non-critical paths until it reaches a more stable major version.","message":"As an early-stage plugin (version 0.0.4), it may have edge cases, bugs, or incomplete feature support. Users should test thoroughly and report issues. Behavior might change rapidly in pre-1.0 versions without strict adherence to semantic versioning for breaking changes.","severity":"gotcha","affected_versions":"0.x"}],"env_vars":null,"last_verified":"2026-04-19T00:00:00.000Z","next_check":"2026-07-18T00:00:00.000Z","problems":[{"fix":"Install `eslint-import-resolver-typescript` and configure it in your `.eslintrc.js` `settings['import/resolver']` to point to your `tsconfig.json`.","cause":"ESLint, specifically `eslint-plugin-import`, cannot understand TypeScript `paths` or `baseUrl` aliases without a dedicated resolver, leading to module not found errors.","error":"ESLint: Unable to resolve path to module 'src/utils/helpers'."},{"fix":"For runtime execution, use `tsconfig-paths` (e.g., `node -r tsconfig-paths/register your-app.js`). For build output, integrate `tsc-alias` into your post-compilation step (e.g., `tsc && tsc-alias`).","cause":"The TypeScript compiler understands `baseUrl` and `paths` for type checking and compilation, but Node.js runtime (or the compiled JavaScript output) does not automatically rewrite these paths by default, leading to module not found errors.","error":"Error: Cannot find module 'src/components/Button' (at runtime or during build)."},{"fix":"Install `@typescript-eslint/parser` and configure it in your `.eslintrc.js` `parser` option and `parserOptions.project` (e.g., `parser: '@typescript-eslint/parser', parserOptions: { project: './tsconfig.json' }`).","cause":"ESLint is not configured with a TypeScript-compatible parser (like `@typescript-eslint/parser`) or is not correctly linked to your project's `tsconfig.json`.","error":"Error: You have used a rule which requires a parser."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":""}