Some Sonar code smell suggestions

This commit is contained in:
shamoon
2025-09-14 15:58:43 -07:00
parent bc3098419c
commit a2f4c5aea0
4 changed files with 9 additions and 18 deletions

View File

@@ -34,17 +34,17 @@ describe('flattenTags', () => {
expect(flat.map((t) => t.orderIndex)).toEqual([0, 1, 2, 3, 4, 5, 6])
// Children are rebuilt
const aRoot = flat.find((t) => t.name === 'A-root')!
const aRoot = flat.find((t) => t.name === 'A-root')
expect(new Set(aRoot.children?.map((c) => c.name))).toEqual(
new Set(['child 2', 'Child 10'])
)
const bRoot = flat.find((t) => t.name === 'B-root')!
const bRoot = flat.find((t) => t.name === 'B-root')
expect(new Set(bRoot.children?.map((c) => c.name))).toEqual(
new Set(['Alpha', 'beta'])
)
const child2 = flat.find((t) => t.name === 'child 2')!
const child2 = flat.find((t) => t.name === 'child 2')
expect(new Set(child2.children?.map((c) => c.name))).toEqual(
new Set(['Sub 1'])
)

View File

@@ -8,7 +8,7 @@ export function flattenTags(all: Tag[]): Tag[] {
for (const t of map.values()) {
if (t.parent) {
const p = map.get(t.parent)
p && p.children.push(t)
p?.children.push(t)
}
}
const roots = Array.from(map.values()).filter((t) => !t.parent)
@@ -29,6 +29,7 @@ export function flattenTags(all: Tag[]): Tag[] {
}
}
}
roots.sort(sortByName).forEach((r) => walk(r, 0))
roots.sort(sortByName)
roots.forEach((r) => walk(r, 0))
return ordered
}