# eslint-plugin-prefer-ts-paths

> ESLint plugin that prefer TS paths over relative imports

Latest version **1.0.1** (published 2023-10-08) · MIT license · 0 weekly downloads

## Install

```sh
npm install eslint-plugin-prefer-ts-paths
pnpm add eslint-plugin-prefer-ts-paths
yarn add eslint-plugin-prefer-ts-paths
bun add eslint-plugin-prefer-ts-paths
```

## Health

**Score 25/100 (F)** — status: abandoned.

Positive: has types; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.1 |
| Published | 2023-10-08 |
| First published | 2023-10-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | CommonJS |
| Dependencies | 0 |
| Unpacked size | 13 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 0 |
| Author | kanevnik |
| Maintainers | kanevnik |
| Keywords | eslint, typescript, example |

## Links

- npm: https://www.npmjs.com/package/eslint-plugin-prefer-ts-paths
- Repository: https://github.com/kanevnik/eslint-plugin-perfer-ts-paths
- Homepage: https://github.com/kanevnik/eslint-plugin-perfer-ts-paths#readme
- Issues: https://github.com/kanevnik/eslint-plugin-perfer-ts-paths/issues
- npm.io page: https://npm.io/package/eslint-plugin-prefer-ts-paths

## Alternatives

- [eslint-plugin-sonarjs](https://npm.io/package/eslint-plugin-sonarjs.md) — 2.9M weekly downloads
- [eslint-config-expo](https://npm.io/package/eslint-config-expo.md) — 1.5M weekly downloads
- [@matter/protocol](https://npm.io/package/@matter/protocol.md) — 63.5K weekly downloads
- [@eventcatalog/linter](https://npm.io/package/@eventcatalog/linter.md) — 24.8K weekly downloads
- [@pandacss/eslint-plugin](https://npm.io/package/@pandacss/eslint-plugin.md) — 18.7K weekly downloads

## Recent versions

- 1.0.1 (latest) — 2023-10-08

## README

# ESLint `use-import-alias` Rule

This ESLint rule helps enforce the usage of alias imports instead of relative imports for specified paths, keeping your codebase clean and consistent.

### 🛠️ Installation & Set Up

Before utilizing this rule, ensure you've configured TypeScript paths. For example:

```json
// tsconfig.json
{
  "compilerOptions": {
    "baseUrl": ".",
    "paths": {
      "@components/*": ["src/components/*"],
      "@models/*": ["src/models/*"],
      "@utils/*": ["src/utils/*"]
    }
  }
}
```

🔗 Refer to [TypeScript Module Resolution](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping) for detailed guidance.

### 🚀 Usage

This rule requires you to provide an array of strings, each being a path that the rule should check.

For instance:

```json
// .eslintrc.json
{
  "rules": {
    "your-plugin-name/use-import-alias": ["error", ["components", "utils", "models"]]
  }
}
```

### 📘 Example

Given the configuration above, this ESLint rule will:

❌ Flag as error:

```typescript
import Button from "../components/Button";
import Model from "../../models/Model";
```

✅ Auto-fix to:

```typescript
import Button from "@components/Button";
import Model from "@models/Model";
```

### 🧪 Testing the Rule

In the project, we also provide test cases to ensure the rule behaves as expected.

Example test:

```typescript
import { RuleTester } from "eslint";
import rule from "./use-import-alias";

// ... [rest of the test code]
```

### ⚖️ Configurability

This rule is designed to be flexible and adaptable to various project structures. Simply provide the array of paths as per your project’s structure and needs.

### 💼 Use Case

- Ensure clean import statements throughout your codebase.
- Enforce a consistent use of TypeScript path aliases.
- Reduce the hassle in updating paths during refactors or directory changes.

### 📚 Further Reading

- [ESLint Rules](https://eslint.org/docs/rules/)
- [TypeScript Path Mappings](https://www.typescriptlang.org/docs/handbook/module-resolution.html#path-mapping)

### 🙌 Contributing

Feel free to open issues or PRs if you find a bug or see potential improvements!

### 📃 License

This project is open-source and available under [MIT License](LICENSE).

---
_Source: https://npm.io/package/eslint-plugin-prefer-ts-paths · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
