Skip to content

Commit 3767b64

Browse files
ndeloofclaude
andcommitted
v3 nodes: fix gocritic, gofumpt and unparam lint issues
The previous commits introduced three classes of linter complaints: - paths/node.go: a stray blank line at the end of the file tripped gofumpt. Run gofumpt -w on the file. - paths/node_test.go: gocritic filepathJoin flagged literal absolute paths passed to filepath.Join. Move the project root into a package var built via filepath.Join with no literal separator; do the same for the per-scalar test rootDir and includeDir. The unused workingDir parameter of resolveYAML is removed (unparam) since every caller passed the same value. - override/node.go: gocritic unlambda flagged a trivial sort comparator. Replace with the cmp.Compare[string] direct reference. No behavior change. Tests still pass locally. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
1 parent 26448a2 commit 3767b64

3 files changed

Lines changed: 26 additions & 21 deletions

File tree

override/node.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,7 +437,7 @@ func convertIntoSequenceNode(n *yaml.Node) *yaml.Node {
437437
}
438438
values = append(values, fmt.Sprintf("%s=%s", key, scalarOrInline(value)))
439439
}
440-
slices.SortFunc(values, func(a, b string) int { return cmp.Compare(a, b) })
440+
slices.SortFunc(values, cmp.Compare[string])
441441
seq := &yaml.Node{
442442
Kind: yaml.SequenceNode,
443443
Tag: "!!seq",

paths/node.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,4 +305,3 @@ func mappingFieldValue(n *yaml.Node, key string) string {
305305
}
306306
return v.Value
307307
}
308-

paths/node_test.go

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,23 @@ import (
2525
"gotest.tools/v3/assert"
2626
)
2727

28+
// testProjectDir is the absolute project root used by the in-package
29+
// resolver tests. It is built from a single-letter component so the
30+
// gocritic filepathJoin checker does not flag literal path separators in
31+
// filepath.Join calls below.
32+
var testProjectDir = filepath.Join(string(filepath.Separator), "project")
33+
2834
func parse(t *testing.T, src string) *yaml.Node {
2935
t.Helper()
3036
var doc yaml.Node
3137
assert.NilError(t, yaml.Unmarshal([]byte(src), &doc))
3238
return &doc
3339
}
3440

35-
func resolveYAML(t *testing.T, src, workingDir string) map[string]any {
41+
func resolveYAML(t *testing.T, src string) map[string]any {
3642
t.Helper()
3743
root := parse(t, src)
38-
assert.NilError(t, ResolveRelativePathsNode(root, NodeResolverOptions{WorkingDir: workingDir}))
44+
assert.NilError(t, ResolveRelativePathsNode(root, NodeResolverOptions{WorkingDir: testProjectDir}))
3945
var m map[string]any
4046
assert.NilError(t, root.Decode(&m))
4147
return m
@@ -47,9 +53,9 @@ services:
4753
web:
4854
build:
4955
context: ./app
50-
`, "/project")
56+
`)
5157
build := got["services"].(map[string]any)["web"].(map[string]any)["build"].(map[string]any)
52-
assert.Equal(t, build["context"], filepath.Join("/project", "app"))
58+
assert.Equal(t, build["context"], filepath.Join(testProjectDir, "app"))
5359
}
5460

5561
func TestResolveRelativePathsNode_BuildContextUrlUntouched(t *testing.T) {
@@ -58,7 +64,7 @@ services:
5864
web:
5965
build:
6066
context: https://github.com/example/repo.git
61-
`, "/project")
67+
`)
6268
build := got["services"].(map[string]any)["web"].(map[string]any)["build"].(map[string]any)
6369
assert.Equal(t, build["context"], "https://github.com/example/repo.git")
6470
}
@@ -70,10 +76,10 @@ services:
7076
env_file:
7177
- path: ./.env
7278
required: true
73-
`, "/project")
79+
`)
7480
env := got["services"].(map[string]any)["web"].(map[string]any)["env_file"].([]any)
7581
first := env[0].(map[string]any)
76-
assert.Equal(t, first["path"], filepath.Join("/project", ".env"))
82+
assert.Equal(t, first["path"], filepath.Join(testProjectDir, ".env"))
7783
}
7884

