-
-
Notifications
You must be signed in to change notification settings - Fork 56
refactor: migrate to @ and # path aliases, replace tsx with vite-node #1733
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,157 @@ | ||
| # Import Paths Convention | ||
|
|
||
| This monorepo uses TypeScript `paths` to provide clean, stable import aliases. Instead of relying on brittle relative paths like `../../utils/create-rule`, use the aliases defined in each package's `tsconfig.json`. | ||
|
|
||
| ## Table of Contents | ||
|
|
||
| - [Overview](#overview) | ||
| - [`@` — Package Source Root](#-package-source-root) | ||
| - [`#` — Workspace Root](#-workspace-root) | ||
| - [Configuration](#configuration) | ||
| - [Examples](#examples) | ||
| - [FAQ](#faq) | ||
|
|
||
| ## Overview | ||
|
|
||
| | Alias | Target | Purpose | | ||
| | ----- | --------- | ---------------------------------------------------------------------- | | ||
| | `@` | `./src` | Import from the current package's source directory. | | ||
| | `@/*` | `./src/*` | Import a sub-module from the current package's source directory. | | ||
| | `#` | `../..` | Import from the workspace root (shared utilities, test helpers, etc.). | | ||
| | `#/*` | `../../*` | Import a sub-module from the workspace root. | | ||
|
|
||
| ## `@` — Package Source Root | ||
|
|
||
| Use `@` whenever you need to reference a module inside the **current package's `src/` directory**. | ||
|
|
||
| This eliminates the need to count `../` segments and makes refactorings (moving files between directories) much safer. | ||
|
|
||
| ```ts | ||
| // ❌ Avoid — breaks when the file is moved | ||
| import { createRule } from "../../utils/create-rule"; | ||
|
|
||
| // ✅ Preferred — stable regardless of file depth | ||
| import { createRule } from "@/utils/create-rule"; | ||
| ``` | ||
|
|
||
| ### Where it resolves | ||
|
|
||
| In every package under `packages/*` and `plugins/*`, `@` is mapped to that package's own `src/` folder: | ||
|
|
||
| ```json | ||
| { | ||
| "compilerOptions": { | ||
| "paths": { | ||
| "@": ["./src"], | ||
| "@/*": ["./src/*"] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## `#` — Workspace Root | ||
|
|
||
| Use `#` when you need to reference a module at the **monorepo root** (e.g. shared test helpers in `test/`, build scripts, or workspace-wide types). | ||
|
|
||
| ```ts | ||
| // ❌ Avoid — fragile and hard to read | ||
| import { ruleTester } from "../../../../../test"; | ||
|
|
||
| // ✅ Preferred — always points to the workspace root | ||
| import { ruleTester } from "#/test"; | ||
| ``` | ||
|
|
||
| ### Where it resolves | ||
|
|
||
| In each package, `#` is mapped two levels up (`../..`) to reach the workspace root: | ||
|
|
||
| ```json | ||
| { | ||
| "compilerOptions": { | ||
| "paths": { | ||
| "#": ["../.."], | ||
| "#/*": ["../../*"] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| The workspace root `tsconfig.json` also defines `#` for root-level files: | ||
|
|
||
| ```json | ||
| { | ||
| "compilerOptions": { | ||
| "paths": { | ||
| "#": ["."], | ||
| "#/*": ["./*"] | ||
| } | ||
| } | ||
| } | ||
| ``` | ||
|
|
||
| ## Configuration | ||
|
|
||
| ### Per-package `tsconfig.json` | ||
|
|
||
| Every plugin and package must declare both aliases in its local `tsconfig.json`: | ||
|
|
||
| ```json | ||
| { | ||
| "extends": ["@local/configs/tsconfig.base.json"], | ||
| "compilerOptions": { | ||
| "paths": { | ||
| "@": ["./src"], | ||
| "#": ["../.."], | ||
| "@/*": ["./src/*"], | ||
| "#/*": ["../../*"] | ||
| } | ||
| }, | ||
| "include": ["src"] | ||
| } | ||
| ``` | ||
|
|
||
| ### Vitest support | ||
|
|
||
| Vitest is configured to resolve these aliases via `resolve.tsconfigPaths: true` in `vitest.config.ts`, so tests run with the same mappings as the TypeScript compiler. | ||
|
|
||
| ## Examples | ||
|
|
||
| ### Inside a plugin rule implementation | ||
|
|
||
| ```ts | ||
| // plugins/eslint-plugin-react-x/src/rules/no-missing-key/no-missing-key.ts | ||
| import { createRule } from "@/utils/create-rule"; | ||
| import { getSettings } from "@/utils/get-settings"; | ||
| ``` | ||
|
|
||
| ### Inside a plugin test file | ||
|
|
||
| ```ts | ||
| // plugins/eslint-plugin-react-x/src/rules/no-missing-key/no-missing-key.spec.ts | ||
| import { ruleTester } from "#/test"; | ||
| import { createRule } from "@/utils/create-rule"; | ||
| ``` | ||
|
|
||
| ### Inside a package source file | ||
|
|
||
| ```ts | ||
| // packages/ast/src/compare.ts | ||
| import { isTypeExpression } from "@/check"; | ||
| ``` | ||
|
|
||
| ## FAQ | ||
|
|
||
| ### Why not use `~` or `#` for package-local imports? | ||
|
|
||
| We follow the convention where `@` represents the **current package scope** (similar to many Vite / Next.js setups) and `#` represents the **workspace scope**. This keeps the mental model simple: | ||
|
|
||
| - `@/*` = "inside this package" | ||
| - `#/*` = "inside the whole repo" | ||
|
|
||
| ### What about `packages/` that import each other? | ||
|
|
||
| Cross-package imports should still use the real package name (e.g. `@eslint-react/ast`, `@eslint-react/core`). `paths` aliases are only for intra-package and intra-workspace references that would otherwise require deep relative paths. | ||
|
|
||
| ### Can I use these aliases in build outputs? | ||
|
|
||
| No — these aliases are for **source code only**. The bundler (`tsdown`) is configured to resolve and inline them during the build. Consumers of the published packages never see `@/` or `#/` imports. | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
plugins/eslint-plugin-react-debug/src/rules/function-component/function-component.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
plugins/eslint-plugin-react-debug/src/rules/function-component/function-component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
4 changes: 2 additions & 2 deletions
4
plugins/eslint-plugin-react-debug/src/rules/hook/hook.spec.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.