Skip to content

Commit

Permalink
Fix lint
Browse files Browse the repository at this point in the history
  • Loading branch information
dnephin committed Sep 17, 2024
1 parent 2f61a73 commit d50fd00
Show file tree
Hide file tree
Showing 14 changed files with 31 additions and 45 deletions.
10 changes: 2 additions & 8 deletions .project/golangci-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,39 +16,33 @@ issues:
text: 'ST1000: at least one file in a package should have a package comment'
- linters: [errcheck]
text: 'Error return value of `.*\.WriteString` is not checked'
- linters: [errcheck]
text: 'Error return value of `fmt.Fprint.*` is not checked'
- linters: [unparam]
text: 'result .* is always'
- linters: [unparam]
text: 'always receives'
# Remove once go1.16 is dropped
- linters: staticcheck
text: 'env.Patch is deprecated'

linters:
disable-all: true
enable:
- bodyclose
- deadcode
- depguard
- errcheck
- goconst
- gofmt
- goimports
- gosimple
- govet
- ineffassign
- interfacer
- lll
- misspell
- nakedret
- prealloc
- revive
- staticcheck
- structcheck
- stylecheck
- typecheck
- unconvert
- unparam
- unused
- varcheck
- whitespace
5 changes: 2 additions & 3 deletions cmd/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"gotest.tools/gotestsum/testjson"
"gotest.tools/v3/assert"
"gotest.tools/v3/assert/cmp"
"gotest.tools/v3/env"
"gotest.tools/v3/fs"
"gotest.tools/v3/golden"
)
Expand All @@ -32,8 +31,8 @@ func TestPostRunHook(t *testing.T) {
stdout: buf,
}

env.Patch(t, "GOTESTSUM_FORMAT", "short")
env.Patch(t, "GOTESTSUM_FORMAT_ICONS", "default")
t.Setenv("GOTESTSUM_FORMAT", "short")
t.Setenv("GOTESTSUM_FORMAT_ICONS", "default")

exec := newExecFromTestData(t)
err = postRunHook(opts, exec)
Expand Down
3 changes: 1 addition & 2 deletions cmd/internal/signalhandlerdriver/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package main

