Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 34 additions & 33 deletions .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ linters:
- copyloopvar
- decorder
- dogsled
# - dupl # temporarily disabled - has 2 issues
- dupl
- dupword
- durationcheck
- errcheck
- errchkjson
- errname
- exhaustive
Expand All @@ -32,14 +33,14 @@ linters:
- gomoddirectives
- gomodguard
- goprintffuncname
# - gosmopolitan # temporarily disabled - has 2 issues
- gosmopolitan
- govet
- grouper
- iface
- importas
- ineffassign
- interfacebloat
# - lll # temporarily disabled - has 50 issues
- lll
- loggercheck
- makezero
- mirror
Expand All @@ -48,7 +49,7 @@ linters:
- nilerr
- nilnesserr
- noctx
# - nolintlint # temporarily disabled - has 4 issues
- nolintlint
- nosprintfhostport
- predeclared
- promlinter
Expand All @@ -60,6 +61,7 @@ linters:
- sloglint
- spancheck
- sqlclosecheck
- staticcheck
- tagliatelle
- testableexamples
- tparallel
Expand All @@ -76,8 +78,6 @@ linters:
# These linters are disabled ONLY because fixing/investigating their complaints initially was too overwhelming.
# We SHOULD try and evaluate each of them eventually and either fix their reports
# or comment here on why we decided to not listen to them.
- errcheck # temporarily disabled - has 11 issues
- staticcheck # temporarily disabled - has 7 issues
- cyclop
- depguard
- err113
Expand Down Expand Up @@ -109,6 +109,32 @@ linters:
- thelper
- varnamelen
- wrapcheck
settings:
errcheck:
check-type-assertions: true
check-blank: true
lll:
line-length: 250
dupl:
threshold: 400
govet:
settings:
printf:
funcs:
- (github.com/kudobuilder/kuttl/internal/utils.Logger).Logf
- (github.com/kudobuilder/kuttl/internal/utils.TestLogger).Logf
- (github.com/kudobuilder/kuttl/internal/case.clientWithKubeConfig).Logf
- (github.com/kudobuilder/kuttl/internal/case.clientWithKubeConfig).Wrapf
# TODO: fix the `context` usage in step package and enable these linters.
usetesting:
context-background: false
context-todo: false
exclusions:
paths:
- hack
- dist
- keps
- kind-*

formatters:
enable:
Expand All @@ -117,31 +143,6 @@ formatters:
settings:
goimports:
# Don't use 'github.com/kudobuilder/kuttl', it'll result in unreliable output!
local-prefixes: github.com/kudobuilder
local-prefixes:
- github.com/kudobuilder

