Skip to content

Commit 2327bba

Browse files
committed
chore: update golangci-lint; enable revive & address lints
Signed-off-by: Tyler Gillson <tyler.gillson@gmail.com>
1 parent 737741d commit 2327bba

File tree

8 files changed

+169
-121
lines changed

8 files changed

+169
-121
lines changed

.golangci.yaml

Lines changed: 28 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,53 +1,34 @@
1-
## golangci-lint v1.55.2
2-
3-
# References:
4-
# - https://golangci-lint.run/usage/linters/
5-
# - https://gist.github.com/maratori/47a4d00457a92aa426dbd48a18776322
6-
71
run:
8-
timeout: 10m # default 1m
9-
10-
linters-settings:
11-
gosimple:
12-
go: "1.21" # default 1.13
13-
govet:
14-
enable-all: true
15-
disable:
16-
- fieldalignment # too strict
17-
- shadow # too strict
18-
staticcheck:
19-
go: "1.21" # default 1.13
2+
timeout: 5m
3+
allow-parallel-runners: true
204

21-
# Non-default
22-
cyclop:
23-
max-complexity: 15 # maximal code complexity to report; default 10
24-
package-average: 0.0 # maximal average package complexity to report; default 0.0
25-
gocognit:
26-
min-complexity: 30 # minimal code complexity to report; default: 30
5+
issues:
6+
# don't skip warning about doc comments
7+
# don't exclude the default set of lint
8+
exclude-use-default: false
9+
exclude-files:
10+
- ".*test\\.go$"
2711

2812
linters:
2913
disable-all: true
3014
enable:
31-
## enabled by default
32-
- errcheck # Errcheck is a program for checking for unchecked errors in go programs. These unchecked errors can be critical bugs in some cases
33-
- ineffassign # Detects when assignments to existing variables are not used
34-
- typecheck # Like the front-end of a Go compiler, parses and type-checks Go code
35-
- gosimple # Linter for Go source code that specializes in simplifying a code
36-
- govet # Vet examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string
37-
- unused # Checks Go code for unused constants, variables, functions and types
38-
- staticcheck # Staticcheck is a go vet on steroids, applying a ton of static analysis checks
39-
## disabled by default
40-
- cyclop # checks function and package cyclomatic complexity
41-
- gocognit # Computes and checks the cognitive complexity of functions
42-
43-
issues:
44-
max-issues-per-linter: 0
45-
max-same-issues: 0
46-
exclude-rules:
47-
- path: _test\.go
48-
linters:
49-
- errcheck
50-
- gosimple
51-
- ineffassign
52-
- staticcheck
53-
- unused
15+
- dupl
16+
- errcheck
17+
- exportloopref
18+
- ginkgolinter
19+
- goconst
20+
- gocyclo
21+
- gofmt
22+
- goimports
23+
- gosimple
24+
- govet
25+
- ineffassign
26+
- misspell
27+
- nakedret
28+
- prealloc
29+
- revive
30+
- staticcheck
31+
- typecheck
32+
- unconvert
33+
- unparam
34+
- unused

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
# binary versions
77
BIN_DIR ?= ./bin
8-
GOLANGCI_VERSION ?= 1.55.2
8+
GOLANGCI_VERSION ?= 1.59.1
99

1010
GOOS ?= $(shell go env GOOS)
1111
GOARCH ?= $(shell go env GOARCH)

prompts/file.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,10 @@ import (
1313
)
1414

1515
var (
16-
editorBinary = "vi"
17-
editorPath = ""
16+
editorBinary = "vi"
17+
editorPath = ""
18+
19+
// GetCmdExecutor allows monkey-patching the command executor for testing purposes.
1820
GetCmdExecutor = getEditorExecutor
1921
)
2022