import (
"fmt"
"io/ioutil"
"os"
"os/signal"
"strconv"
Expand All @@ -17,7 +16,7 @@ func main() {
}

pid := []byte(strconv.Itoa(os.Getpid()))
if err := ioutil.WriteFile(os.Args[1], pid, 0644); err != nil {
if err := os.WriteFile(os.Args[1], pid, 0644); err != nil {
log("failed to write file:", err.Error())
os.Exit(1)
}
Expand Down
4 changes: 1 addition & 3 deletions cmd/main_e2e_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package cmd

import (
"bytes"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -174,8 +173,7 @@ func compileBinary(t *testing.T) string {
}

binaryFixture.Do(func() string {
tmpDir, err := ioutil.TempDir("", "gotestsum-binary")
assert.NilError(t, err)
tmpDir := t.TempDir()

path := filepath.Join(tmpDir, "gotestsum")
result := icmd.RunCommand("go", "build", "-o", path, "..")
Expand Down
10 changes: 5 additions & 5 deletions cmd/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ func TestRun_RerunFails_WithTooManyInitialFailures(t *testing.T) {
{"Package": "pkg", "Action": "fail"}
`

fn := func(args []string) *proc {
fn := func([]string) *proc {
return &proc{
cmd: fakeWaiter{result: newExitCode("failed", 1)},
stdout: strings.NewReader(jsonFailed),
Expand Down Expand Up @@ -375,7 +375,7 @@ func TestRun_RerunFails_BuildErrorPreventsRerun(t *testing.T) {
{"Package": "pkg", "Action": "fail"}
`

fn := func(args []string) *proc {
fn := func([]string) *proc {
return &proc{
cmd: fakeWaiter{result: newExitCode("failed", 1)},
stdout: strings.NewReader(jsonFailed),
Expand Down Expand Up @@ -411,7 +411,7 @@ func TestRun_RerunFails_PanicPreventsRerun(t *testing.T) {
{"Package": "pkg", "Action": "fail"}
`

fn := func(args []string) *proc {
fn := func([]string) *proc {
return &proc{
cmd: fakeWaiter{result: newExitCode("failed", 1)},
stdout: strings.NewReader(jsonFailed),
Expand Down Expand Up @@ -479,7 +479,7 @@ func TestRun_JsonFileIsSyncedBeforePostRunCommand(t *testing.T) {

input := golden.Get(t, "../../testjson/testdata/input/go-test-json.out")

fn := func(args []string) *proc {
fn := func([]string) *proc {
return &proc{
cmd: fakeWaiter{},
stdout: bytes.NewReader(input),
Expand Down Expand Up @@ -515,7 +515,7 @@ func TestRun_JsonFileIsSyncedBeforePostRunCommand(t *testing.T) {
func TestRun_JsonFileTimingEvents(t *testing.T) {
input := golden.Get(t, "../../testjson/testdata/input/go-test-json.out")

fn := func(args []string) *proc {
fn := func([]string) *proc {
return &proc{
cmd: fakeWaiter{},
stdout: bytes.NewReader(input),
Expand Down
12 changes: 6 additions & 6 deletions cmd/rerunfails_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"bytes"
"context"
"fmt"
"io/ioutil"
"os"
"strings"
"testing"

Expand All @@ -31,7 +31,7 @@ func TestWriteRerunFailsReport(t *testing.T) {
err = writeRerunFailsReport(opts, exec)
assert.NilError(t, err)

raw, err := ioutil.ReadFile(reportFile.Path())
raw, err := os.ReadFile(reportFile.Path())
assert.NilError(t, err)
golden.Assert(t, string(raw), t.Name()+"-expected")
}
Expand All @@ -53,7 +53,7 @@ func TestWriteRerunFailsReport_HandlesMissingActionRunEvents(t *testing.T) {
err = writeRerunFailsReport(opts, exec)
assert.NilError(t, err)

raw, err := ioutil.ReadFile(reportFile.Path())
raw, err := os.ReadFile(reportFile.Path())
assert.NilError(t, err)
golden.Assert(t, string(raw), t.Name()+"-expected")
}
Expand Down Expand Up @@ -117,7 +117,7 @@ func TestRerunFailed_ReturnsAnErrorWhenTheLastTestIsSuccessful(t *testing.T) {
},
}

fn := func(args []string) *proc {
fn := func([]string) *proc {
next := events[0]
events = events[1:]
return &proc{
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestRerunFailed_ReturnsAnErrorWhenTheLastTestIsSuccessful(t *testing.T) {

func patchStartGoTestFn(f func(args []string) *proc) func() {
orig := startGoTestFn
startGoTestFn = func(ctx context.Context, dir string, args []string) (*proc, error) {
startGoTestFn = func(_ context.Context, _ string, args []string) (*proc, error) {
return f(args), nil
}
return func() {
Expand Down Expand Up @@ -190,7 +190,7 @@ func (e exitCodeError) ExitCode() int {
}

func newExitCode(msg string, code int) error {
return exitCodeError{error: fmt.Errorf(msg), code: code}
return exitCodeError{error: fmt.Errorf("%v", msg), code: code}
}

type noopHandler struct{}
Expand Down
6 changes: 3 additions & 3 deletions cmd/testdata/e2e/flaky/flaky_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
//go:build testdata
// +build testdata

package flaky

import (
"fmt"
"io/ioutil"
"os"
"strconv"
"sync"
Expand All @@ -17,7 +17,7 @@ var once = new(sync.Once)

func setup(t *testing.T) {
once.Do(func() {
raw, err := ioutil.ReadFile(seedfile)
raw, err := os.ReadFile(seedfile)
if err != nil {
t.Fatalf("failed to read seed: %v", err)
}
Expand All @@ -27,7 +27,7 @@ func setup(t *testing.T) {
}
seed = int(n)

err = ioutil.WriteFile(seedfile, []byte(strconv.Itoa(seed+1)), 0644)
err = os.WriteFile(seedfile, []byte(strconv.Itoa(seed+1)), 0644)
if err != nil {
t.Fatalf("failed to write seed: %v", err)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/tool/slowest/slowest.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package slowest
import (
"fmt"
"io"
"io/ioutil"
"os"
"time"

Expand Down Expand Up @@ -139,7 +138,7 @@ func run(opts *options) error {
func jsonfileReader(v string) (io.ReadCloser, error) {
switch v {
case "", "-":
return ioutil.NopCloser(os.Stdin), nil
return io.NopCloser(os.Stdin), nil
default:
return os.Open(v)
}
Expand Down
3 changes: 1 addition & 2 deletions cmd/watch.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bufio"
"context"
"fmt"
"io/ioutil"
"os"
"os/exec"

Expand Down Expand Up @@ -97,7 +96,7 @@ func runSingle(opts *options, dir string) (*testjson.Execution, error) {
}

func delveInitFile(exec *testjson.Execution) (string, func(), error) {
fh, err := ioutil.TempFile("", "gotestsum-delve-init")
fh, err := os.CreateTemp("", "gotestsum-delve-init")
if err != nil {
return "", nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/filewatcher/watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ func TestFSEventHandler_HandleEvent(t *testing.T) {

fn := func(t *testing.T, tc testCase) {
var ran bool
run := func(opts Event) error {
run := func(Event) error {
ran = true
return nil
}
Expand Down
11 changes: 5 additions & 6 deletions internal/junitxml/report_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,21 @@ import (
"bytes"
"fmt"
"io"
"io/ioutil"
"os"
"runtime"
"testing"
"time"

"gotest.tools/gotestsum/testjson"
"gotest.tools/v3/assert"
"gotest.tools/v3/env"
"gotest.tools/v3/golden"
)

func TestWrite(t *testing.T) {
out := new(bytes.Buffer)
exec := createExecution(t)

env.Patch(t, "GOVERSION", "go7.7.7")
t.Setenv("GOVERSION", "go7.7.7")
err := Write(out, exec, Config{
ProjectName: "test",
customTimestamp: new(time.Time).Format(time.RFC3339),
Expand All @@ -33,7 +32,7 @@ func TestWrite_HideEmptyPackages(t *testing.T) {
out := new(bytes.Buffer)
exec := createExecution(t)

env.Patch(t, "GOVERSION", "go7.7.7")
t.Setenv("GOVERSION", "go7.7.7")
err := Write(out, exec, Config{
ProjectName: "test",
HideEmptyPackages: true,
Expand All @@ -54,14 +53,14 @@ func createExecution(t *testing.T) *testjson.Execution {
}

func readTestData(t *testing.T, stream string) io.Reader {
raw, err := ioutil.ReadFile("../../testjson/testdata/input/go-test-json." + stream)
raw, err := os.ReadFile("../../testjson/testdata/input/go-test-json." + stream)
assert.NilError(t, err)
return bytes.NewReader(raw)
}

func TestGoVersion(t *testing.T) {
t.Run("unknown", func(t *testing.T) {
env.Patch(t, "PATH", "/bogus")
t.Setenv("PATH", "/bogus")
assert.Equal(t, goVersion(), "unknown")
})

Expand Down
2 changes: 1 addition & 1 deletion testjson/dotformat.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func (d *dotFormatter) Format(event TestEvent, exec *Execution) error {
pkgname := RelativePackagePath(pkg) + " "
prefix := fmtDotElapsed(exec.Package(pkg))
line.checkWidth(len(prefix+pkgname), d.termWidth)
fmt.Fprintf(d.writer, prefix+pkgname+line.builder.String()+"\n")
fmt.Fprint(d.writer, prefix+pkgname+line.builder.String()+"\n")
}
PrintSummary(d.writer, exec, SummarizeNone)
return d.writer.Flush()
Expand Down
2 changes: 1 addition & 1 deletion testjson/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ func testDoxFormat(out io.Writer, opts FormatOptions) EventFormatter {

getIcon := getIconFunc(opts)
results := map[string][]Result{}
return eventFormatterFunc(func(event TestEvent, exec *Execution) error {
return eventFormatterFunc(func(event TestEvent, _ *Execution) error {
switch {
case event.PackageEvent():
if !event.Action.IsTerminal() {
Expand Down
3 changes: 1 addition & 2 deletions testjson/pkgpathprefix.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package testjson
import (
"bytes"
"go/build"
"io/ioutil"
"os"
"path/filepath"
"runtime"
Expand Down Expand Up @@ -63,7 +62,7 @@ func getPkgPathPrefixFromGoModule(cwd string) string {
if filename == "" {
return ""
}
raw, err := ioutil.ReadFile(filename)
raw, err := os.ReadFile(filename)
if err != nil {
// TODO: log.Warn
return ""
Expand Down

0 comments on commit d50fd00

Please sign in to comment.