Back to all reviewers

Use parameter-based paths

supabase/supabase
Based on 3 comments
TSX

When designing API routes and interfaces, always use parameter-based path syntax instead of hardcoded literals. This approach provides better flexibility, improved type safety, and allows for more reusable code. Additionally, always validate parameters before using them in routes or API calls to prevent undefined reference errors.

API TSX

Reviewer Prompt

When designing API routes and interfaces, always use parameter-based path syntax instead of hardcoded literals. This approach provides better flexibility, improved type safety, and allows for more reusable code. Additionally, always validate parameters before using them in routes or API calls to prevent undefined reference errors.

Example of proper path parameterization:

// Incorrect - using literal values
path: '/platform/projects/default/analytics/endpoints/logs.all'

// Correct - using parameter syntax
path: '/platform/projects/:ref/analytics/endpoints/logs.all'

Example of proper parameter validation:

// Incorrect - not validating parameter before use
if (slug === 'last-visited-org') {
  router.replace(`/new/${lastVisitedOrganization}`)
}

// Correct - validating parameter existence
if (slug === 'last-visited-org' && !!lastVisitedOrganization) {
  router.replace(`/new/${lastVisitedOrganization}`)
}

This approach also enhances API flexibility by supporting optional parameters, allowing consumers to provide only what they need. When designing component APIs, consider parameterizing inputs to increase reusability across different contexts.

3
Comments Analyzed
TSX
Primary Language
API
Category

Source Discussions