Skip to content

Commit 9aa7888

Browse files
authored
Merge pull request #280 from thaJeztah/linting_errors
Fix various linting issues and minor bugs
2 parents 65a3150 + d21c522 commit 9aa7888

File tree

12 files changed

+35
-37
lines changed

12 files changed

+35
-37
lines changed

.golangci.yml

-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ linters:
3232
disable-all: true
3333
enable:
3434
- bodyclose
35-
- depguard
3635
- dogsled
3736
- errcheck
3837
- errorlint

assert/assert_test.go

+5-3
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,14 @@ func TestAssertWithBoolMultiLineFailure(t *testing.T) {
105105
fakeT := &fakeTestingT{}
106106

107107
Assert(fakeT, func() bool {
108-
for range []int{1, 2, 3, 4} {
108+
for i := range []int{1, 2, 3, 4} {
109+
_ = i
109110
}
110111
return false
111112
}())
112113
expectFailNowed(t, fakeT, `assertion failed: expression is false: func() bool {
113-
for range []int{1, 2, 3, 4} {
114+
for i := range []int{1, 2, 3, 4} {
115+
_ = i
114116
}
115117
return false
116118
}()`)
@@ -244,7 +246,7 @@ func TestCheckEqualFailure(t *testing.T) {
244246
func TestCheck_MultipleFunctionsOnTheSameLine(t *testing.T) {
245247
fakeT := &fakeTestingT{}
246248

247-
f := func(b bool) {}
249+
f := func(bool) {}
248250
f(Check(fakeT, false))
249251
// TODO: update the expected when there is a more correct fix
250252
expectFailed(t, fakeT,

assert/cmp/compare.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ type causer interface {
248248
}
249249

250250
func formatErrorMessage(err error) string {
251-
//nolint:errorlint // unwrapping is not appropriate here
251+
//nolint:errorlint,nolintlint // unwrapping is not appropriate here
252252
if _, ok := err.(causer); ok {
253253
return fmt.Sprintf("%q\n%+v", err, err)
254254
}

assert/opt/opt_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -261,5 +261,5 @@ func TestPathDebug(t *testing.T) {
261261
"label1": {},
262262
},
263263
}
264-
gocmp.Equal(fixture, fixture, gocmp.FilterPath(PathDebug, gocmp.Ignore()))
264+
assert.Check(t, gocmp.Equal(fixture, fixture, gocmp.FilterPath(PathDebug, gocmp.Ignore())))
265265
}

fs/report.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,8 @@ func errProblem(reason string, err error) problem {
5050
return problem(fmt.Sprintf("%s: %s", reason, err))
5151
}
5252

53-
func existenceProblem(filename, reason string, args ...interface{}) problem {
54-
return problem(filename + ": " + fmt.Sprintf(reason, args...))
53+
func existenceProblem(filename string, msgAndArgs ...interface{}) problem {
54+
return problem(filename + ": " + format.Message(msgAndArgs...))
5555
}
5656

5757
func eqResource(x, y resource) []problem {

fs/report_test.go

+2-2
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ func TestMatchFileContent(t *testing.T) {
184184
defer dir.Remove()
185185

186186
t.Run("content matches", func(t *testing.T) {
187-
matcher := func(b []byte) CompareResult {
187+
matcher := func([]byte) CompareResult {
188188
return is.ResultSuccess
189189
}
190190
manifest := Expected(t,
@@ -193,7 +193,7 @@ func TestMatchFileContent(t *testing.T) {
193193
})
194194

195195
t.Run("content does not match", func(t *testing.T) {
196-
matcher := func(b []byte) CompareResult {
196+
matcher := func([]byte) CompareResult {
197197
return is.ResultFailure("data content differs from expected")
198198
}
199199
manifest := Expected(t,

internal/source/source.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func getNodeAtLine(fileset *token.FileSet, astFile ast.Node, lineNum int) (ast.N
7272
return node, err
7373
}
7474
}
75-
return nil, nil
75+
return nil, errors.New("failed to find expression")
7676
}
7777

7878
func scanToLine(fileset *token.FileSet, node ast.Node, lineNum int) ast.Node {
@@ -92,19 +92,16 @@ func scanToLine(fileset *token.FileSet, node ast.Node, lineNum int) ast.Node {
9292

9393
func getCallExprArgs(fileset *token.FileSet, astFile ast.Node, line int) ([]ast.Expr, error) {
9494
node, err := getNodeAtLine(fileset, astFile, line)
95-
switch {
96-
case err != nil:
95+
if err != nil {
9796
return nil, err
98-
case node == nil:
99-
return nil, fmt.Errorf("failed to find an expression")
10097
}
10198

10299
debug("found node: %s", debugFormatNode{node})
103100

104101
visitor := &callExprVisitor{}
105102
ast.Walk(visitor, node)
106103
if visitor.expr == nil {
107-
return nil, errors.New("failed to find call expression")
104+
return nil, errors.New("failed to find an expression")
108105
}
109106
debug("callExpr: %s", debugFormatNode{visitor.expr})
110107
return visitor.expr.Args, nil

internal/source/source_test.go

+11-11
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,13 @@ func shim(_, _, _ string) (string, error) {
4747

4848
func TestFormattedCallExprArg_InDefer(t *testing.T) {
4949
skip.If(t, isGoVersion18)
50-
cap := &capture{}
50+
c := &capture{}
5151
func() {
52-
defer cap.shim("first", "second")
52+
defer c.shim("first", "second")
5353
}()
5454

55-
assert.NilError(t, cap.err)
56-
assert.Equal(t, cap.value, `"second"`)
55+
assert.NilError(t, c.err)
56+
assert.Equal(t, c.value, `"second"`)
5757
}
5858

5959
func isGoVersion18() bool {
@@ -70,25 +70,25 @@ func (c *capture) shim(_, _ string) {
7070
}
7171

7272
func TestFormattedCallExprArg_InAnonymousDefer(t *testing.T) {
73-
cap := &capture{}
73+
c := &capture{}
7474
func() {
7575
fmt.Println()
7676
defer fmt.Println()
77-
defer func() { cap.shim("first", "second") }()
77+
defer func() { c.shim("first", "second") }()
7878
}()
7979

80-
assert.NilError(t, cap.err)
81-
assert.Equal(t, cap.value, `"second"`)
80+
assert.NilError(t, c.err)
81+
assert.Equal(t, c.value, `"second"`)
8282
}
8383

8484
func TestFormattedCallExprArg_InDeferMultipleDefers(t *testing.T) {
8585
skip.If(t, isGoVersion18)
86-
cap := &capture{}
86+
c := &capture{}
8787
func() {
8888
fmt.Println()
8989
defer fmt.Println()
90-
defer cap.shim("first", "second")
90+
defer c.shim("first", "second")
9191
}()
9292

93-
assert.ErrorContains(t, cap.err, "ambiguous call expression")
93+
assert.ErrorContains(t, c.err, "ambiguous call expression")
9494
}

poll/example_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func isDesiredState() bool { return false }
3535
func getState() string { return "" }
3636

3737
func ExampleSettingOp() {
38-
check := func(t poll.LogT) poll.Result {
38+
check := func(poll.LogT) poll.Result {
3939
if isDesiredState() {
4040
return poll.Success()
4141
}

poll/poll.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func Compare(compare cmp.Comparison) Result {
152152
if assert.RunComparison(buf, assert.ArgsAtZeroIndex, compare) {
153153
return Success()
154154
}
155-
return Continue(buf.String())
155+
return Continue("%v", buf.String())
156156
}
157157

158158
type logBuffer struct {

poll/poll_test.go

+7-7
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,9 @@ func (t *fakeT) Fatalf(format string, args ...interface{}) {
1818
panic("exit wait on")
1919
}
2020

21-
func (t *fakeT) Log(args ...interface{}) {}
21+
func (t *fakeT) Log(...interface{}) {}
2222

23-
func (t *fakeT) Logf(format string, args ...interface{}) {}
23+
func (t *fakeT) Logf(string, ...interface{}) {}
2424

2525
func TestContinueMessage(t *testing.T) {
2626
tests := []struct {
@@ -52,7 +52,7 @@ func TestContinueMessage(t *testing.T) {
5252
func TestWaitOn(t *testing.T) {
5353
counter := 0
5454
end := 4
55-
check := func(t LogT) Result {
55+
check := func(LogT) Result {
5656
if counter == end {
5757
return Success()
5858
}
@@ -67,7 +67,7 @@ func TestWaitOn(t *testing.T) {
6767
func TestWaitOnWithTimeout(t *testing.T) {
6868
fakeT := &fakeT{}
6969

70-
check := func(t LogT) Result {
70+
check := func(LogT) Result {
7171
return Continue("not done")
7272
}
7373

@@ -80,7 +80,7 @@ func TestWaitOnWithTimeout(t *testing.T) {
8080
func TestWaitOnWithCheckTimeout(t *testing.T) {
8181
fakeT := &fakeT{}
8282

83-
check := func(t LogT) Result {
83+
check := func(LogT) Result {
8484
time.Sleep(1 * time.Second)
8585
return Continue("not done")
8686
}
@@ -92,7 +92,7 @@ func TestWaitOnWithCheckTimeout(t *testing.T) {
9292
func TestWaitOnWithCheckError(t *testing.T) {
9393
fakeT := &fakeT{}
9494

95-
check := func(t LogT) Result {
95+
check := func(LogT) Result {
9696
return Error(fmt.Errorf("broke"))
9797
}
9898

@@ -103,7 +103,7 @@ func TestWaitOnWithCheckError(t *testing.T) {
103103
func TestWaitOn_WithCompare(t *testing.T) {
104104
fakeT := &fakeT{}
105105

106-
check := func(t LogT) Result {
106+
check := func(LogT) Result {
107107
return Compare(cmp.Equal(3, 4))
108108
}
109109

x/subtest/example_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ func ExampleRun_tableTest() {
4444
}
4545
}
4646

47-
func startFakeService(t subtest.TestContext) string {
47+
func startFakeService(_ subtest.TestContext) string {
4848
return "url"
4949
}
5050

0 commit comments

Comments
 (0)