linters-settings:
errcheck:
check-type-assertions: true
check-blank: true
lll:
line-length: 250
dupl:
threshold: 400
govet:
settings:
printf:
funcs:
- (github.com/kudobuilder/kuttl/internal/utils.Logger).Logf
- (github.com/kudobuilder/kuttl/internal/utils.TestLogger).Logf
- (github.com/kudobuilder/kuttl/internal/case.clientWithKubeConfig).Logf
- (github.com/kudobuilder/kuttl/internal/case.clientWithKubeConfig).Wrapf
# TODO: fix the `context` usage in step package and enable these linters.
usetesting:
context-background: false
context-todo: false
issues:
exclude-dirs:
- hack
- dist
- keps
- kind-*
8 changes: 5 additions & 3 deletions internal/file/tar.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func UntarInPlace(path string) error {
if err != nil {
return err
}
defer file.Close()
defer file.Close() //nolint:errcheck

compressed := filepath.Ext(path) == ".tgz"
return UnTar(folder, file, compressed)
Expand All @@ -33,7 +33,7 @@ func UnTar(dest string, r io.Reader, compressed bool) (err error) {
if err != nil {
return err
}
defer gzr.Close()
defer gzr.Close() //nolint:errcheck
r = gzr
}
tr := tar.NewReader(r)
Expand Down Expand Up @@ -76,7 +76,9 @@ func UnTar(dest string, r io.Reader, compressed bool) (err error) {
return err
}

f.Close()
if err := f.Close(); err != nil {
return err
}
}
}
}
2 changes: 1 addition & 1 deletion internal/file/tar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ func TestUntarInPlace(t *testing.T) {
assert.NoError(t, err)

folder := "testdata/tar-test"
defer os.RemoveAll(folder)
defer os.RemoveAll(folder) //nolint:errcheck

fi, err := os.Stat(folder)
assert.NoError(t, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/harness/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ func (h *Harness) Config() (*rest.Config, error) {
return nil, err
}

defer f.Close()
defer f.Close() //nolint:errcheck
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be important to check for errors here? error on closing here could indicate that the config was not successfully written, no?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent point, I will change the code to propagate errors from Close on writable filehandles.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took a proper look at the Close() calls. It would be great if you could review the last commit @mclasmeier 🙏🏻


return h.config, kubernetes.Kubeconfig(h.config, f)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ func (c *Client) Download(url string, path string) error {
if err != nil {
return err
}
defer resp.Body.Close()
defer resp.Body.Close() //nolint:errcheck

_, err = os.Stat(path)
if err == nil || os.IsExist(err) {
Expand All @@ -88,7 +88,7 @@ func (c *Client) Download(url string, path string) error {
if err != nil {
return err
}
defer out.Close()
defer out.Close() //nolint:errcheck
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same question as before, is ignoring err here safe?


// Create our bytes counter and pass it to be used alongside our writer
counter := &writeCounter{Name: filepath.Base(path)}
Expand Down
8 changes: 4 additions & 4 deletions internal/kubernetes/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ func Kubeconfig(cfg *rest.Config, w io.Writer) error {
Name: "cluster",
Cluster: appsv1.Cluster{
Server: cfg.Host,
CertificateAuthorityData: cfg.TLSClientConfig.CAData,
InsecureSkipTLSVerify: cfg.TLSClientConfig.Insecure,
CertificateAuthorityData: cfg.CAData,
InsecureSkipTLSVerify: cfg.Insecure,
},
},
},
Expand All @@ -92,8 +92,8 @@ func Kubeconfig(cfg *rest.Config, w io.Writer) error {
{
Name: "user",
AuthInfo: appsv1.AuthInfo{
ClientCertificateData: cfg.TLSClientConfig.CertData,
ClientKeyData: cfg.TLSClientConfig.KeyData,
ClientCertificateData: cfg.CertData,
ClientKeyData: cfg.KeyData,
Token: cfg.BearerToken,
Username: cfg.Username,
Password: cfg.Password,
Expand Down
12 changes: 6 additions & 6 deletions internal/kubernetes/serialization.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ func convertUnstructured(in client.Object) (client.Object, error) {
if group != kuttlGroup {
return in, nil
}
switch {
case kind == "TestFile":
switch kind {
case "TestFile":
converted = &v1beta1.TestFile{}
case kind == "TestStep":
case "TestStep":
converted = &v1beta1.TestStep{}
case kind == "TestAssert":
case "TestAssert":
converted = &v1beta1.TestAssert{}
case kind == "TestSuite":
case "TestSuite":
converted = &v1beta1.TestSuite{}
default:
return in, nil
Expand Down Expand Up @@ -194,7 +194,7 @@ func LoadYAMLFromFile(path string) ([]client.Object, error) {
if err != nil {
return nil, err
}
defer opened.Close()
defer opened.Close() //nolint:errcheck

return LoadYAML(path, opened)
}
Expand Down
4 changes: 2 additions & 2 deletions internal/kubernetes/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
func TestLoadYAML(t *testing.T) {
tmpfile, err := os.CreateTemp(t.TempDir(), "test.yaml")
require.NoError(t, err)
defer tmpfile.Close()
defer tmpfile.Close() //nolint:errcheck

err = os.WriteFile(tmpfile.Name(), []byte(`
apiVersion: v1
Expand Down Expand Up @@ -147,7 +147,7 @@ func TestPrettyDiff(t *testing.T) {
func TestMatchesKind(t *testing.T) {
tmpfile, err := os.CreateTemp(t.TempDir(), "test.yaml")
require.NoError(t, err)
defer tmpfile.Close()
defer tmpfile.Close() //nolint:errcheck

err = os.WriteFile(tmpfile.Name(), []byte(`
apiVersion: v1
Expand Down
4 changes: 2 additions & 2 deletions internal/kuttlctl/cmd/values_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,14 +120,14 @@ func TestParseVars(t *testing.T) {
},
"unicode and special characters": {
input: map[string]string{
"unicode": "测试",
"unicode": "测试", //nolint:gosmopolitan // Unicode test data
"emoji": "🚀",
"special_chars": "name@domain.com",
"with_quotes": `"quoted string"`,
"with_backslash": `path\to\file`,
},
expected: map[string]any{
"unicode": "测试",
"unicode": "测试", //nolint:gosmopolitan // Unicode test data
"emoji": "🚀",
"special_chars": "name@domain.com",
"with_quotes": "quoted string",
Expand Down
Loading