Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .jules/refactor.md
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.

We should remove this file, no?

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
## 2025-05-15 - Prefer local helpers over inline Set for uniqueness
**Smell:** Manually creating `[...new Set(array)]` when a `uniq` helper exists in `common/array.ts`.
**Learning:** The codebase has a standard `uniq` utility in `@shopify/cli-kit/common/array` that wraps `Set` in a consistent way. Using it improves readability and follows the "Reach for an existing helper" philosophy.
**Action:** Always check `common/array.ts` for existing collection helpers before manual implementation.
16 changes: 9 additions & 7 deletions packages/cli-kit/src/public/common/string.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {takeRandomFromArray} from './array.js'
import {takeRandomFromArray, uniq} from './array.js'
import {unstyled} from '../node/output.js'
import {Token, TokenItem} from '../../private/node/ui/components/TokenizedText.js'

Expand Down Expand Up @@ -419,12 +419,14 @@ export function pascalize(str: string): string {
export function normalizeDelimitedString(delimitedString?: string, delimiter = ','): string | undefined {
if (!delimitedString) return

const items = delimitedString.split(delimiter).map((value) => value.trim())
const nonEmptyItems = items.filter((value) => value !== '')
const sortedItems = nonEmptyItems.sort()
const uniqueSortedItems = [...new Set(sortedItems)]

return uniqueSortedItems.join(delimiter)
return uniq(
delimitedString
.split(delimiter)
.map((item) => item.trim())
.filter((item) => item !== ''),
)
.sort()
.join(delimiter)
}

/**
Expand Down
Loading