prompts/mocks/file_editor.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
// Package mocks contains mock implementations of the interfaces in the prompts package for testing purposes.
2+
package mocks
3+
4+
import (
5+
"os"
6+
)
7+
8+
// CommandExecutor is an interface for executing commands.
9+
type CommandExecutor interface {
10+
Start() error
11+
Wait() error
12+
}
13+
14+
// MockFileEditor is a mock implementation of the FileEditor interface for testing purposes.
15+
type MockFileEditor struct {
16+
FileContents []string
17+
filename string
18+
}
19+
20+
// Start writes the next value in the FileContents slice to the file.
21+
func (m *MockFileEditor) Start() error {
22+
if err := os.WriteFile(m.filename, []byte(m.FileContents[0]), 0600); err != nil {
23+
return err
24+
}
25+
m.FileContents = m.FileContents[1:]
26+
return nil
27+
}
28+
29+
// Wait is a no-op to satisfy the CommandExecutor interface.
30+
func (m *MockFileEditor) Wait() error {
31+
return nil
32+
}
33+
34+
// GetCmdExecutor returns a CommandExecutor that writes to the given filename.
35+
func (m *MockFileEditor) GetCmdExecutor(_ string, filename string) CommandExecutor {
36+
m.filename = filename
37+
return m
38+
}

prompts/mocks/file_editor_mocks.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

prompts/mocks/prompt_mocks.go renamed to prompts/mocks/prompts.go

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"golang.org/x/exp/slices"
88
)
99

10+
// MockTUI is a mock implementation of the TUI interface for testing purposes.
1011
type MockTUI struct {
1112
Values []string
1213
SliceValues [][]string
@@ -15,7 +16,8 @@ type MockTUI struct {
1516
validateSlice func([]string) error
1617
}
1718

18-
func (m *MockTUI) GetBool(prompt string, defaultVal bool) (bool, error) {
19+
// GetBool returns the next value in the Values slice as a bool.
20+
func (m *MockTUI) GetBool(_ string, defaultVal bool) (bool, error) {
1921
val, err := m.run()
2022
if err != nil {
2123
return false, err
@@ -30,21 +32,24 @@ func (m *MockTUI) GetBool(prompt string, defaultVal bool) (bool, error) {
3032
return val == "y", err
3133
}
3234

33-
func (m *MockTUI) GetText(prompt, defaultVal, mask string, optional bool, validate func(string) error) (string, error) {
35+
// GetText returns the next value in the Values slice as a string.
36+
func (m *MockTUI) GetText(_, _, _ string, _ bool, validate func(string) error) (string, error) {
3437
if validate != nil {
3538
m.validate = validate
3639
}
3740
return m.run()
3841
}
3942

40-
func (m *MockTUI) GetTextSlice(prompt, defaultVal string, optional bool, validate func([]string) error) ([]string, error) {
43+
// GetTextSlice returns the next value in the SliceValues slice as a []string.
44+
func (m *MockTUI) GetTextSlice(_, _ string, _ bool, validate func([]string) error) ([]string, error) {
4145
if validate != nil {
4246
m.validateSlice = validate
4347
}
4448
return m.runSlice()
4549
}
4650

47-
func (m *MockTUI) GetSelection(prompt string, options []string) (string, error) {
51+
// GetSelection returns the next value in the Values slice as a string.
52+
func (m *MockTUI) GetSelection(_ string, options []string) (string, error) {
4853
val, err := m.run()
4954
if err != nil {
5055
return val, err
@@ -55,7 +60,8 @@ func (m *MockTUI) GetSelection(prompt string, options []string) (string, error)
5560
return val, nil
5661
}
5762

58-
func (m *MockTUI) GetMultiSelection(prompt string, options []string, minSelections int) ([]string, error) {
63+
// GetMultiSelection returns the next minSelections values in the Values slice as a []string.
64+
func (m *MockTUI) GetMultiSelection(_ string, _ []string, minSelections int) ([]string, error) {
5965
vals := make([]string, 0)
6066
for i := 0; i < minSelections; i++ {
6167
val, err := m.run()

0 commit comments

Comments
 (0)