Skip to content

Commit

Permalink
Merge pull request #280 from thaJeztah/linting_errors
Browse files Browse the repository at this point in the history
Fix various linting issues and minor bugs
  • Loading branch information
dnephin authored Aug 29, 2024
2 parents 65a3150 + d21c522 commit 9aa7888
Show file tree
Hide file tree
Showing 12 changed files with 35 additions and 37 deletions.
1 change: 0 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ linters:
disable-all: true
enable:
- bodyclose
- depguard
- dogsled
- errcheck
- errorlint
Expand Down
8 changes: 5 additions & 3 deletions assert/assert_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,14 @@ func TestAssertWithBoolMultiLineFailure(t *testing.T) {
fakeT := &fakeTestingT{}

Assert(fakeT, func() bool {
for range []int{1, 2, 3, 4} {
for i := range []int{1, 2, 3, 4} {
_ = i
}
return false
}())
expectFailNowed(t, fakeT, `assertion failed: expression is false: func() bool {
for range []int{1, 2, 3, 4} {
for i := range []int{1, 2, 3, 4} {
_ = i
}
return false
}()`)
Expand Down Expand Up @@ -244,7 +246,7 @@ func TestCheckEqualFailure(t *testing.T) {
func TestCheck_MultipleFunctionsOnTheSameLine(t *testing.T) {
fakeT := &fakeTestingT{}

f := func(b bool) {}
f := func(bool) {}
f(Check(fakeT, false))
// TODO: update the expected when there is a more correct fix
expectFailed(t, fakeT,
Expand Down
2 changes: 1 addition & 1 deletion assert/cmp/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ type causer interface {
}

func formatErrorMessage(err error) string {
//nolint:errorlint // unwrapping is not appropriate here
//nolint:errorlint,nolintlint // unwrapping is not appropriate here
if _, ok := err.(causer); ok {
return fmt.Sprintf("%q\n%+v", err, err)
}
Expand Down
2 changes: 1 addition & 1 deletion assert/opt/opt_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,5 +261,5 @@ func TestPathDebug(t *testing.T) {
"label1": {},
},
}
gocmp.Equal(fixture, fixture, gocmp.FilterPath(PathDebug, gocmp.Ignore()))
assert.Check(t, gocmp.Equal(fixture, fixture, gocmp.FilterPath(PathDebug, gocmp.Ignore())))
}
4 changes: 2 additions & 2 deletions fs/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ func errProblem(reason string, err error) problem {
return problem(fmt.Sprintf("%s: %s", reason, err))
}

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

func eqResource(x, y resource) []problem {
Expand Down
4 changes: 2 additions & 2 deletions fs/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func TestMatchFileContent(t *testing.T) {
defer dir.Remove()

t.Run("content matches", func(t *testing.T) {
matcher := func(b []byte) CompareResult {
matcher := func([]byte) CompareResult {
return is.ResultSuccess
}
manifest := Expected(t,
Expand All @@ -193,7 +193,7 @@ func TestMatchFileContent(t *testing.T) {
})

t.Run("content does not match", func(t *testing.T) {
matcher := func(b []byte) CompareResult {
matcher := func([]byte) CompareResult {
return is.ResultFailure("data content differs from expected")
}
manifest := Expected(t,
Expand Down
9 changes: 3 additions & 6 deletions internal/source/source.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ func getNodeAtLine(fileset *token.FileSet, astFile ast.Node, lineNum int) (ast.N
return node, err
}
}
return nil, nil
return nil, errors.New("failed to find expression")
}

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

func getCallExprArgs(fileset *token.FileSet, astFile ast.Node, line int) ([]ast.Expr, error) {
node, err := getNodeAtLine(fileset, astFile, line)
switch {
case err != nil:
if err != nil {
return nil, err
case node == nil:
return nil, fmt.Errorf("failed to find an expression")
}

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

visitor := &callExprVisitor{}
ast.Walk(visitor, node)
if visitor.expr == nil {
return nil, errors.New("failed to find call expression")
return nil, errors.New("failed to find an expression")
}
debug("callExpr: %s", debugFormatNode{visitor.expr})
return visitor.expr.Args, nil
Expand Down
22 changes: 11 additions & 11 deletions internal/source/source_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ func shim(_, _, _ string) (string, error) {

func TestFormattedCallExprArg_InDefer(t *testing.T) {
skip.If(t, isGoVersion18)
cap := &capture{}
c := &capture{}
func() {
defer cap.shim("first", "second")
defer c.shim("first", "second")
}()

assert.NilError(t, cap.err)
assert.Equal(t, cap.value, `"second"`)
assert.NilError(t, c.err)
assert.Equal(t, c.value, `"second"`)
}

func isGoVersion18() bool {
Expand All @@ -70,25 +70,25 @@ func (c *capture) shim(_, _ string) {
}

func TestFormattedCallExprArg_InAnonymousDefer(t *testing.T) {
cap := &capture{}
c := &capture{}
func() {
fmt.Println()
defer fmt.Println()
defer func() { cap.shim("first", "second") }()
defer func() { c.shim("first", "second") }()
}()

assert.NilError(t, cap.err)
assert.Equal(t, cap.value, `"second"`)
assert.NilError(t, c.err)
assert.Equal(t, c.value, `"second"`)
}

func TestFormattedCallExprArg_InDeferMultipleDefers(t *testing.T) {
skip.If(t, isGoVersion18)
cap := &capture{}
c := &capture{}
func() {
fmt.Println()
defer fmt.Println()
defer cap.shim("first", "second")
defer c.shim("first", "second")
}()

assert.ErrorContains(t, cap.err, "ambiguous call expression")
assert.ErrorContains(t, c.err, "ambiguous call expression")
}
2 changes: 1 addition & 1 deletion poll/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func isDesiredState() bool { return false }
func getState() string { return "" }

func ExampleSettingOp() {
check := func(t poll.LogT) poll.Result {
check := func(poll.LogT) poll.Result {
if isDesiredState() {
return poll.Success()
}
Expand Down
2 changes: 1 addition & 1 deletion poll/poll.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ func Compare(compare cmp.Comparison) Result {
if assert.RunComparison(buf, assert.ArgsAtZeroIndex, compare) {
return Success()
}
return Continue(buf.String())
return Continue("%v", buf.String())
}

type logBuffer struct {
Expand Down
14 changes: 7 additions & 7 deletions poll/poll_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ func (t *fakeT) Fatalf(format string, args ...interface{}) {
panic("exit wait on")
}

func (t *fakeT) Log(args ...interface{}) {}
func (t *fakeT) Log(...interface{}) {}

func (t *fakeT) Logf(format string, args ...interface{}) {}
func (t *fakeT) Logf(string, ...interface{}) {}

func TestContinueMessage(t *testing.T) {
tests := []struct {
Expand Down Expand Up @@ -52,7 +52,7 @@ func TestContinueMessage(t *testing.T) {
func TestWaitOn(t *testing.T) {
counter := 0
end := 4
check := func(t LogT) Result {
check := func(LogT) Result {
if counter == end {
return Success()
}
Expand All @@ -67,7 +67,7 @@ func TestWaitOn(t *testing.T) {
func TestWaitOnWithTimeout(t *testing.T) {
fakeT := &fakeT{}

check := func(t LogT) Result {
check := func(LogT) Result {
return Continue("not done")
}

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

check := func(t LogT) Result {
check := func(LogT) Result {
time.Sleep(1 * time.Second)
return Continue("not done")
}
Expand All @@ -92,7 +92,7 @@ func TestWaitOnWithCheckTimeout(t *testing.T) {
func TestWaitOnWithCheckError(t *testing.T) {
fakeT := &fakeT{}

check := func(t LogT) Result {
check := func(LogT) Result {
return Error(fmt.Errorf("broke"))
}

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

check := func(t LogT) Result {
check := func(LogT) Result {
return Compare(cmp.Equal(3, 4))
}

Expand Down
2 changes: 1 addition & 1 deletion x/subtest/example_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func ExampleRun_tableTest() {
}
}

func startFakeService(t subtest.TestContext) string {
func startFakeService(_ subtest.TestContext) string {
return "url"
}

Expand Down

0 comments on commit 9aa7888

Please sign in to comment.