Skip to content

Commit 1d09e21

Browse files
refactor: streamline flattening logic and improve variable naming in tests & upgrade golangci-lint to V2
fix: update Go setup to use version from go.mod and enable latest check fix: ensure Go setup action is correctly specified in CI workflow fix: correct golangci-lint configuration file extension from .yml to .yaml
1 parent d71049c commit 1d09e21

4 files changed

Lines changed: 136 additions & 131 deletions

File tree

.github/workflows/ci.yml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ jobs:
1414
- name: Set up Go
1515
uses: actions/setup-go@v5
1616
with:
17-
go-version: "1.21"
17+
go-version-file: go.mod
18+
check-latest: true
1819
- name: Build
1920
run: make build
2021
- name: Test
@@ -27,11 +28,10 @@ jobs:
2728
- name: Set up Go
2829
uses: actions/setup-go@v5
2930
with:
30-
go-version: "1.21"
31-
- name: Install golangci-lint
32-
run: |
33-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.64.8
34-
- name: Check golangci-lint version
35-
run: golangci-lint --version
36-
- name: Lint
37-
run: make lint
31+
go-version-file: go.mod
32+
check-latest: true
33+
- name: golangci-lint
34+
uses: golangci/golangci-lint-action@4afd733a84b1f43292c63897423277bb7f4313a9 # pin@8.0.0
35+
with:
36+
version: latest
37+
args: -v -c .golangci.yaml

.golangci.yaml

Lines changed: 113 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -1,122 +1,135 @@
1-
# GolangCI-Lint v2.x configuration (clean, no deprecated options)
2-
# See: https://golangci-lint.run/usage/configuration/
3-
4-
linters-settings:
5-
gocyclo:
6-
min-complexity: 15
7-
dupl:
8-
threshold: 100
9-
errcheck:
10-
check-type-assertions: true
11-
staticcheck:
12-
checks: [all]
13-
revive:
14-
confidence: 0.8
15-
severity: warning
16-
rules:
17-
- name: var-naming
18-
- name: indent-error-flow
19-
- name: error-naming
20-
- name: if-return
21-
- name: import-shadowing
22-
- name: range-val-address
23-
- name: time-naming
24-
- name: unexported-return
25-
- name: unused-parameter
26-
- name: unused-receiver
27-
- name: var-declaration
28-
- name: exported
29-
- name: blank-imports
30-
- name: context-as-argument
31-
- name: context-keys-type
32-
- name: error-strings
33-
- name: error-return
34-
- name: errorf
35-
- name: function-length
36-
gofmt:
37-
simplify: true
38-
misspell:
39-
locale: US
40-
1+
version: "2"
412
run:
42-
timeout: 5m
43-
tests: true
44-
issues-exit-code: 1
453
modules-download-mode: readonly
4+
issues-exit-code: 1
5+
tests: true
466
allow-parallel-runners: true
47-
48-
issues:
49-
exclude-dirs:
50-
- dist
51-
- vendor
52-
- .git
53-
- .github
54-
- .vscode
55-
- .idea
56-
- node_modules
57-
- testdata
58-
exclude-files:
59-
- ".*_gen.go$"
60-
- ".*_mock.go$"
61-
exclude-rules:
62-
# Exclude test files from certain linting rules
63-
- path: ".*_test\\.go$"
64-
linters:
65-
- dupl
66-
- gocyclo
67-
- revive
68-
# Allow longer functions in tests
69-
- path: ".*_test\\.go$"
70-
text: "function-length"
71-
# Allow high cyclomatic complexity in tests
72-
- path: ".*_test\\.go$"
73-
text: "cyclomatic complexity"
74-
757
linters:
768
enable:
77-
- govet
78-
- errcheck
79-
- staticcheck
80-
- revive
81-
- gofmt
82-
- misspell
83-
- gocyclo
849
- dupl
10+
- gocyclo
11+
- misspell
12+
- revive
8513
disable:
86-
- godox
87-
- lll
88-
- funlen
89-
- wsl
14+
- asasalint
15+
- bodyclose
16+
- cyclop
17+
- depguard
9018
- dogsled
19+
- exhaustive
20+
- forbidigo
21+
- funlen
22+
- gocognit
9123
- goconst
9224
- gocritic
25+
- godox
26+
- goheader
27+
- goprintffuncname
9328
- gosec
94-
- depguard
95-
- unparam
29+
- lll
9630
- nakedret
97-
- prealloc
98-
- exhaustive
9931
- nestif
100-
- goprintffuncname
101-
- gocognit
102-
- cyclop
103-
- bodyclose
104-
- asasalint
10532
- nlreturn
10633
- noctx
107-
- rowserrcheck
108-
- stylecheck
109-
- typecheck
110-
- unused
111-
- whitespace
112-
- wrapcheck
113-
- forbidigo
114-
- gci
115-
- goheader
11634
- nolintlint
11735
- paralleltest
36+
- prealloc
37+
- rowserrcheck
11838
- testpackage
11939
- thelper
12040
- tparallel
12141
- unconvert
42+
- unparam
43+
- unused
12244
- wastedassign
45+
- whitespace
46+
- wrapcheck
47+
- wsl
48+
settings:
49+
dupl:
50+
threshold: 100
51+
errcheck:
52+
check-type-assertions: true
53+
gocyclo:
54+
min-complexity: 15
55+
misspell:
56+
locale: US
57+
revive:
58+
confidence: 0.8
59+
severity: warning
60+
rules:
61+
- name: var-naming
62+
- name: indent-error-flow
63+
- name: error-naming
64+
- name: if-return
65+
- name: import-shadowing
66+
- name: range-val-address
67+
- name: time-naming
68+
- name: unexported-return
69+
- name: unused-parameter
70+
- name: unused-receiver
71+
- name: var-declaration
72+
- name: exported
73+
- name: blank-imports
74+
- name: context-as-argument
75+
- name: context-keys-type
76+
- name: error-strings
77+
- name: error-return
78+
- name: errorf
79+
- name: function-length
80+
staticcheck:
81+
checks:
82+
- all
83+
exclusions:
84+
generated: lax
85+
presets:
86+
- comments
87+
- common-false-positives
88+
- legacy
89+
- std-error-handling
90+
rules:
91+
- linters:
92+
- dupl
93+
- gocyclo
94+
- revive
95+
path: .*_test\.go$
96+
- path: .*_test\.go$
97+
text: function-length
98+
- path: .*_test\.go$
99+
text: cyclomatic complexity
100+
paths:
101+
- .*_gen.go$
102+
- .*_mock.go$
103+
- dist
104+
- vendor
105+
- .git
106+
- .github
107+
- .vscode
108+
- .idea
109+
- node_modules
110+
- testdata
111+
- third_party$
112+
- builtin$
113+
- examples$
114+
formatters:
115+
enable:
116+
- gofmt
117+
settings:
118+
gofmt:
119+
simplify: true
120+
exclusions:
121+
generated: lax
122+
paths:
123+
- .*_gen.go$
124+
- .*_mock.go$
125+
- dist
126+
- vendor
127+
- .git
128+
- .github
129+
- .vscode
130+
- .idea
131+
- node_modules
132+
- testdata
133+
- third_party$
134+
- builtin$
135+
- examples$

