Skip to content

Commit 92f4c23

Browse files
fix lint
1 parent dfb8330 commit 92f4c23

File tree

9 files changed

+38
-161
lines changed

9 files changed

+38
-161
lines changed

.golangci.yaml

Lines changed: 6 additions & 138 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,10 @@ version: "2"
22

33
# Options for analysis running.
44
run:
5-
# Timeout for analysis, e.g. 30s, 5m.
6-
# Default: 1m
7-
timeout: 10m
8-
9-
# The default concurrency value is the number of available CPU.
10-
concurrency: 4
11-
12-
# Which dirs to skip: issues from them won't be reported.
13-
# Can use regexp here: `generated.*`, regexp is applied on full path,
14-
# including the path prefix if one is set.
15-
# Default value is empty list,
16-
# but default dirs are skipped independently of this option's value (see skip-dirs-use-default).
17-
# "/" will be replaced by current OS file path separator to properly work on Windows.
18-
skip-dirs:
19-
- bin
20-
- docs
21-
- examples
22-
- hack
23-
24-
# output configuration options.
25-
output:
26-
# Format: colored-line-number|line-number|json|colored-tab|tab|checkstyle|code-climate|junit-xml|github-actions|teamcity
27-
#
28-
# Multiple can be specified by separating them by comma, output can be provided
29-
# for each of them by separating format name and path by colon symbol.
30-
# Output path can be either `stdout`, `stderr` or path to the file to write to.
31-
# Example: "checkstyle:report.xml,json:stdout,colored-line-number"
32-
#
33-
# Default: colored-line-number
34-
format: colored-line-number
35-
36-
# Print lines of code with issue.
37-
# Default: true
38-
print-issued-lines: true
39-
40-
# Print linter name in the end of issue text.
41-
# Default: true
42-
print-linter-lines: true
5+
# Timeout for total work, e.g. 30s, 5m, 5m30s.
6+
# If the value is lower or equal to 0, the timeout is disabled.
7+
# Default: 0 (disabled)
8+
timeout: 5m
439

4410
linters:
4511
# Default set of linters.
@@ -49,107 +15,9 @@ linters:
4915
# - `none`: disables all linters by default.
5016
# - `fast`: enables only linters considered as "fast" (`golangci-lint help linters --json | jq '[ .[] | select(.fast==true) ] | map(.name)'`).
5117
# Default: standard
52-
default: all
53-
# All available settings of specific linters.
54-
settings:
55-
# See the dedicated "linters.settings" documentation section.
56-
option: value
57-
# Defines a set of rules to ignore issues.
58-
# It does not skip the analysis, and so does not ignore "typecheck" errors.
59-
exclusions:
60-
# Mode of the generated files analysis.
61-
#
62-
# - `strict`: sources are excluded by strictly following the Go generated file convention.
63-
# Source files that have lines matching only the following regular expression will be excluded: `^// Code generated .* DO NOT EDIT\.$`
64-
# This line must appear before the first non-comment, non-blank text in the file.
65-
# https://go.dev/s/generatedcode
66-
# - `lax`: sources are excluded if they contain lines like `autogenerated file`, `code generated`, `do not edit`, etc.
67-
# - `disable`: disable the generated files exclusion.
68-
#
69-
# Default: strict
70-
generated: lax
71-
# Log a warning if an exclusion rule is unused.
72-
# Default: false
73-
warn-unused: true
74-
# Predefined exclusion rules.
75-
# Default: []
76-
presets:
77-
- comments
78-
- std-error-handling
79-
- common-false-positives
80-
- legacy
81-
# Excluding configuration per-path, per-linter, per-text and per-source.
82-
rules:
83-
# Exclude some linters from running on tests files.
84-
- path: _test\.go
85-
linters:
86-
- gocyclo
87-
- errcheck
88-
- dupl
89-
- gosec
90-
# Run some linter only for test files by excluding its issues for everything else.
91-
- path-except: _test\.go
92-
linters:
93-
- forbidigo
94-
# Exclude known linters from partially hard-vendored code,
95-
# which is impossible to exclude via `nolint` comments.
96-
# `/` will be replaced by the current OS file path separator to properly work on Windows.
97-
- path: internal/hmac/
98-
text: "weak cryptographic primitive"
99-
linters:
100-
- gosec
101-
# Exclude some `staticcheck` messages.
102-
- linters:
103-
- staticcheck
104-
text: "SA9003:"
105-
# Exclude `lll` issues for long lines with `go:generate`.
106-
- linters:
107-
- lll
108-
source: "^//go:generate "
109-
# Which file paths to exclude: they will be analyzed, but issues from them won't be reported.
110-
# "/" will be replaced by the current OS file path separator to properly work on Windows.
111-
# Default: []
112-
paths:
113-
- ".*\\.my\\.go$"
114-
- lib/bad.go
115-
# Which file paths to not exclude.
116-
# Default: []
117-
paths-except:
118-
- ".*\\.my\\.go$"
119-
- lib/bad.go
18+
default: standard
12019

