Skip to content

Commit 1c2ae8c

Browse files
committed
chore(golangci-lint: fix various
1 parent 1625200 commit 1c2ae8c

File tree

4 files changed

+13
-34
lines changed

4 files changed

+13
-34
lines changed

cmd/ogen-fixerror/main.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,17 +47,14 @@ func run(args []string) error {
4747
return fmt.Errorf("read file: %w", err)
4848
}
4949

50-
fixed, count, err := FixUnexpectedStatusCodeBody(content)
51-
if err != nil {
52-
return fmt.Errorf("fix error body: %w", err)
53-
}
50+
fixed, count := FixUnexpectedStatusCodeBody(content)
5451

5552
if count == 0 {
5653
fmt.Printf("No UnexpectedStatusCode returns needed fixing in %s\n", filename)
5754
return nil
5855
}
5956

60-
if err := os.WriteFile(filename, fixed, 0644); err != nil {
57+
if err := os.WriteFile(filename, fixed, 0600); err != nil {
6158
return fmt.Errorf("write file: %w", err)
6259
}
6360

@@ -67,7 +64,7 @@ func run(args []string) error {
6764

6865
// FixUnexpectedStatusCodeBody finds returns of validate.UnexpectedStatusCodeWithResponse
6966
// and adds code to buffer the response body before returning.
70-
func FixUnexpectedStatusCodeBody(content []byte) ([]byte, int, error) {
67+
func FixUnexpectedStatusCodeBody(content []byte) ([]byte, int) {
7168
// Check if we need to add imports
7269
needsImports := !bytes.Contains(content, []byte(`"bytes"`)) ||
7370
!bytes.Contains(content, []byte(`"io"`))
@@ -100,7 +97,7 @@ func FixUnexpectedStatusCodeBody(content []byte) ([]byte, int, error) {
10097
fixed = addImports(fixed)
10198
}
10299

103-
return fixed, count, nil
100+
return fixed, count
104101
}
105102

106103
// addImports ensures "bytes" and "io" are in the import block

cmd/ogen-fixerror/main_test.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,7 @@ func decodeTestResponse(resp *http.Response) (res TestRes, _ error) {
2626
resp.Body = io.NopCloser(bytes.NewReader(body))
2727
return res, validate.UnexpectedStatusCodeWithResponse(resp)`
2828

29-
fixed, count, err := FixUnexpectedStatusCodeBody([]byte(input))
30-
if err != nil {
31-
t.Fatalf("FixUnexpectedStatusCodeBody() error = %v", err)
32-
}
29+
fixed, count := FixUnexpectedStatusCodeBody([]byte(input))
3330

3431
if count != 1 {
3532
t.Errorf("count = %d, want 1", count)
@@ -64,10 +61,7 @@ func decode2(resp *http.Response) (res Res2, _ error) {
6461
}
6562
`
6663

67-
fixed, count, err := FixUnexpectedStatusCodeBody([]byte(input))
68-
if err != nil {
69-
t.Fatalf("FixUnexpectedStatusCodeBody() error = %v", err)
70-
}
64+
fixed, count := FixUnexpectedStatusCodeBody([]byte(input))
7165

7266
if count != 2 {
7367
t.Errorf("count = %d, want 2", count)
@@ -94,10 +88,7 @@ func decodeTest(resp *http.Response) (res TestRes, _ error) {
9488
}
9589
`
9690

97-
fixed, count, err := FixUnexpectedStatusCodeBody([]byte(input))
98-
if err != nil {
99-
t.Fatalf("FixUnexpectedStatusCodeBody() error = %v", err)
100-
}
91+
fixed, count := FixUnexpectedStatusCodeBody([]byte(input))
10192

10293
if count != 1 {
10394
t.Errorf("count = %d, want 1", count)

cmd/ogen-fixnull/main.go

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,14 @@ func run(args []string) error {
4444
return fmt.Errorf("read file: %w", err)
4545
}
4646

47-
fixed, count, err := FixOptDecodeNullHandling(content)
48-
if err != nil {
49-
return fmt.Errorf("fix null handling: %w", err)
50-
}
47+
fixed, count := FixOptDecodeNullHandling(content)
5148

5249
if count == 0 {
5350
fmt.Printf("No Opt* Decode methods needed fixing in %s\n", filename)
5451
return nil
5552
}
5653

57-
if err := os.WriteFile(filename, fixed, 0644); err != nil {
54+
if err := os.WriteFile(filename, fixed, 0600); err != nil {
5855
return fmt.Errorf("write file: %w", err)
5956
}
6057

@@ -88,7 +85,7 @@ func run(args []string) error {
8885
// }
8986
// o.Set = true
9087
// if err := o.Value.Decode(d); err != nil {
91-
func FixOptDecodeNullHandling(content []byte) ([]byte, int, error) {
88+
func FixOptDecodeNullHandling(content []byte) ([]byte, int) {
9289
// Pattern matches Opt* Decode methods that are missing null handling.
9390
// It captures:
9491
// 1. The type name (e.g., OptManualVerificationResponseModel)
@@ -142,5 +139,5 @@ func FixOptDecodeNullHandling(content []byte) ([]byte, int, error) {
142139
return result.Bytes()
143140
})
144141

145-
return fixed, count, nil
142+
return fixed, count
146143
}

cmd/ogen-fixnull/main_test.go

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,7 @@ func (o *OptBar) Decode(d *jx.Decoder) error {
148148

149149
for _, tt := range tests {
150150
t.Run(tt.name, func(t *testing.T) {
151-
fixed, count, err := FixOptDecodeNullHandling([]byte(tt.input))
152-
if err != nil {
153-
t.Fatalf("unexpected error: %v", err)
154-
}
151+
fixed, count := FixOptDecodeNullHandling([]byte(tt.input))
155152

156153
if count != tt.wantCount {
157154
t.Errorf("count = %d, want %d", count, tt.wantCount)
@@ -199,10 +196,7 @@ func SomeOtherFunc() {
199196
}
200197
`
201198

202-
fixed, count, err := FixOptDecodeNullHandling([]byte(input))
203-
if err != nil {
204-
t.Fatalf("unexpected error: %v", err)
205-
}
199+
fixed, count := FixOptDecodeNullHandling([]byte(input))
206200

207201
if count != 1 {
208202
t.Errorf("count = %d, want 1", count)

0 commit comments

Comments
 (0)