Skip to content

Refactor (packages/web/src/components/share/part.tsx): Function with high complexity: flattenToolArgs - #63

Open
mmirzata wants to merge 2 commits into
CMU-17313Q:mainfrom
mmirzata:refactor/flatten-tool-args
Open

Refactor (packages/web/src/components/share/part.tsx): Function with high complexity: flattenToolArgs#63
mmirzata wants to merge 2 commits into
CMU-17313Q:mainfrom
mmirzata:refactor/flatten-tool-args

Conversation

@mmirzata

@mmirzata mmirzata commented Sep 4, 2026

Copy link
Copy Markdown

Issue for this PR

Closes #62

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Qlty flagged flattenToolArgs in part.tsx for high complexity (count = 21). The array
branch repeated the same object-vs-leaf check the function already did at the top, adding
duplication and nesting.

I moved the function into a new part-utils.ts and exported it so it can be tested, and
rewrote it so objects and arrays share one path (arrays just format the key as [i]
instead of .key). Output is unchanged, so same [path, value] pairs.

I used Claude to help with the refactor and the tests, following the instruction alone was not enough.

How did you verify your code works?

Added part-utils.test.ts with 5 tests covering nested objects/arrays, primitives and
null, non-object input, empty inputs, and array bracket paths. All 5 pass with 100%
coverage on part-utils.ts, and qlty smells no longer reports the smell.

Screenshots / recordings

Before: Qlty smell (count = 21):
issues

After: no smell on part-utils.ts:
resolved

Tests passing, 100% coverage:
coverage

Lint: filtering bun lint to my changed files returns nothing, confirming part-utils.ts and part.tsx have no lint errors (the repo's only lint errors are pre-existing, in unrelated files I didn't modify).
Screenshot 2026-09-04 at 19 08 51

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

@mmirzata mmirzata changed the title Refactor/flatten tool argRefactor (packages/web/src/components/share/part.tsx): Function with high complexity: flattenToolArgss Refactor (packages/web/src/components/share/part.tsx): Function with high complexity: flattenToolArgs Sep 4, 2026
@mmirzata mmirzata changed the title Refactor (packages/web/src/components/share/part.tsx): Function with high complexity: flattenToolArgs Refactor (packages/web/src/components/share/part.tsx): Function with high complexity: flattenToolArgs Sep 4, 2026
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.

P1B: Refactor (packages/web/src/components/share/part.tsx:758): Function with high complexity (count = 21): flattenToolArgs

1 participant