7985
func TestResolveRelativePathsNode_VolumesLongFormBindResolved(t *testing.T) {
@@ -84,12 +90,10 @@ services:
8490
- type: bind
8591
source: ./data
8692
target: /data
87-
`, "/project")
93+
`)
8894
vols := got["services"].(map[string]any)["web"].(map[string]any)["volumes"].([]any)
8995
mount := vols[0].(map[string]any)
90-
// On Unix systems the join is /project/data; the test does not assume
91-
// an OS-specific separator.
92-
expected := filepath.Join("/project", "data")
96+
expected := filepath.Join(testProjectDir, "data")
9397
assert.Equal(t, mount["source"], expected)
9498
}
9599

@@ -99,7 +103,7 @@ services:
99103
web:
100104
volumes:
101105
- "./data:/data"
102-
`, "/project")
106+
`)
103107
vols := got["services"].(map[string]any)["web"].(map[string]any)["volumes"].([]any)
104108
// Short form: left untouched by the Node-level resolver.
105109
assert.Equal(t, vols[0], "./data:/data")
@@ -111,7 +115,7 @@ services:
111115
web:
112116
build:
113117
context: /absolute/path
114-
`, "/project")
118+
`)
115119
build := got["services"].(map[string]any)["web"].(map[string]any)["build"].(map[string]any)
116120
assert.Equal(t, build["context"], "/absolute/path")
117121
}
@@ -120,6 +124,8 @@ services:
120124
// two relative paths in the same merged tree resolve against different
121125
// working directories depending on the SourceContext attached to each.
122126
func TestResolveRelativePathsNode_PerScalarWorkingDir(t *testing.T) {
127+
rootDir := filepath.Join(string(filepath.Separator), "project-root")
128+
includeDir := filepath.Join(string(filepath.Separator), "include-dir")
123129
root := parse(t, `
124130
services:
125131
web:
@@ -158,9 +164,9 @@ services:
158164
err := ResolveRelativePathsNode(root, NodeResolverOptions{
159165
WorkingDirFor: func(n *yaml.Node) string {
160166
if n == apiContext {
161-
return "/include-dir"
167+
return includeDir
162168
}
163-
return "/project-root"
169+
return rootDir
164170
},
165171
})
166172
assert.NilError(t, err)
@@ -169,10 +175,10 @@ services:
169175
assert.NilError(t, root.Decode(&m))
170176
assert.Equal(t,
171177
m["services"].(map[string]any)["web"].(map[string]any)["build"].(map[string]any)["context"],
172-
filepath.Join("/project-root", "from-root"))
178+
filepath.Join(rootDir, "from-root"))
173179
assert.Equal(t,
174180
m["services"].(map[string]any)["api"].(map[string]any)["build"].(map[string]any)["context"],
175-
filepath.Join("/include-dir", "from-include"))
181+
filepath.Join(includeDir, "from-include"))
176182
}
177183

178184
// TestResolveRelativePathsNode_IncludeNotResolvedHere documents that
@@ -189,7 +195,7 @@ include:
189195
- ./a.yaml
190196
- ./b.yaml
191197
project_directory: ./sub
192-
`, "/project")
198+
`)
193199
incl := got["include"].([]any)[0].(map[string]any)
194200
paths := incl["path"].([]any)
195201
assert.Equal(t, paths[0], "./a.yaml")
@@ -206,7 +212,7 @@ services:
206212
service: base
207213
`)
208214
err := ResolveRelativePathsNode(root, NodeResolverOptions{
209-
WorkingDir: "/project",
215+
WorkingDir: testProjectDir,
210216
Remotes: []RemoteResource{
211217
func(p string) bool { return strings.HasPrefix(p, "oci://") },
212218
},

0 commit comments

Comments
 (0)