chore(biome): prep refactors toward useMaxParams max: 2#2042
Conversation
Converts several helpers across @packrat/guards, @packrat/analytics, and
@packrat/api to the "(subject, opts)" pattern in prep for tightening
Biome's useMaxParams rule from 3 to 2 in a follow-up:
- guards: assertEnum(value, { members, name })
- analytics: QueryBuilder.trendsQuery(keyword, { sites, days })
- api/utils: logAIRequest(env, { headers, log }),
getPresignedUrl(c, { command, signOptions })
- api/services: CatalogService.vectorSearch(q, { limit, offset })
Call sites (routes, AI tools, tests) updated accordingly. No behavior
or HTTP contract changes.
Converts >2-arg helpers in the guides app to "(subject, opts)" shape
in prep for tightening Biome's useMaxParams rule from 3 to 2 in a
follow-up:
- components/ui/chart: getPayloadConfigFromPayload(config, { payload, key })
- scripts/enhance-content: writeEnhancedContent / enhanceFile
- scripts/generate-content: generateTopicIdeas(count, { categories, existingContent })
Converts feature hooks with 3+ params to the "(subject, opts)" shape
in prep for tightening Biome's useMaxParams rule from 3 to 2:
- auth/useAuthActions: resetPassword(email, { code, newPassword })
- packs/useAddCatalogItem: addItemToPack(packId, { catalogItem, data })
- catalog/useSimilarItems: getSimilarPackItems / useSimilarPackItems
now take (packId, { itemId, params })
Call sites (reset-password screen, GapSuggestion, SimilarItemsForPackItem)
updated accordingly. No UI or request-shape changes.
Converts test helpers and container-side utilities with 3+ params to
the "(subject, opts)" shape, in prep for tightening Biome's
useMaxParams rule from 3 to 2 in a follow-up:
- container_src/server:
* detectMediaTypeAndExtension(response, { buffer, isVideo })
* downloadAndRehostImage(imageUrl, { contentId, index })
* waitForFileToBeActiveGoogle(ai, { fileName, maxWaitTimeMs })
- test/utils/db-helpers: seedPackTemplateItems / seedPackItems
now take (id, { count, overrides })
- test/utils/test-helpers:
* httpMethods: drop unused positional `_url` first arg
* apiWithAuth: back to (path, init?); a new apiWithAuthAs(path, { user, init })
helper covers the rare case of authenticating as a custom user
* apiWithAdmin unchanged externally
All test files updated to the new httpMethods call shape
(`httpMethods.post(body)` etc. instead of `httpMethods.post('', body)`).
|
Important Review skippedAuto reviews are disabled on base/target branches other than the default branch. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches🧪 Generate unit tests (beta)
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 |
Coverage Report for Expo Unit Tests Coverage (./apps/expo)
File CoverageNo changed files found. |
Coverage Report for API Unit Tests Coverage (./packages/api)
File CoverageNo changed files found. |
There was a problem hiding this comment.
Pull request overview
Prepares the monorepo for tightening Biome’s useMaxParams rule to max: 2 by refactoring targeted functions to the canonical (subject, opts) signature shape and updating call sites accordingly (no intended runtime/contract changes).
Changes:
- Refactored several helpers/services/hooks to accept an
optsobject instead of multiple positional params. - Updated API routes, AI tool plumbing, and a broad set of tests to match the new call signatures.
- Adjusted test helper utilities (
httpMethods, auth request helpers) to reduce parameter counts.
Reviewed changes
Copilot reviewed 32 out of 32 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| packages/guards/src/enum.ts | Refactors assertEnum to accept { members, name? } options object. |
| packages/api/test/utils/test-helpers.ts | Introduces fetchWithUser / apiWithAuthAs and drops unused _url arg from httpMethods. |
| packages/api/test/utils/db-helpers.ts | Refactors seedPackTemplateItems/seedPackItems to (id, opts) signature. |
| packages/api/test/upload.test.ts | Updates httpMethods calls to new signatures. |
| packages/api/test/packs.test.ts | Updates httpMethods calls to new signatures. |
| packages/api/test/pack-templates.test.ts | Updates seeding helper call to new (id, opts) signature and httpMethods usage. |
| packages/api/test/image-detection.test.ts | Updates httpMethods.post calls to new signature. |
| packages/api/test/guides.test.ts | Updates httpMethods.get calls to new signature. |
| packages/api/test/generate-from-online-content.test.ts | Updates httpMethods.post calls to new signature. |
| packages/api/test/chat.test.ts | Updates httpMethods.post calls to new signature. |
| packages/api/test/catalog.test.ts | Updates httpMethods calls to new signatures. |
| packages/api/test/auth.test.ts | Switches custom-user auth request to apiWithAuthAs and updates httpMethods usage. |
| packages/api/src/utils/getPresignedUrl.ts | Refactors getPresignedUrl to accept { command, signOptions }. |
| packages/api/src/utils/ai/tools.ts | Updates CatalogService.vectorSearch call to pass { limit, offset }. |
| packages/api/src/utils/ai/logging.ts | Refactors logAIRequest to accept { headers, log }. |
| packages/api/src/services/catalogService.ts | Refactors vectorSearch(q, opts) with defaults from opts. |
| packages/api/src/services/tests/catalogService.test.ts | Updates vectorSearch unit test calls to new (q, opts) signature. |
| packages/api/src/routes/upload.ts | Updates getPresignedUrl invocation to { command, signOptions }. |
| packages/api/src/routes/packs/analyzeImage.ts | Updates getPresignedUrl invocation to { command, signOptions }. |
| packages/api/src/routes/catalog/vectorSearchRoute.ts | Updates vectorSearch invocation to { limit, offset }. |
| packages/api/container_src/server.ts | Refactors several internal helpers to (subject, opts) shape and updates call sites. |
| packages/analytics/src/core/query-builder.ts | Refactors trendsQuery(keyword, opts) and applies defaults from opts. |
| packages/analytics/test/core/query-builder.test.ts | Updates trendsQuery call to pass { days }. |
| apps/guides/scripts/generate-content.ts | Refactors generateTopicIdeas(count, opts) and updates call sites. |
| apps/guides/scripts/enhance-content.ts | Refactors writeEnhancedContent/enhanceFile to accept opts objects and updates usage. |
| apps/guides/components/ui/chart.tsx | Refactors getPayloadConfigFromPayload to accept { payload, key }. |
| apps/expo/features/packs/hooks/useAddCatalogItem.ts | Refactors addItemToPack(packId, opts) signature. |
| apps/expo/features/packs/components/SimilarItemsForPackItem.tsx | Updates useSimilarPackItems call to new (packId, opts) signature. |
| apps/expo/features/packs/components/GapSuggestion.tsx | Updates addItemToPack call to { catalogItem, data } options object. |
| apps/expo/features/catalog/hooks/useSimilarItems.ts | Refactors getSimilarPackItems/useSimilarPackItems to accept opts. |
| apps/expo/features/auth/hooks/useAuthActions.ts | Refactors resetPassword(email, opts) signature. |
| apps/expo/app/auth/(login)/reset-password.tsx | Updates reset-password screen call site to { code, newPassword } opts. |
| const fetchWithUser = async ( | ||
| path: string, | ||
| init?: RequestInit, | ||
| user: typeof TEST_USER | typeof TEST_ADMIN = TEST_USER, | ||
| opts: { user: typeof TEST_USER | typeof TEST_ADMIN; init?: RequestInit }, | ||
| ) => { | ||
| const { user, init } = opts; |
There was a problem hiding this comment.
fetchWithUser (and apiWithAuthAs) only accepts typeof TEST_USER | typeof TEST_ADMIN, which forces callers that use createTestUser() to use unsafe casts (see auth.test.ts). Consider widening the accepted type to the minimal shape needed to sign the JWT (e.g., { id: number; role: 'USER' | 'ADMIN' }) so tests can pass real DB users without as casts.
Deploying packrat-guides with
|
| Latest commit: |
4a36fb1
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://00a0bac3.packrat-guides-6gq.pages.dev |
| Branch Preview URL: | https://chore-biome-max-params-2.packrat-guides-6gq.pages.dev |
Makes "one positional + one typed options object" the canonical function shape for new code. Follows #2042 (which did the bulk of the refactoring prep work) and the preceding overrides / trail-conditions refactor in this branch. Framework-required signatures remain exempted via the overrides added in the prior commit.
chore(biome): prep refactors toward useMaxParams max: 2
Makes "one positional + one typed options object" the canonical function shape for new code. Follows #2042 (which did the bulk of the refactoring prep work) and the preceding overrides / trail-conditions refactor in this branch. Framework-required signatures remain exempted via the overrides added in the prior commit.
Summary
Prep work toward tightening Biome's
useMaxParamsrule frommax: 3to
max: 2. Refactors 14 functions across the monorepo frompositional args to the canonical
(subject, opts)shape so that afollow-up PR can flip the rule.
The rule itself is NOT flipped in this PR — see Why not flip the rule now below.
Follows #1953, which introduced the rule at
max: 3.Refactored functions
packages/guardsassertEnum(value, { members, name })packages/analyticsQueryBuilder.trendsQuery(keyword, { sites, days })packages/apilogAIRequest(env, { headers, log })getPresignedUrl(c, { command, signOptions })CatalogService.vectorSearch(q, { limit, offset })detectMediaTypeAndExtension(response, { buffer, isVideo })(container_src)downloadAndRehostImage(imageUrl, { contentId, index })(container_src)waitForFileToBeActiveGoogle(ai, { fileName, maxWaitTimeMs })(container_src)seedPackTemplateItems(packTemplateId, { count, overrides })(test utils)seedPackItems(packId, { count, overrides })(test utils)httpMethods.{get,post,put,patch,delete}: dropped the unused positional_urlfirst argapiWithAuth(path, init?)kept as-is; custom-user case moved to a newapiWithAuthAs(path, { user, init })helperapps/guidesgetPayloadConfigFromPayload(config, { payload, key })(chart.tsx)writeEnhancedContent(filePath, { metadata, enhancedContent })enhanceFile(filePath, { cliOptions, enhancementOptions })generateTopicIdeas(count, { categories, existingContent })apps/exporesetPassword(email, { code, newPassword })(auth hook)addItemToPack(packId, { catalogItem, data })(packs hook)getSimilarPackItems(packId, { itemId, params })(catalog hook)useSimilarPackItems(packId, { itemId, params })(catalog hook)All call sites (routes, AI tools, components, screens, tests) updated. No
HTTP contract, UI, or runtime-behavior changes.
Why max: 2
At
max: 2the canonical shape becomesfn(subject, { options }), which:Why not flip the rule now
At
max: 2, biome reports 34 violations across 25 files. 13 of those(in 10 files) cannot be refactored without violating external
contracts:
atomWithAsyncStorage,atomWithKvStorage,atomWithSecureStorage,locationsAtoms) — Jotai's write atomsignature is
(get, set, update) => void, dictated by the library.basicAuthmiddleware (admin/index.ts) — theverifyUser(username, password, c)callback is prescribed byhono/basic-auth.R2Bucket(services/r2-bucket.tsx2) —put(key, value, options)anduploadPart(key, uploadId, partNumber)arepart of the R2 binding interface.
Array.reducecallback (services/etl/processCatalogEtl.ts) —(acc, header, idx) => ...is the stdlib reduce signature.test/guides.test.ts,test/setup.ts) —mirror the R2 binding signature above.
apps/expo/utils/weight.ts,packages/api/src/utils/weight.ts): 24 call sites monorepo-wide —out of scope for this PR.
This PR lands the refactor-only piece so the follow-up that flips the
rule can focus solely on the config change + whatever Biome overrides
(per-path
useMaxParams: off) are needed for the external-contractcases above.
Test plan
bun biome checkclean atmax: 3tsc --noEmitclean across the monorepobun lintclean (no new errors introduced; existing warnings unchanged)@packrat/api(uses the refactoredapiWithAuth/httpMethods)@packrat/analytics(trendsQuery)🤖 Generated with Claude Code