Skip to content

chore(genkit-tools): enable string-coercion and assertion ESLint rules - #7491

Open
MichaelDoyle wants to merge 3 commits into
md/tools-eslint-low-churnfrom
md/tools-eslint-string-assertions
Open

MichaelDoyle wants to merge 3 commits into
md/tools-eslint-low-churnfrom
md/tools-eslint-string-assertions

Conversation

@MichaelDoyle

@MichaelDoyle MichaelDoyle commented Dec 4, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Enables string-coercion and assertion-hygiene ESLint rules in genkit-tools/eslint.config.mjs to prevent [object Object] / function-reference interpolation bugs and drop stale type casts. Fixes #7430.

Bugs Fixed

  • Compiled-binary CLI update notifications were silently broken (cli/src/utils/updates.ts): getBinaryUpdateInfo() interpolated ${platform}-${arch} (the os.platform / os.arch function references) instead of calling ${platform()}-${arch()}, so the GCS platform lookup always missed and compiled-binary users never saw update notifications. Fixed and covered with a new compiled-binary unit test in updates.test.ts.
  • Plain error objects formatted as "[object Object]" (common/src/utils/errors.ts): getErrorDetails() now preserves custom .toString() methods and falls back to JSON.stringify() instead of String(error).
  • Unsafe WebSocket RawData decoding (common/src/manager/manager-v2.ts): Added rawDataToString() to decode Buffer, Buffer[], and ArrayBuffer cleanly instead of calling data.toString() (which produces "[object ArrayBuffer]" on ArrayBuffer).
  • Unsafe optional chaining on error stacks (common/src/manager/manager.ts): Fixed (error?.details).stack (which throws a TypeError when details is missing) to error?.details?.stack.

Rules Enabled (by commit)

Rule Summary
@typescript-eslint/no-base-to-string Safe WebSocket RawData decoding, typed Express query/index helpers, primitive narrowing before String(), and getErrorDetails() JSON fallback
@typescript-eslint/restrict-template-expressions Fixed ${platform()}-${arch()} in updates.ts, formatted Axios 400 response bodies, and wrapped caught unknown errors in String()
@typescript-eslint/no-unnecessary-type-assertion Removed redundant casts across 33 files, fixed error?.details?.stack in manager.ts, and replaced array casts with type predicates

@MichaelDoyle
MichaelDoyle added this pull request to stack #7494 December 4, 2026 22:44
@MichaelDoyle MichaelDoyle changed the title md/tools eslint string assertions chore(genkit-tools): enable string-coercion and assertion ESLint rules Dec 4, 2026

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Code Review

This pull request updates the ESLint configuration to enforce stricter TypeScript rules, including @typescript-eslint/no-base-to-string, @typescript-eslint/restrict-template-expressions, and @typescript-eslint/no-unnecessary-type-assertion. Consequently, numerous files have been updated to safely handle string conversions, remove redundant type assertions, and refine type checks. Feedback on these changes highlights two issues: first, the new toIndexString helper in file-trace-store.ts can return undefined at runtime when handling undefined values, violating its type signature; second, the error serialization logic in errors.ts bypasses custom toString() implementations on non-primitive objects by defaulting directly to JSON.stringify.

Comment thread genkit-tools/common/src/utils/errors.ts Resolved

@genkit-bot genkit-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM with comments

Details

Run 46276b58-fb26-4482-95da-47390c6fb732 · Cloud Run logs · Dashboard

Comment thread genkit-tools/cli/src/utils/updates.ts Resolved
@MichaelDoyle
MichaelDoyle force-pushed the md/tools-eslint-string-assertions branch 2 times, most recently from 1eb1771 to 3f318b6 Compare December 5, 2026 02:50
@MichaelDoyle
MichaelDoyle force-pushed the md/tools-eslint-string-assertions branch from 3f318b6 to a4d0b2b Compare December 5, 2026 02:59
@MichaelDoyle
MichaelDoyle force-pushed the md/tools-eslint-string-assertions branch from a4d0b2b to 98b52d3 Compare December 5, 2026 03:37
@MichaelDoyle
MichaelDoyle marked this pull request as ready for review December 5, 2026 03:41

This branch has not been deployed

No deployments
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.

[genkit-tools] Enable string-coercion and type-assertion ESLint rules

2 participants