Skip to content

Commit 67e61eb

Browse files
committed
chore: check and fix suppressed linter warnings (#38)
* check linters such as: * golint * gosec * gocritic * goimports * gonmd * revive * stylecheck * wsl * remove the `new-from-rev` configuration option from `.golangci.yml`
1 parent ffae354 commit 67e61eb

File tree

14 files changed

+80
-118
lines changed

14 files changed

+80
-118
lines changed

.golangci.yml

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,20 @@ linters-settings:
1313
errcheck:
1414
check-type-assertions: false
1515
check-blank: false
16-
exclude: ./errcheck_excludes.txt
16+
exclude-functions:
17+
- (*os.File).Close
18+
errorlint:
19+
errorf: true
20+
asserts: true
21+
comparison: true
1722
gofmt:
1823
simplify: true
24+
gofumpt:
25+
lang-version: "1.17"
26+
extra-rules: false
27+
gosimple:
28+
go: "1.17"
29+
checks: [ "all" ]
1930
goimports:
2031
local-prefixes: gitlab.com/postgres-ai/database-lab
2132
dupl:
@@ -29,7 +40,7 @@ linters-settings:
2940
gomnd:
3041
settings:
3142
mnd:
32-
ignored-functions: strconv.Format*,os.*
43+
ignored-functions: strconv.Format*,os.*,strconv.Parse*,strings.SplitN,bytes.SplitN
3344
revive:
3445
min-confidence: 0.8
3546
unused:
@@ -50,6 +61,8 @@ linters-settings:
5061
- hugeParam
5162
enabled-tags:
5263
- performance
64+
disabled-tags:
65+
- experimental
5366

5467
linters:
5568
enable:
@@ -99,5 +112,3 @@ issues:
99112
exclude-use-default: false
100113
max-issues-per-linter: 0
101114
max-same-issues: 0
102-
103-
new-from-rev: 9e951ebe

cmd/database-lab/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ func main() {
7575

7676
pm := pool.NewPoolManager(&cfg.PoolManager, runner)
7777
if err := pm.ReloadPools(); err != nil {
78-
log.Fatal(err.Error())
78+
log.Err(err.Error())
79+
return
7980
}
8081

8182
internalNetworkID, err := networks.Setup(ctx, dockerCLI, engProps.InstanceID, engProps.ContainerName)

errcheck_excludes.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

internal/estimator/profile.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,11 @@ func (p *Profiler) RenderStat() string {
293293
return p.out.String()
294294
}
295295

296+
const (
297+
percentColumnSize = 6
298+
timingColumnSize = 12
299+
)
300+
296301
// printHeader prints stats header.
297302
func (p *Profiler) printHeader() {
298303
p.out.WriteString(fmt.Sprintf("%% time seconds wait_event\n"))
@@ -320,14 +325,16 @@ func (p *Profiler) printStat() {
320325

321326
// Print stats and calculating totals.
322327
for _, e := range eventsList {
323-
p.out.WriteString(fmt.Sprintf("%-*.2f %*.6f %s\n", 6, p.waitEventPercents[e.waitEventName], 12, e.waitEventValue, e.waitEventName))
328+
p.out.WriteString(fmt.Sprintf("%-*.2f %*.6f %s\n", percentColumnSize, p.waitEventPercents[e.waitEventName],
329+
timingColumnSize, e.waitEventValue, e.waitEventName))
330+
324331
totalPct += p.waitEventPercents[e.waitEventName]
325332
totalTime += e.waitEventValue
326333
}
327334

328335
// Print totals.
329336
p.out.WriteString("------ ------------ -----------------------------\n")
330-
p.out.WriteString(fmt.Sprintf("%-*.2f %*.6f\n", 6, totalPct, 12, totalTime))
337+
p.out.WriteString(fmt.Sprintf("%-*.2f %*.6f\n", percentColumnSize, totalPct, timingColumnSize, totalTime))
331338
}
332339

333340
// EstimateTime estimates time.

internal/provision/databases/postgres/postgres.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ func Stop(r runners.Runner, p *resources.Pool, name string) error {
131131
}
132132

133133
log.Msg("docker container was not found, ignore", err)
134-
135134
}
136135

137136
if _, err := r.Run("rm -rf " + p.SocketCloneDir(name) + "/*"); err != nil {

internal/provision/pool/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ func NewManager(runner runners.Runner, config ManagerConfig) (FSManager, error)
8585
}
8686

8787
default:
88-
return nil, errors.New(fmt.Sprintf(`unsupported thin-clone manager specified: "%s"`, config.Pool.Mode))
88+
return nil, fmt.Errorf(`unsupported thin-clone manager specified: "%s"`, config.Pool.Mode)
8989
}
9090

9191
log.Dbg(fmt.Sprintf(`Using "%s" thin-clone manager.`, config.Pool.Mode))

internal/provision/runners/runners.go

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ const (
3030
sudoParams = "--non-interactive"
3131
)
3232

33+
// Runner runs commands.
3334
type Runner interface {
3435
Run(string, ...bool) (string, error)
3536
}
3637

38+
// RunnerError represents a runner error.
3739
type RunnerError struct {
3840
Msg string
3941
ExitStatus int
@@ -51,12 +53,10 @@ func NewRunnerError(command string, stderr string, e error) error {
5153
case (*exec.ExitError):
5254
// SO: https://stackoverflow.com/questions/10385551/get-exit-code-go.
5355
// The program has exited with an exit code != 0
54-
5556
// This works on both Unix and Windows. Although package
5657
// syscall is generally platform dependent, WaitStatus is
5758
// defined for both Unix and Windows and in both cases has
5859
// an ExitStatus() method with the same signature.
59-
6060
if status, ok := err.Sys().(syscall.WaitStatus); ok {
6161
exitStatus = status.ExitStatus()
6262
}
@@ -72,11 +72,12 @@ func NewRunnerError(command string, stderr string, e error) error {
7272
}
7373
}
7474

75+
// Error returns runner error.
7576
func (e RunnerError) Error() string {
7677
return e.Msg
7778
}
7879

79-
// Local.
80+
// LocalRunner represents implementation of a local runner.
8081
type LocalRunner struct {
8182
UseSudo bool
8283
}
@@ -90,6 +91,7 @@ func NewLocalRunner(useSudo bool) *LocalRunner {
9091
return r
9192
}
9293

94+
// Run executes command.
9395
func (r *LocalRunner) Run(command string, options ...bool) (string, error) {
9496
command = strings.Trim(command, " \n")
9597
if len(command) == 0 {
@@ -104,9 +106,6 @@ func (r *LocalRunner) Run(command string, options ...bool) (string, error) {
104106
log.Dbg(fmt.Sprintf(`Run(Local): "%s"`, logCommand))
105107
}
106108

107-
var out bytes.Buffer
108-
var stderr bytes.Buffer
109-
110109
if runtime.GOOS == "windows" {
111110
return "", errors.New("Windows is not supported")
112111
}
@@ -117,6 +116,11 @@ func (r *LocalRunner) Run(command string, options ...bool) (string, error) {
117116

118117
cmd := exec.Command("/bin/bash", "-c", command)
119118

119+
var (
120+
out bytes.Buffer
121+
stderr bytes.Buffer
122+
)
123+
120124
cmd.Stdout = &out
121125
cmd.Stderr = &stderr
122126

internal/provision/thinclones/lvm/lvmanager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ func (m *LVManager) GetSessionState(_ string) (*resources.SessionState, error) {
125125
return &resources.SessionState{}, nil
126126
}
127127

128-
// GetDiskState is not implemented.
128+
// GetFilesystemState is not implemented.
129129
func (m *LVManager) GetFilesystemState() (models.FileSystem, error) {
130130
// TODO(anatoly): Implement.
131131
return models.FileSystem{Mode: PoolMode}, nil

pkg/client/dblabapi/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919
"time"
2020

2121
"github.com/pkg/errors"
22+
2223
"gitlab.com/postgres-ai/database-lab/v3/pkg/log"
2324
"gitlab.com/postgres-ai/database-lab/v3/pkg/models"
2425
)

pkg/client/platform/client.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
"strings"
1818

1919
"github.com/pkg/errors"
20+
2021
"gitlab.com/postgres-ai/database-lab/v3/pkg/log"
2122
)
2223

0 commit comments

Comments
 (0)