Skip to content

Commit 70b4b68

Browse files
fix: convert references to absolute paths for proper parent directory handling and deduplication (#58)
1 parent 40abaee commit 70b4b68

File tree

15 files changed

+1431
-224
lines changed

15 files changed

+1431
-224
lines changed

.mise.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@ gotestsum = "latest"
77
description = "Create VSCode symlinks for tools not automatically handled by mise-vscode"
88
run = [
99
"mkdir -p .vscode/mise-tools",
10-
"ln -sf $(mise exec [email protected] -- which golangci-lint) .vscode/mise-tools/golangci-lint",
10+
"ln -sf $(mise exec -- which golangci-lint-v2) $(dirname $(mise exec -- which golangci-lint-v2))/golangci-lint || true",
11+
"ln -sf $(mise exec -- which golangci-lint) .vscode/mise-tools/golangci-lint",
1112
]
1213

1314
[hooks]

internal/utils/references.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ func (rc *ReferenceClassification) JoinWith(relative string) (string, error) {
148148
}
149149

150150
if rc.IsFile {
151-
return rc.joinFilePath(relative)
151+
joined := rc.joinFilePath(relative)
152+
return joined, nil
152153
}
153154

154155
// If base is a fragment, treat relative as the new reference
@@ -157,7 +158,8 @@ func (rc *ReferenceClassification) JoinWith(relative string) (string, error) {
157158
}
158159

159160
// Fallback: treat as file path
160-
return rc.joinFilePath(relative)
161+
joined := rc.joinFilePath(relative)
162+
return joined, nil
161163
}
162164

163165
// joinURL joins this URL reference with a relative reference using the cached ParsedURL
@@ -185,11 +187,11 @@ func (rc *ReferenceClassification) joinURL(relative string) (string, error) {
185187
}
186188

187189
// joinFilePath joins this file path reference with a relative path using cross-platform path handling
188-
func (rc *ReferenceClassification) joinFilePath(relative string) (string, error) {
190+
func (rc *ReferenceClassification) joinFilePath(relative string) string {
189191
// If relative path is absolute, return it as-is
190192
// Check for both OS-specific absolute paths and Unix-style absolute paths (for cross-platform compatibility)
191193
if filepath.IsAbs(relative) || strings.HasPrefix(relative, "/") || rc.isWindowsAbsolutePath(relative) {
192-
return relative, nil
194+
return relative
193195
}
194196

195197
// Determine the path separator style from the original path
@@ -217,7 +219,7 @@ func (rc *ReferenceClassification) joinFilePath(relative string) (string, error)
217219
joined = strings.ReplaceAll(joined, "\\", "/")
218220
}
219221

220-
return joined, nil
222+
return joined
221223
}
222224

223225
// getWindowsDir extracts the directory part from a Windows-style path

internal/utils/references_windows_test.go

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
)
1111

1212
func TestWindowsPathClassification_Success(t *testing.T) {
13+
t.Parallel()
14+
1315
tests := []struct {
1416
name string
1517
windowsPath string
@@ -46,6 +48,7 @@ func TestWindowsPathClassification_Success(t *testing.T) {
4648

4749
for _, tt := range tests {
4850
t.Run(tt.name, func(t *testing.T) {
51+
t.Parallel()
4952
classification, err := ClassifyReference(tt.windowsPath)
5053
require.NoError(t, err)
5154
require.NotNil(t, classification)
@@ -60,6 +63,8 @@ func TestWindowsPathClassification_Success(t *testing.T) {
6063
}
6164

6265
func TestWindowsPathJoining_Success(t *testing.T) {
66+
t.Parallel()
67+
6368
tests := []struct {
6469
name string
6570
base string
@@ -87,8 +92,8 @@ func TestWindowsPathJoining_Success(t *testing.T) {
8792
{
8893
name: "windows path with absolute relative path",
8994
base: "C:\\path\\to\\schemas\\user.json",
90-
relative: "D:\\other\\path\\schema.json",
91-
expected: "D:\\other\\path\\schema.json",
95+
relative: "D:\\some\\path\\schema.json",
96+
expected: "D:\\some\\path\\schema.json",
9297
},
9398
{
9499
name: "windows path with fragment",
@@ -100,6 +105,7 @@ func TestWindowsPathJoining_Success(t *testing.T) {
100105

101106
for _, tt := range tests {
102107
t.Run(tt.name, func(t *testing.T) {
108+
t.Parallel()
103109
classification, err := ClassifyReference(tt.base)
104110
require.NoError(t, err)
105111
require.NotNil(t, classification)
@@ -113,6 +119,8 @@ func TestWindowsPathJoining_Success(t *testing.T) {
113119
}
114120

115121
func TestWindowsPathJoinReference_Success(t *testing.T) {
122+
t.Parallel()
123+
116124
tests := []struct {
117125
name string
118126
base string
@@ -135,6 +143,7 @@ func TestWindowsPathJoinReference_Success(t *testing.T) {
135143

136144
for _, tt := range tests {
137145
t.Run(tt.name, func(t *testing.T) {
146+
t.Parallel()
138147
result, err := JoinReference(tt.base, tt.relative)
139148
require.NoError(t, err)
140149
assert.Equal(t, tt.expected, result)

0 commit comments

Comments
 (0)