12120
formatters:
12221
# Enable specific formatter.
12322
# Default: [] (uses standard Go formatting)
124-
enable:
125-
- gci
126-
- gofmt
127-
- gofumpt
128-
- goimports
129-
- golines
130-
- swaggo
131-
# Formatters settings.
132-
settings:
133-
# See the dedicated "formatters.settings" documentation section.
134-
option: value
135-
exclusions:
136-
# Log a warning if an exclusion path is unused.
137-
# Default: false
138-
warn-unused: true
139-
# Mode of the generated files analysis.
140-
#
141-
# - `strict`: sources are excluded by strictly following the Go generated file convention.
142-
# Source files that have lines matching only the following regular expression will be excluded: `^// Code generated .* DO NOT EDIT\.$`
143-
# This line must appear before the first non-comment, non-blank text in the file.
144-
# https://go.dev/s/generatedcode
145-
# - `lax`: sources are excluded if they contain lines like `autogenerated file`, `code generated`, `do not edit`, etc.
146-
# - `disable`: disable the generated files exclusion.
147-
#
148-
# Default: lax
149-
generated: strict
150-
# Which file paths to exclude.
151-
# This option is ignored when using `--stdin` as the path is unknown.
152-
# Default: []
153-
paths:
154-
- ".*\\.my\\.go$"
155-
- lib/bad.go
23+
enable: []

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
module github.com/GreptimeTeam/gtctl
22

3-
go 1.18
3+
go 1.25
44

