Skip to content

ci: enforce route constants via ESLint and CodeRabbit#2781

Open
Logvin wants to merge 1 commit intoseerr-team:developfrom
Logvin:ci/enforce-route-constants
Open

ci: enforce route constants via ESLint and CodeRabbit#2781
Logvin wants to merge 1 commit intoseerr-team:developfrom
Logvin:ci/enforce-route-constants

Conversation

@Logvin
Copy link
Copy Markdown

@Logvin Logvin commented Mar 30, 2026

Summary

  • Adds an ESLint no-restricted-syntax rule that flags hardcoded /api/v1 string literals in src/ and server/ (excluding the constant definition files)
  • Adds .coderabbit.yaml with path instructions so CodeRabbit flags hardcoded route paths during review

This is a companion to #2762 (route constants refactor). Once that PR lands, these guardrails prevent the hardcoded paths from being reintroduced.

Why

PR #2762 replaces 201 hardcoded /api/v1 occurrences across 73 files with centralized constants. Without enforcement, new code will inevitably reintroduce hardcoded paths. These two lightweight checks catch it at dev time (ESLint, pre-commit hook) and at review time (CodeRabbit).

What changed

  • eslint.config.mts — Two new config blocks with no-restricted-syntax:
    • src/**/*.{ts,tsx} (excludes src/utils/apiUrl.ts): "Use apiUrl() from @app/utils/apiUrl"
    • server/**/*.ts (excludes server/constants/routes.ts): "Use API_BASE_PATH from @server/constants/routes"
  • .coderabbit.yaml — Path instructions for src/, server/index.ts, and server/routes/

Notes

Test plan

  • npx eslint src/components/TitleCard/index.tsx flags all 8 hardcoded /api/v1 paths
  • ESLint config loads without errors
  • Constant definition files (src/utils/apiUrl.ts, server/constants/routes.ts) are excluded
  • Verify CodeRabbit picks up .coderabbit.yaml instructions on future PRs

AI Disclosure: This PR was developed with Claude Code as a pair programming tool. I directed the approach, reviewed the config changes, and verified the ESLint rule behavior. I'm the author, Claude is my editor.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Established automated code quality checks to ensure consistent API path patterns are used throughout the codebase, enhancing maintainability and reducing configuration errors.

Add guardrails to prevent hardcoded /api/v1 paths from being
reintroduced after the route constants refactor (seerr-team#2762):

- ESLint no-restricted-syntax rule flags hardcoded /api/v1 in src/
  and server/ (excluding the constant definition files)
- CodeRabbit path instructions for src/, server/index.ts, and
  server/routes/ to flag hardcoded paths during review

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@Logvin Logvin requested a review from a team as a code owner March 30, 2026 02:04
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 30, 2026

Warning

Ignoring CodeRabbit configuration file changes. For security, only the configuration from the base branch is applied for open source repositories.

📝 Walkthrough

Walkthrough

This PR adds configuration-based enforcement for consistent API path handling. It extends code review instructions and ESLint rules to require client code use the apiUrl() helper function and server code use route constants instead of hardcoded API path strings.

Changes

Cohort / File(s) Summary
Configuration & Linting Rules
.coderabbit.yaml, eslint.config.mts
Adds code review path-specific instructions and ESLint rules to enforce API path patterns: client-side code must use apiUrl() helper instead of hardcoded /api/v1, and server-side code must reference route constants from server/constants/routes.ts.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

🐰 Paths once scattered, now we gather,
Constants guide where hardcodes chatter,
From /api/v1 to helpers bright,
Consistency hops into the night!

🚥 Pre-merge checks | ✅ 2
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'ci: enforce route constants via ESLint and CodeRabbit' accurately and concisely summarizes the main change: adding enforcement mechanisms to prevent hardcoded route constants through CI tooling.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
.coderabbit.yaml (1)

3-7: Add an explicit exception instruction for src/utils/apiUrl.ts.

Line 3’s src/** guidance will also target the canonical helper file itself, which can create avoidable false-positive review comments.

🧭 Suggested adjustment
 reviews:
   path_instructions:
+    - path: 'src/utils/apiUrl.ts'
+      instructions: |
+        '/api/v1' is allowed here as the canonical API base helper definition.
     - path: 'src/**'
       instructions: |
         Flag any hardcoded '/api/v1' string literals in client code.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In @.coderabbit.yaml around lines 3 - 7, The global rule that flags hardcoded
'/api/v1' in 'src/**' is also catching the canonical helper itself; update the
config to exempt the helper by excluding or adding an exception for
src/utils/apiUrl.ts so the linter/qa rule does not flag that file; specifically
adjust the 'src/**' rule to add an exclude pattern or explicit exception for the
file path (src/utils/apiUrl.ts) while leaving the rest of the pattern intact.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In @.coderabbit.yaml:
- Around line 3-7: The global rule that flags hardcoded '/api/v1' in 'src/**' is
also catching the canonical helper itself; update the config to exempt the
helper by excluding or adding an exception for src/utils/apiUrl.ts so the
linter/qa rule does not flag that file; specifically adjust the 'src/**' rule to
add an exclude pattern or explicit exception for the file path
(src/utils/apiUrl.ts) while leaving the rest of the pattern intact.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: f4a28fdd-ed07-4d72-aa57-e890b6495da1

📥 Commits

Reviewing files that changed from the base of the PR and between 993ae4c and b86063f.

📒 Files selected for processing (2)
  • .coderabbit.yaml
  • eslint.config.mts

@Logvin
Copy link
Copy Markdown
Author

Logvin commented Mar 30, 2026

CodeRabbit flagged that the src/** path instruction in .coderabbit.yaml would also match src/utils/apiUrl.ts (the canonical helper where /api/v1 is defined). The ESLint rule already excludes that file, so there's no practical effect... but I can add an explicit exception in the yaml for consistency if folks think it's worth it. Happy to push that or leave it as-is.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant