Added ESLint rule to enforce path aliases over relative imports#25355
Added ESLint rule to enforce path aliases over relative imports#25355
Conversation
|
Note Other AI code review bot(s) detectedCodeRabbit has detected other AI code review bot(s) in this pull request and will avoid duplicating their findings in the review comments. This may lead to a less comprehensive review. WalkthroughAdds the ESLint plugin Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
📜 Recent review detailsConfiguration used: CodeRabbit UI Review profile: CHILL Plan: Pro ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
🚧 Files skipped from review as they are similar to previous changes (1)
🧰 Additional context used🧠 Learnings (1)📓 Common learnings⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
🔇 Additional comments (1)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #25355 +/- ##
==========================================
+ Coverage 72.10% 72.15% +0.04%
==========================================
Files 1515 1515
Lines 115104 115109 +5
Branches 13781 13790 +9
==========================================
+ Hits 82995 83053 +58
+ Misses 31096 31042 -54
- Partials 1013 1014 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
This PR is being reviewed by Cursor Bugbot
Details
Your team is on the Bugbot Free tier. On this plan, Bugbot will review limited PRs each billing cycle for each member of your team.
To receive Bugbot reviews on all of your PRs, visit the Cursor dashboard to activate Pro and start your 14-day free trial.
| rules: { | ||
| 'no-relative-import-paths/no-relative-import-paths': [ | ||
| 'error', | ||
| { allowSameFolder: true, rootDir: 'src', prefix: '@' }, |
There was a problem hiding this comment.
Bug: Mismatched Path Aliases Break ESLint/TS Imports
The ESLint configuration enforces path aliases with prefix: '@' and rootDir: 'src', but there are no corresponding TypeScript path aliases configured in tsconfig.app.json or tsconfig.json. This will cause ESLint to enforce and auto-fix imports to use @/* aliases that are not recognized by TypeScript or the build system, resulting in broken imports and compilation errors. The TypeScript configuration needs to include a paths section mapping @/* to ./src/* (similar to apps/shade, apps/activitypub, and apps/admin-x-settings).
There was a problem hiding this comment.
Actionable comments posted: 1
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
⛔ Files ignored due to path filters (1)
yarn.lockis excluded by!**/yarn.lock,!**/*.lock
📒 Files selected for processing (2)
apps/admin/eslint.config.js(3 hunks)apps/admin/package.json(1 hunks)
🧰 Additional context used
🧠 Learnings (4)
📓 Common learnings
Learnt from: CR
Repo: TryGhost/Ghost PR: 0
File: apps/shade/AGENTS.md:0-0
Timestamp: 2025-10-15T07:53:49.814Z
Learning: Applies to apps/shade/**/*.{ts,tsx,js} : Use the @ alias for internal imports (e.g., @/lib/utils)
Learnt from: CR
Repo: TryGhost/Ghost PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-09T17:25:12.439Z
Learning: Applies to apps/@(admin-x-*,posts)/** : Admin UI new features must be implemented in React under apps/admin-x-* or apps/posts
Learnt from: CR
Repo: TryGhost/Ghost PR: 0
File: AGENTS.md:0-0
Timestamp: 2025-10-09T17:25:12.439Z
Learning: Applies to apps/@(admin-x-*,posts)/**/*.{ts,tsx,js,jsx} : Avoid admin-x-design-system for new Admin UI work (legacy, being phased out)
Learnt from: CR
Repo: TryGhost/Ghost PR: 0
File: apps/shade/AGENTS.md:0-0
Timestamp: 2025-10-15T07:53:49.814Z
Learning: Applies to apps/shade/**/* : Follow ESLint and tailwindcss/* rules
📚 Learning: 2025-10-15T07:53:49.814Z
Learnt from: CR
Repo: TryGhost/Ghost PR: 0
File: apps/shade/AGENTS.md:0-0
Timestamp: 2025-10-15T07:53:49.814Z
Learning: Applies to apps/shade/**/*.{ts,tsx,js} : Use the @ alias for internal imports (e.g., @/lib/utils)
Applied to files:
apps/admin/eslint.config.js
📚 Learning: 2025-10-15T07:53:49.814Z
Learnt from: CR
Repo: TryGhost/Ghost PR: 0
File: apps/shade/AGENTS.md:0-0
Timestamp: 2025-10-15T07:53:49.814Z
Learning: Applies to apps/shade/test/unit/**/*.test.@(ts|tsx|js) : Unit tests live under test/unit with *.test.(ts|tsx|js) naming
Applied to files:
apps/admin/eslint.config.js
📚 Learning: 2025-10-15T07:53:49.814Z
Learnt from: CR
Repo: TryGhost/Ghost PR: 0
File: apps/shade/AGENTS.md:0-0
Timestamp: 2025-10-15T07:53:49.814Z
Learning: Applies to apps/shade/**/* : Follow ESLint and tailwindcss/* rules
Applied to files:
apps/admin/eslint.config.js
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: Cursor Bugbot
- GitHub Check: E2E Tests (Shard 2/2)
- GitHub Check: E2E Tests (Shard 1/2)
🔇 Additional comments (3)
apps/admin/eslint.config.js (2)
7-7: LGTM! Plugin import and registration.The plugin import and registration follow the correct ESLint flat config format.
Also applies to: 19-21
31-40: LGTM! Correct configuration for src files.The rule configuration correctly enforces
@/*aliases for src files with auto-fix support. TheallowSameFolder: trueoption provides reasonable flexibility for same-directory imports.apps/admin/package.json (1)
30-30: No issues found. The dependency version is current and secure.The version ^1.6.1 is the latest available on npm, and there are no known security vulnerabilities for this package. The dependency addition is correct and safe to merge.
ref https://linear.app/ghost/issue/BER-2610 - Configured no-relative-import-paths ESLint plugin - Enforces use of @ aliases instead of relative imports in src/ - Enforces use of @test-utils/* instead of relative imports in test-utils/ - Allows same-folder relative imports for convenience
54b7d1a to
0879916
Compare
…host#25355) ref https://linear.app/ghost/issue/BER-2610 Adds linting rule to not allow relative imports unless its a sibling or sub directory.
ref https://linear.app/ghost/issue/BER-2610
Why are we making this change?
As part of the Ember → React migration, we're adding new React code to
apps/admin. We've configured TypeScript path aliases (@/*for src,@test-utils/*for test-utils) to improve code readability and maintainability.However, developers can still write relative imports (
../../utils/foo) even when path aliases are available. This PR enforces the use of path aliases through ESLint to ensure consistency across the codebase.What does this PR do?
Adds
eslint-plugin-no-relative-import-pathstoapps/admin/package.jsonConfigures ESLint rules in
apps/admin/eslint.config.js:src/**/*.{ts,tsx}: Enforces@/*aliases, allows same-folder relative importstest-utils/**/*.{ts,tsx}: Enforces use of aliases, allows same-folder relative importsUpdates
yarn.lockwith the new dependencyWhy is this needed?
@/utils/foois clearer than../../../utils/fooExample
Note
Enforces path alias imports in
apps/adminby adding and configuringeslint-plugin-no-relative-import-paths.eslint-plugin-no-relative-import-pathsand register it ineslint.config.js.src/**/*.{ts,tsx}: Enforce alias imports with{ rootDir: 'src', prefix: '@', allowSameFolder: true }.test-utils/**/*.{ts,tsx}: Enforce no relative imports (allow same-folder).eslint-plugin-no-relative-import-pathstodevDependenciesand updateyarn.lock.Written by Cursor Bugbot for commit 0879916. This will update automatically on new commits. Configure here.