Skip to content

Commit 6d5f23f

Browse files
committed
style: fix golangci-lint warnings across codebase
1 parent f321ede commit 6d5f23f

27 files changed

Lines changed: 113 additions & 115 deletions

.golangci.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1+
version: 2
2+
13
linters:
24
enable:
3-
- gofumpt
45
- thelper
5-
- goimports
66
- tparallel
77
- wastedassign
88
- unparam

lazypodman.exe

18.7 MB
Binary file not shown.

main.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ import (
1111
"github.com/docker/docker/client"
1212
"github.com/go-errors/errors"
1313
"github.com/integrii/flaggy"
14+
"github.com/jesseduffield/yaml"
1415
"github.com/m7medVision/lazypodman/pkg/app"
1516
"github.com/m7medVision/lazypodman/pkg/config"
1617
"github.com/m7medVision/lazypodman/pkg/utils"
17-
"github.com/jesseduffield/yaml"
1818
"github.com/samber/lo"
1919
)
2020

@@ -82,7 +82,9 @@ func main() {
8282
if err == nil {
8383
err = app.Run()
8484
}
85-
app.Close()
85+
if closeErr := app.Close(); closeErr != nil && err == nil {
86+
err = closeErr
87+
}
8688

8789
if err != nil {
8890
if errMessage, known := app.KnownError(err); known {

pkg/cheatsheet/generate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ func generateAtDir(dir string) {
3939
}
4040

4141
for lang := range i18n.GetTranslationSets() {
42-
os.Setenv("LC_ALL", lang)
42+
_ = os.Setenv("LC_ALL", lang)
4343
mApp, _ := app.NewApp(mConfig)
4444
mApp.Gui.SetupFakeGui()
4545

pkg/cheatsheet/validate.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ func Check() {
2020
if err != nil {
2121
log.Fatalf("Error occurred while checking if cheatsheets are up to date: %v", err)
2222
}
23-
defer os.RemoveAll(tmpDir)
23+
defer func() { _ = os.RemoveAll(tmpDir) }()
2424

2525
if err = os.Mkdir(tmpDir, 0o700); err != nil {
2626
log.Fatalf("Error occurred while checking if cheatsheets are up to date: %v", err)

pkg/commands/docker.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ func NewDockerCommand(log *logrus.Entry, osCommand *OSCommand, tr *i18n.Translat
179179
// `SSHHandler.HandleSSHDockerHost()` to create a local unix socket tunneled
180180
// over SSH to the specified ssh host.
181181
if strings.HasPrefix(dockerHost, "ssh://") {
182-
os.Setenv(dockerHostEnvKey, dockerHost)
182+
_ = os.Setenv(dockerHostEnvKey, dockerHost)
183183
}
184184

185185
tunnelCloser, err := ssh.NewSSHHandler(osCommand).HandleSSHDockerHost()
@@ -253,7 +253,7 @@ func (c *DockerCommand) CreateClientStatMonitor(container *Container) {
253253
return
254254
}
255255

256-
defer stream.Body.Close()
256+
defer func() { _ = stream.Body.Close() }()
257257

258258
scanner := bufio.NewScanner(stream.Body)
259259
for scanner.Scan() {

pkg/commands/docker_host_unix_test.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ func TestResolveDefaultDockerHostPrefersExistingPodmanSocket(t *testing.T) {
1212
originalRuntimeDir := os.Getenv("XDG_RUNTIME_DIR")
1313
originalStat := osStat
1414
defer func() {
15-
os.Setenv("XDG_RUNTIME_DIR", originalRuntimeDir)
15+
_ = os.Setenv("XDG_RUNTIME_DIR", originalRuntimeDir)
1616
osStat = originalStat
1717
}()
1818

19-
os.Setenv("XDG_RUNTIME_DIR", "/tmp/test-runtime")
19+
_ = os.Setenv("XDG_RUNTIME_DIR", "/tmp/test-runtime")
2020
expectedPath := filepath.Join("/tmp/test-runtime", "podman", "podman.sock")
2121
osStat = func(name string) (os.FileInfo, error) {
2222
if name == expectedPath {
@@ -34,11 +34,11 @@ func TestResolveDefaultDockerHostFallsBackToRootfulPodmanSocket(t *testing.T) {
3434
originalRuntimeDir := os.Getenv("XDG_RUNTIME_DIR")
3535
originalStat := osStat
3636
defer func() {
37-
os.Setenv("XDG_RUNTIME_DIR", originalRuntimeDir)
37+
_ = os.Setenv("XDG_RUNTIME_DIR", originalRuntimeDir)
3838
osStat = originalStat
3939
}()
4040

41-
os.Unsetenv("XDG_RUNTIME_DIR")
41+
_ = os.Unsetenv("XDG_RUNTIME_DIR")
4242
osStat = func(name string) (os.FileInfo, error) {
4343
return nil, os.ErrNotExist
4444
}

pkg/commands/docker_test.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,13 @@ func TestNewDockerClientVersionNegotiation(t *testing.T) {
2222
originalAPIVersion := os.Getenv("DOCKER_API_VERSION")
2323
defer func() {
2424
if originalAPIVersion == "" {
25-
os.Unsetenv("DOCKER_API_VERSION")
25+
_ = os.Unsetenv("DOCKER_API_VERSION")
2626
} else {
27-
os.Setenv("DOCKER_API_VERSION", originalAPIVersion)
27+
_ = os.Setenv("DOCKER_API_VERSION", originalAPIVersion)
2828
}
2929
}()
3030

31-
// Set DOCKER_API_VERSION to an old version that would cause
32-
// "client version 1.25 is too old" errors if negotiation is disabled
33-
os.Setenv("DOCKER_API_VERSION", "1.25")
31+
_ = os.Setenv("DOCKER_API_VERSION", "1.25")
3432

3533
t.Run("FromEnv locks version preventing negotiation", func(t *testing.T) {
3634
// This demonstrates the problematic behavior we're avoiding.
@@ -41,7 +39,7 @@ func TestNewDockerClientVersionNegotiation(t *testing.T) {
4139
client.WithAPIVersionNegotiation(),
4240
)
4341
assert.NoError(t, err)
44-
defer cli.Close()
42+
defer func() { _ = cli.Close() }()
4543

4644
// Version is locked to the env var value
4745
assert.Equal(t, "1.25", cli.ClientVersion())
@@ -53,7 +51,7 @@ func TestNewDockerClientVersionNegotiation(t *testing.T) {
5351
// (unix socket on Linux/macOS, named pipe on Windows).
5452
cli, err := newDockerClient(client.DefaultDockerHost)
5553
assert.NoError(t, err)
56-
defer cli.Close()
54+
defer func() { _ = cli.Close() }()
5755

5856
// Version is NOT locked to the env var value (1.25).
5957
// Instead, it uses the library's default version and will negotiate

pkg/commands/image.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func getHistoryResponseItemDisplayStrings(layer image.HistoryResponseItem) []str
5757
createdBy = utils.ColoredString(split[0], color.FgYellow) + " " + strings.Join(split[1:], " ")
5858
}
5959

60-
createdBy = strings.Replace(createdBy, "\t", " ", -1)
60+
createdBy = strings.ReplaceAll(createdBy, "\t", " ")
6161

6262
size := utils.FormatBinaryBytes(int(layer.Size))
6363
sizeColor := color.FgWhite
@@ -84,7 +84,8 @@ func (i *Image) RenderHistory() (string, error) {
8484
return getHistoryResponseItemDisplayStrings(layer)
8585
})
8686

87-
headers := [][]string{{"ID", "TAG", "SIZE", "COMMAND"}}
87+
headers := make([][]string, 1, 1+len(tableBody))
88+
headers[0] = []string{"ID", "TAG", "SIZE", "COMMAND"}
8889
table := append(headers, tableBody...)
8990

9091
return utils.RenderTable(table)

pkg/commands/os.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ func (c *OSCommand) Quote(message string) string {
220220
// Unquote removes wrapping quotations marks if they are present
221221
// this is needed for removing quotes from staged filenames with spaces
222222
func (c *OSCommand) Unquote(message string) string {
223-
return strings.Replace(message, `"`, "", -1)
223+
return strings.ReplaceAll(message, `"`, "")
224224
}
225225

226226
// AppendLineToFile adds a new line in file
@@ -229,7 +229,7 @@ func (c *OSCommand) AppendLineToFile(filename, line string) error {
229229
if err != nil {
230230
return WrapError(err)
231231
}
232-
defer f.Close()
232+
defer func() { _ = f.Close() }()
233233

234234
_, err = f.WriteString("\n" + line)
235235
if err != nil {

0 commit comments

Comments
 (0)