55
require (
66
github.com/GreptimeTeam/greptimedb-operator v0.1.0-alpha.9

pkg/artifacts/manager.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ func (m *manager) downloadFromHTTP(ctx context.Context, httpURL string, dest str
246246
if resp.StatusCode != http.StatusOK {
247247
return fmt.Errorf("download failed, status code: %d", resp.StatusCode)
248248
}
249-
defer resp.Body.Close()
249+
defer fileutils.MustClose(resp.Body)
250250

251251
data, err := io.ReadAll(resp.Body)
252252
if err != nil {
@@ -306,7 +306,7 @@ func (m *manager) chartIndexFile(ctx context.Context, indexURL string) (*repo.In
306306
if err != nil {
307307
return nil, err
308308
}
309-
defer rsp.Body.Close()
309+
defer fileutils.MustClose(rsp.Body)
310310

311311
data, err := io.ReadAll(rsp.Body)
312312
if err != nil {
@@ -431,7 +431,7 @@ func (m *manager) installBinaries(downloadFile, installDir string) error {
431431
if err != nil {
432432
return err
433433
}
434-
defer os.RemoveAll(tempDir)
434+
defer fileutils.RemoveAll(tempDir)
435435

436436
if err := fileutils.Uncompress(downloadFile, tempDir); err != nil {
437437
return err
@@ -525,7 +525,7 @@ func (m *manager) getVersionInfoFromS3(typ ArtifactType, name string, nightly bo
525525
if resp.StatusCode != http.StatusOK {
526526
return "", fmt.Errorf("get latest info from '%s' failed, status code: %d", latestVersionInfoURL, resp.StatusCode)
527527
}
528-
defer resp.Body.Close()
528+
defer fileutils.MustClose(resp.Body)
529529

530530
data, err := io.ReadAll(resp.Body)
531531
if err != nil {

pkg/artifacts/manager_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ import (
2626
"sigs.k8s.io/kind/pkg/log"
2727

2828
"github.com/GreptimeTeam/gtctl/pkg/logger"
29+
"github.com/GreptimeTeam/gtctl/pkg/utils/file"
2930
)
3031

3132
func TestDownloadCharts(t *testing.T) {
3233
tempDir, err := os.MkdirTemp("/tmp", "gtctl-ut-")
3334
if err != nil {
3435
t.Fatal(err)
3536
}
36-
defer os.RemoveAll(tempDir)
37+
defer file.RemoveAll(tempDir)
3738

3839
m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
3940
if err != nil {
@@ -79,7 +80,7 @@ func TestDownloadChartsFromCNRegion(t *testing.T) {
7980
if err != nil {
8081
t.Fatal(err)
8182
}
82-
defer os.RemoveAll(tempDir)
83+
defer file.RemoveAll(tempDir)
8384

8485
m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
8586
if err != nil {
@@ -125,7 +126,7 @@ func TestDownloadBinariesFromCNRegion(t *testing.T) {
125126
if err != nil {
126127
t.Fatal(err)
127128
}
128-
defer os.RemoveAll(tempDir)
129+
defer file.RemoveAll(tempDir)
129130

130131
m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
131132
if err != nil {
@@ -171,7 +172,7 @@ func TestDownloadBinaries(t *testing.T) {
171172
if err != nil {
172173
t.Fatal(err)
173174
}
174-
defer os.RemoveAll(tempDir)
175+
defer file.RemoveAll(tempDir)
175176

176177
m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
177178
if err != nil {
@@ -218,7 +219,7 @@ func TestArtifactsCache(t *testing.T) {
218219
if err != nil {
219220
t.Fatal(err)
220221
}
221-
defer os.RemoveAll(tempDir)
222+
defer file.RemoveAll(tempDir)
222223

223224
m, err := NewManager(logger.New(os.Stdout, log.Level(4), logger.WithColored()))
224225
if err != nil {

pkg/helm/loader_test.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/GreptimeTeam/gtctl/pkg/artifacts"
2727
opt "github.com/GreptimeTeam/gtctl/pkg/cluster"
2828
"github.com/GreptimeTeam/gtctl/pkg/logger"
29+
"github.com/GreptimeTeam/gtctl/pkg/utils/file"
2930
)
3031

3132
const (
@@ -37,7 +38,7 @@ func TestLoadAndRenderChart(t *testing.T) {
3738
if err != nil {
3839
t.Errorf("failed to create render: %v", err)
3940
}
40-
defer cleanMetadataDir()
41+
defer file.RemoveAll(testMetadataDir)
4142

4243
opts := &LoadOptions{
4344
ReleaseName: "gtctl-ut",
@@ -73,7 +74,3 @@ func TestLoadAndRenderChart(t *testing.T) {
7374
t.Errorf("expected %s, got %s", string(wantedManifests), string(manifests))
7475
}
7576
}
76-
77-
func cleanMetadataDir() {
78-
os.RemoveAll(testMetadataDir)
79-
}

pkg/kube/client.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func NewClient(kubeconfig string) (*Client, error) {
109109

110110
kubeVersion, err := kubeClient.ServerVersion()
111111
if err != nil {
112-
return nil, fmt.Errorf("failed to get kubernetes server version: %v\n", err)
112+
return nil, fmt.Errorf("failed to get kubernetes server version: %v", err)
113113
}
114114
helm.KubeVersion = kubeVersion.String()
115115

pkg/metadata/manager_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,15 @@ import (
2626

2727
"github.com/GreptimeTeam/gtctl/pkg/artifacts"
2828
"github.com/GreptimeTeam/gtctl/pkg/config"
29+
"github.com/GreptimeTeam/gtctl/pkg/utils/file"
2930
)
3031

3132
func TestMetadataManager(t *testing.T) {
3233
tempDir, err := os.MkdirTemp("/tmp", "gtctl-ut-")
3334
if err != nil {
3435
t.Fatal(err)
3536
}
36-
defer os.RemoveAll(tempDir)
37+
defer file.RemoveAll(tempDir)
3738

3839
m, err := New(tempDir)
3940
if err != nil {

pkg/utils/file/file.go

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,13 @@ func CopyFile(src, dst string) error {
7373
if err != nil {
7474
return err
7575
}
76-
defer r.Close()
76+
defer MustClose(r)
7777

7878
w, err := os.Create(dst)
7979
if err != nil {
8080
return err
8181
}
82-
defer w.Close()
82+
defer MustClose(w)
8383

8484
_, err = io.Copy(w, r)
8585
if err != nil {
@@ -115,7 +115,7 @@ func unzip(file, dst string) error {
115115
if err != nil {
116116
return err
117117
}
118-
defer archive.Close()
118+
defer MustClose(archive)
119119

120120
for _, f := range archive.File {
121121
filePath := filepath.Join(dst, f.Name)
@@ -210,3 +210,15 @@ func untar(file, dst string) error {
210210

211211
return nil
212212
}
213+
214+
func MustClose(c io.Closer) {
215+
if err := c.Close(); err != nil {
216+
_ = fmt.Errorf("failed to close: %v", err)
217+
}
218+
}
219+
220+
func RemoveAll(path string) {
221+
if err := os.RemoveAll(path); err != nil {
222+
_ = fmt.Errorf("failed to remove path %s: %v", path, err)
223+
}
224+
}

pkg/utils/file/file_test.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,7 @@ func TestUncompress(t *testing.T) {
3939
}
4040

4141
// Clean up output dir.
42-
defer func() {
43-
os.RemoveAll(outputDir)
44-
}()
42+
defer RemoveAll(outputDir)
4543

4644
for _, test := range tests {
4745
if err := Uncompress(test.path, test.dst); err != nil {

0 commit comments

Comments
 (0)