Skip to content

chore(biome): prep refactors toward useMaxParams max: 2#2042

Merged
andrew-bierman merged 4 commits into
developmentfrom
chore/biome-max-params-2
Apr 11, 2026
Merged

chore(biome): prep refactors toward useMaxParams max: 2#2042
andrew-bierman merged 4 commits into
developmentfrom
chore/biome-max-params-2

Conversation

@andrew-bierman
Copy link
Copy Markdown
Collaborator

Summary

Prep work toward tightening Biome's useMaxParams rule from max: 3
to max: 2. Refactors 14 functions across the monorepo from
positional args to the canonical (subject, opts) shape so that a
follow-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/guards

  • assertEnum(value, { members, name })

packages/analytics

  • QueryBuilder.trendsQuery(keyword, { sites, days })

packages/api

  • logAIRequest(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 _url first arg
  • apiWithAuth(path, init?) kept as-is; custom-user case moved to a new apiWithAuthAs(path, { user, init }) helper

apps/guides

  • getPayloadConfigFromPayload(config, { payload, key }) (chart.tsx)
  • writeEnhancedContent(filePath, { metadata, enhancedContent })
  • enhanceFile(filePath, { cliOptions, enhancementOptions })
  • generateTopicIdeas(count, { categories, existingContent })

apps/expo

  • resetPassword(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: 2 the canonical shape becomes fn(subject, { options }), which:

  • Makes call sites self-documenting (no guessing which positional arg is which)
  • Allows future additions to the options object without breaking callers
  • Plays well with TypeScript's structural typing (partial opts via defaults)

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:

  • Jotai write atoms (atomWithAsyncStorage, atomWithKvStorage,
    atomWithSecureStorage, locationsAtoms) — Jotai's write atom
    signature is (get, set, update) => void, dictated by the library.
  • Hono basicAuth middleware (admin/index.ts) — the
    verifyUser(username, password, c) callback is prescribed by
    hono/basic-auth.
  • Cloudflare R2Bucket (services/r2-bucket.ts x2) — put(key, value, options) and uploadPart(key, uploadId, partNumber) are
    part of the R2 binding interface.
  • Array.reduce callback (services/etl/processCatalogEtl.ts) —
    (acc, header, idx) => ... is the stdlib reduce signature.
  • R2 put mocks in tests (test/guides.test.ts, test/setup.ts) —
    mirror the R2 binding signature above.
  • convertWeight (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-contract
cases above.

Test plan

  • bun biome check clean at max: 3
  • tsc --noEmit clean across the monorepo
  • bun lint clean (no new errors introduced; existing warnings unchanged)
  • CI unit tests on @packrat/api (uses the refactored apiWithAuth / httpMethods)
  • CI unit tests on @packrat/analytics (trendsQuery)
  • Expo E2E on auth reset-password + pack item add flow

🤖 Generated with Claude Code

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)`).
Copilot AI review requested due to automatic review settings April 11, 2026 05:08
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Apr 11, 2026

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: df185175-449c-4a3c-9979-d52fb670fe65

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch chore/biome-max-params-2

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.

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for Expo Unit Tests Coverage (./apps/expo)

Status Category Percentage Covered / Total
🔵 Lines 75.92% 495 / 652
🔵 Statements 75.92% (🎯 75%) 495 / 652
🔵 Functions 92.72% 51 / 55
🔵 Branches 91.82% 191 / 208
File CoverageNo changed files found.
Generated in workflow #51 for commit 4a36fb1 by the Vitest Coverage Report Action

@github-actions
Copy link
Copy Markdown
Contributor

Coverage Report for API Unit Tests Coverage (./packages/api)

Status Category Percentage Covered / Total
🔵 Lines 96.57% 902 / 934
🔵 Statements 96.57% (🎯 80%) 902 / 934
🔵 Functions 100% 48 / 48
🔵 Branches 90.03% 280 / 311
File CoverageNo changed files found.
Generated in workflow #51 for commit 4a36fb1 by the Vitest Coverage Report Action

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 opts object 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.

Comment on lines +38 to +42
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;
Copy link

Copilot AI Apr 11, 2026

Choose a reason for hiding this comment

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

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.

Copilot uses AI. Check for mistakes.
@cloudflare-workers-and-pages
Copy link
Copy Markdown
Contributor

Deploying packrat-guides with  Cloudflare Pages  Cloudflare Pages

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

View logs

@andrew-bierman andrew-bierman merged commit d0da43b into development Apr 11, 2026
13 of 15 checks passed
@andrew-bierman andrew-bierman deleted the chore/biome-max-params-2 branch April 11, 2026 05:24
andrew-bierman added a commit that referenced this pull request Apr 11, 2026
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.
andrew-bierman added a commit that referenced this pull request May 14, 2026
chore(biome): prep refactors toward useMaxParams max: 2
andrew-bierman added a commit that referenced this pull request May 14, 2026
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants