Skip to content

Commit 1d381f2

Browse files
committed
enforce lint in CI
Signed-off-by: Aravindhan Ayyanathan <aravindhan.a@est.tech>
1 parent d7f5964 commit 1d381f2

5 files changed

Lines changed: 20 additions & 19 deletions

File tree

go/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ lint: install-golangci-lint lint-modules
2525
lint-modules: $(MODULES)
2626
@for f in $(^D); do \
2727
(cd $$f; echo "Checking golangci-lint $$f"; \
28-
$(GOBIN)/golangci-lint run ./...); \
28+
$(GOBIN)/golangci-lint run ./...) || exit 1; \
2929
done
3030

3131
.PHONY: test

go/fn/internal/docs/render.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright 2025 The kpt Authors
1+
// Copyright 2025-2026 The kpt Authors
22
//
33
// Licensed under the Apache License, Version 2.0 (the "License");
44
// you may not use this file except in compliance with the License.
@@ -42,26 +42,26 @@ type DocOutput struct {
4242
// "no documentation available" message.
4343
func RenderHelp(w io.Writer, sections Sections, meta Metadata) {
4444
if sections.Short == "" && sections.Long == "" && sections.Examples == "" && isMetadataEmpty(meta) {
45-
fmt.Fprint(w, "No documentation available. Pass fn.WithDocs to fn.AsMain to enable --help.\n")
45+
_, _ = fmt.Fprint(w, "No documentation available. Pass fn.WithDocs to fn.AsMain to enable --help.\n")
4646
return
4747
}
4848

4949
if sections.Short != "" {
50-
fmt.Fprintf(w, "%s\n", sections.Short)
50+
_, _ = fmt.Fprintf(w, "%s\n", sections.Short)
5151
}
5252

5353
if sections.Long != "" {
5454
if sections.Short != "" {
55-
fmt.Fprint(w, "\n")
55+
_, _ = fmt.Fprint(w, "\n")
5656
}
57-
fmt.Fprintf(w, "%s\n", sections.Long)
57+
_, _ = fmt.Fprintf(w, "%s\n", sections.Long)
5858
}
5959

6060
if sections.Examples != "" {
6161
if sections.Short != "" || sections.Long != "" {
62-
fmt.Fprint(w, "\n")
62+
_, _ = fmt.Fprint(w, "\n")
6363
}
64-
fmt.Fprintf(w, "Examples:\n%s\n", sections.Examples)
64+
_, _ = fmt.Fprintf(w, "Examples:\n%s\n", sections.Examples)
6565
}
6666
}
6767

go/fn/run.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"fmt"
1919
"io"
2020
"os"
21+
"path/filepath"
2122
"slices"
2223
"strings"
2324

@@ -141,7 +142,7 @@ func AsMain(input any, opts ...Option) error {
141142
// handleHelp renders help text to STDOUT based on registered docs.
142143
func handleHelp(cfg *mainConfig) error {
143144
if cfg.readme == nil && cfg.metadata == nil {
144-
fmt.Fprint(os.Stdout, "No documentation available. Pass fn.WithDocs to fn.AsMain to enable --help.\n")
145+
_, _ = fmt.Fprint(os.Stdout, "No documentation available. Pass fn.WithDocs to fn.AsMain to enable --help.\n")
145146
return nil
146147
}
147148

@@ -159,7 +160,7 @@ func handleHelp(cfg *mainConfig) error {
159160
// handleDoc renders JSON documentation to STDOUT based on registered docs.
160161
func handleDoc(cfg *mainConfig) error {
161162
if cfg.readme == nil && cfg.metadata == nil {
162-
fmt.Fprint(os.Stdout, "{}")
163+
_, _ = fmt.Fprint(os.Stdout, "{}")
163164
return nil
164165
}
165166

@@ -183,7 +184,7 @@ func readFilesAsResourceList(paths []string) (*ResourceList, error) {
183184
FunctionConfig: NewEmptyKubeObject(),
184185
}
185186
for _, path := range paths {
186-
data, err := os.ReadFile(path)
187+
data, err := os.ReadFile(filepath.Clean(path))
187188
if err != nil {
188189
if os.IsNotExist(err) {
189190
return nil, fmt.Errorf("file not found: %s", path)

go/fn/run_filemode_property_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ func genKRMResource() *rapid.Generator[string] {
3838
for i := range numEntries {
3939
key := rapid.StringMatching(`[a-z][a-z0-9]{1,8}`).Draw(t, fmt.Sprintf("key%d", i))
4040
value := rapid.StringMatching(`[a-zA-Z0-9]{1,15}`).Draw(t, fmt.Sprintf("value%d", i))
41-
dataLines.WriteString(fmt.Sprintf(" %s: %s\n", key, value))
41+
fmt.Fprintf(&dataLines, " %s: %s\n", key, value)
4242
}
4343
return fmt.Sprintf(`apiVersion: v1
4444
kind: ConfigMap
@@ -65,7 +65,7 @@ func TestProperty6_FileModeEquivalence(t *testing.T) {
6565
if err != nil {
6666
t.Fatalf("failed to create temp dir: %v", err)
6767
}
68-
defer os.RemoveAll(tmpDir)
68+
defer func() { _ = os.RemoveAll(tmpDir) }()
6969

7070
var filePaths []string
7171
for i, res := range resources {

go/fn/run_flags_test.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ func captureStdout(t *testing.T, fn func()) string {
4444

4545
fn()
4646

47-
w.Close()
47+
_ = w.Close()
4848
os.Stdout = origStdout
4949

5050
var buf bytes.Buffer
5151
_, err = io.Copy(&buf, r)
5252
require.NoError(t, err)
53-
r.Close()
53+
_ = r.Close()
5454

5555
return buf.String()
5656
}
@@ -66,13 +66,13 @@ func captureStderr(t *testing.T, fn func()) string {
6666

6767
fn()
6868

69-
w.Close()
69+
_ = w.Close()
7070
os.Stderr = origStderr
7171

7272
var buf bytes.Buffer
7373
_, err = io.Copy(&buf, r)
7474
require.NoError(t, err)
75-
r.Close()
75+
_ = r.Close()
7676

7777
return buf.String()
7878
}
@@ -96,11 +96,11 @@ func TestAsMain_HelpFlag_ExitsZero(t *testing.T) {
9696
origStdin := os.Stdin
9797
r, w, err := os.Pipe()
9898
require.NoError(t, err)
99-
w.Close() // Close write end immediately — reading would get EOF
99+
_ = w.Close() // Close write end immediately — reading would get EOF
100100
os.Stdin = r
101101
t.Cleanup(func() {
102102
os.Stdin = origStdin
103-
r.Close()
103+
_ = r.Close()
104104
})
105105

106106
output := captureStdout(t, func() {

0 commit comments

Comments
 (0)