Skip to content

Commit d59701b

Browse files
[Refactor] Use early returns in commonParentDirectory
Replace a ternary operator return with a cleaner early-return pattern if there are one or fewer common components, simplifying readability.
1 parent 7f41b79 commit d59701b

1 file changed

Lines changed: 4 additions & 1 deletion

File tree

  • packages/cli-kit/src/public/node

packages/cli-kit/src/public/node/path.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,10 @@ export function commonParentDirectory(first: string, second: string): string {
119119
while (i < firstParts.length && i < secondParts.length && firstParts[i] === secondParts[i]) {
120120
i++
121121
}
122-
return i > 1 ? firstParts.slice(0, i).join('/') : '/'
122+
if (i <= 1) {
123+
return '/'
124+
}
125+
return firstParts.slice(0, i).join('/')
123126
}
124127

125128
/**

0 commit comments

Comments
 (0)