internal/transform/flatten.go

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,10 @@ func processDocumentFlattening(doc, root *yaml.Node, path string, opts FlattenOp
8080
// Track component references before flattening to identify unused ones later
8181
componentsBefore := extractComponentRefs(root)
8282

83-
changed := false
84-
8583
// First pass: flatten oneOf/anyOf/allOf with single refs
86-
if processComponentsFlattening(root, path, result, &changed) {
87-
changed = true
88-
}
89-
90-
if processPathsFlattening(root, path, result, &changed) {
91-
changed = true
92-
}
84+
changed := false
85+
processComponentsFlattening(root, path, result, &changed)
86+
processPathsFlattening(root, path, result, &changed)
9387

9488
// Second pass: flatten reference chains (optional, more aggressive)
9589
if opts.FlattenResponses {
@@ -130,18 +124,16 @@ func flattenReferenceChains(root *yaml.Node, filePath string, result *FlattenRes
130124
if len(refMap) == 0 {
131125
return false
132126
}
133-
134-
localChanged := false
135-
136127
// Flatten reference chains in components/schemas
137-
if flattenSchemaReferences(root, refMap, filePath, result) {
138-
localChanged = true
139-
}
128+
// Capture the result of the first flattening operation
129+
schemaChanged := flattenSchemaReferences(root, refMap, filePath, result)
140130

141131
// Flatten reference chains in paths
142-
if flattenPathReferences(root, refMap, filePath, result) {
143-
localChanged = true
144-
}
132+
// Capture the result of the second flattening operation
133+
pathChanged := flattenPathReferences(root, refMap, filePath, result)
134+
135+
// Combine the results: localChanged is true if either operation made a change
136+
localChanged := schemaChanged || pathChanged
145137

146138
if localChanged {
147139
*changed = true

internal/transform/flatten_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,12 +159,12 @@ paths:
159159
t.Fatal("content is not a map[string]interface{}")
160160
}
161161

162-
applicationJson, ok := content["application/json"].(map[string]interface{})
162+
applicationJSON, ok := content["application/json"].(map[string]interface{})
163163
if !ok {
164164
t.Fatal("application/json is not a map[string]interface{}")
165165
}
166166

167-
schema, ok := applicationJson["schema"].(map[string]interface{})
167+
schema, ok := applicationJSON["schema"].(map[string]interface{})
168168
if !ok {
169169
t.Fatal("schema is not a map[string]interface{}")
170170
}
@@ -441,12 +441,12 @@ paths:
441441
t.Fatal("content is not a map[string]interface{}")
442442
}
443443

444-
appJson, ok := content["application/json"].(map[string]interface{})
444+
appJSON, ok := content["application/json"].(map[string]interface{})
445445
if !ok {
446446
t.Fatal("application/json is not a map[string]interface{}")
447447
}
448448

449-
schema, ok := appJson["schema"].(map[string]interface{})
449+
schema, ok := appJSON["schema"].(map[string]interface{})
450450
if !ok {
451451
t.Fatal("schema is not a map[string]interface{}")
452452
}

0 commit comments

Comments
 (0)