Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix staticcheck issues and add staticcheck to ci (#263) #2

Merged
merged 1 commit into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ go.vet:
go.fmt:
@ test -z "$(shell go fmt $(GO_SOURCE))"

go.staticcheck:
@ go run honnef.co/go/tools/cmd/staticcheck $(GO_SOURCE)

go.install:
@ go build --trimpath \
--ldflags="-s -w \
Expand Down Expand Up @@ -169,8 +172,8 @@ budjs.test:
##

test: test.dev
test.dev: go.tools go.generate go.fmt go.vet budjs.check budjs.test go.test
test.all: go.tools go.generate go.vet budjs.check budjs.test go.test
test.dev: go.tools go.generate go.fmt go.vet go.staticcheck budjs.check budjs.test go.test
test.all: go.tools go.generate go.vet go.staticcheck budjs.check budjs.test go.test

##
# CI
Expand Down
3 changes: 1 addition & 2 deletions framework/controller/controllerrt/request/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package request
import (
"encoding/json"
"io"
"io/ioutil"
"mime"
"net/http"
"net/url"
Expand Down Expand Up @@ -60,7 +59,7 @@ func unmarshalForm(r *http.Request, v interface{}) error {
}

func unmarshalJSON(r io.Reader, v interface{}) error {
data, err := ioutil.ReadAll(r)
data, err := io.ReadAll(r)
if err != nil {
return err
}
Expand Down
1 change: 0 additions & 1 deletion framework/web/welcome/welcome.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package welcome

import (
"embed"
_ "embed"
"io/fs"
"net/http"

Expand Down
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,13 @@ require (
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c
golang.org/x/tools v0.1.11-0.20220513221640-090b14e8501f
honnef.co/go/tools v0.3.3
rogchap.com/v8go v0.7.0
src.techknowlogick.com/xgo v1.4.1-0.20220413212431-091a0a22b814
)

require (
github.com/BurntSushi/toml v0.4.1 // indirect
github.com/andybalholm/cascadia v1.3.1 // indirect
github.com/gedex/inflector v0.0.0-20170307190818-16278e9db813 // indirect
github.com/kr/pretty v0.3.0 // indirect
Expand All @@ -40,6 +42,7 @@ require (
github.com/pointlander/jetset v1.0.1-0.20190518214125-eee7eff80bd4 // indirect
github.com/rogpeppe/go-internal v1.8.1 // indirect
github.com/sergi/go-diff v1.2.0 // indirect
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e // indirect
golang.org/x/net v0.0.0-20211015210444-4f30a5c0130f // indirect
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b // indirect
Expand Down
6 changes: 6 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
github.com/BurntSushi/toml v0.4.1 h1:GaI7EiDXDRfa8VshkTj7Fym7ha+y8/XxIgD2okUIjLw=
github.com/BurntSushi/toml v0.4.1/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ=
github.com/OneOfOne/xxhash v1.2.2 h1:KMrpdQIwFcEqXDklaen+P1axHaj9BSKzvpUUfnHldSE=
github.com/OneOfOne/xxhash v1.2.2/go.mod h1:HSdplMjZKSmBqAxg5vPj2TmRDmfkzw+cTzAElWljhcU=
github.com/PuerkitoBio/goquery v1.8.0 h1:PJTF7AmFCFKk1N6V6jmKfrNH9tV5pNE6lZMkG0gta/U=
Expand Down Expand Up @@ -87,6 +89,8 @@ github.com/xlab/treeprint v1.1.0 h1:G/1DjNkPpfZCFt9CSh6b5/nY4VimlbHF3Rh4obvtzDk=
github.com/xlab/treeprint v1.1.0/go.mod h1:gj5Gd3gPdKtR1ikdDK6fnFLdmIS0X30kTTuNd/WEJu0=
go.kuoruan.net/v8go-polyfills v0.5.1-0.20220727011656-c74c5b408ebd h1:lMfOO39WTD+CxBPmqZvLdISrLVsEjgNfWoV4viBt15M=
go.kuoruan.net/v8go-polyfills v0.5.1-0.20220727011656-c74c5b408ebd/go.mod h1:egHzK8RIHR7dPOYzhnRsomClFTVmYCtvhTWqec4JXaY=
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e h1:qyrTQ++p1afMkO4DPEeLGq/3oTsdlvdH4vqZUBWzUKM=
golang.org/x/exp/typeparams v0.0.0-20220218215828-6cf2b201936e/go.mod h1:AbB0pIl9nAr9wVwH+Z2ZpaocVmF5I4GyWCDIsVjR0bk=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 h1:6zppjxzCulZykYSLyVDYbneBfbaBIQPYMevg0bEwv2s=
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
golang.org/x/net v0.0.0-20210916014120-12bc252f5db8/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=
Expand Down Expand Up @@ -115,6 +119,8 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C
gopkg.in/yaml.v3 v3.0.0-20200605160147-a5ece683394c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b h1:h8qDotaEPuJATrMmW04NCwg7v22aHH28wwpauUhK9Oo=
gopkg.in/yaml.v3 v3.0.0-20210107192922-496545a6307b/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
honnef.co/go/tools v0.3.3 h1:oDx7VAwstgpYpb3wv0oxiZlxY+foCpRAwY7Vk6XpAgA=
honnef.co/go/tools v0.3.3/go.mod h1:jzwdWgg7Jdq75wlfblQxO4neNaFFSvgc1tD5Wv8U0Yw=
rogchap.com/v8go v0.7.0 h1:kgjbiO4zE5itA962ze6Hqmbs4HgZbGzmueCXsZtremg=
rogchap.com/v8go v0.7.0/go.mod h1:MxgP3pL2MW4dpme/72QRs8sgNMmM0pRc8DPhcuLWPAs=
src.techknowlogick.com/xgo v1.4.1-0.20220413212431-091a0a22b814 h1:/oIyHjKnlyQ3yFzxq7uin83l6h0sHXT7Z+9TpP9wr8s=
Expand Down
4 changes: 2 additions & 2 deletions internal/cli/testcli/testcli.go
Original file line number Diff line number Diff line change
Expand Up @@ -249,9 +249,9 @@ func checkDate(res *http.Response) error {
return err
}
// Date should be within 1 minute. In reality, it should be almost instant
elapsed := time.Now().Sub(dt)
elapsed := time.Since(dt)
if elapsed > time.Minute {
return fmt.Errorf("Date header is too old %s", elapsed)
return fmt.Errorf("date header is too old %s", elapsed)
}
return nil
}
Expand Down
3 changes: 1 addition & 2 deletions internal/cli/toolv8/toolv8.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"errors"
"fmt"
"io"
"io/ioutil"

v8 "github.com/livebud/bud/package/js/v8"
)
Expand Down Expand Up @@ -37,7 +36,7 @@ func (c *Command) Run(ctx context.Context) error {
}

func (c *Command) getScript() (string, error) {
code, err := ioutil.ReadAll(c.Stdin)
code, err := io.ReadAll(c.Stdin)
if err != nil {
return "", err
}
Expand Down
1 change: 0 additions & 1 deletion internal/dsync/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import (

var (
// helpful to not write everywhere struct{}{}
keyExists = struct{}{}
nonExistent fs.DirEntry
)

Expand Down
5 changes: 2 additions & 3 deletions internal/golden/golden.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"bytes"
"encoding/json"
"flag"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -40,7 +39,7 @@ func Test(t testing.TB, actual *txtar.Archive) {
t.Helper()
filename := filepath.Join("testdata", t.Name()+".golden")
formatted := txtar.Format(actual)
expected, err := ioutil.ReadFile(filename)
expected, err := os.ReadFile(filename)
if err != nil {
if len(formatted) == 0 {
return
Expand All @@ -63,7 +62,7 @@ func writeFile(name string, data []byte) error {
if err := os.MkdirAll(filepath.Dir(name), 0755); err != nil {
return err
}
return ioutil.WriteFile(name, data, 0644)
return os.WriteFile(name, data, 0644)
}

// TestString diffs two strings
Expand Down
1 change: 1 addition & 0 deletions internal/is/is_internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ type I struct {

func (is *I) log(args ...interface{}) {
s := is.decorate(fmt.Sprint(args...))
//lint:ignore SA1006 - s can be a formatted string
fmt.Fprintf(is.writer, s)
is.fail()
}
Expand Down
10 changes: 6 additions & 4 deletions internal/is/is_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ func TestTrueOk(t *testing.T) {
out := new(bytes.Buffer)
is.writer = out
is.colorful = false
//lint:ignore SA4000 this is a test
is.True(1 == 1)
if m.failed {
t.Fatalf(`expected no failure`)
Expand All @@ -363,11 +364,12 @@ func TestTrueMessage(t *testing.T) {
out := new(bytes.Buffer)
is.writer = out
is.colorful = false
//lint:ignore SA4000 this is a test
is.True(1 != 1, "expected %d and %d to be equal", 1, 1)
if !m.failed {
t.Fatalf(`expected is.True to fail`)
}
expect := "is_test.go:366: not true: 1 != 1. expected 1 and 1 to be equal\n"
expect := "is_test.go:368: not true: 1 != 1. expected 1 and 1 to be equal\n"
if out.String() != expect {
t.Fatalf("expected %q, got %q", expect, out)
}
Expand All @@ -383,7 +385,7 @@ func TestInMessage(t *testing.T) {
if !m.failed {
t.Fatalf(`expected is.In to fail`)
}
expect := "is_test.go:382: hi not in hello. hello doesn't contain hi\n"
expect := "is_test.go:384: hi not in hello. hello doesn't contain hi\n"
if out.String() != expect {
t.Fatalf("expected %q, got %q", expect, out)
}
Expand All @@ -399,7 +401,7 @@ func TestFail(t *testing.T) {
if !m.failed {
t.Fatalf(`expected is.Fail to fail`)
}
expect := "is_test.go:398: failed\n"
expect := "is_test.go:400: failed\n"
if out.String() != expect {
t.Fatalf("expected %q, got %q", expect, out)
}
Expand All @@ -415,7 +417,7 @@ func TestFailMessage(t *testing.T) {
if !m.failed {
t.Fatalf(`expected is.Fail to fail`)
}
expect := "is_test.go:414: failed. context from \"component\" should have exited\n"
expect := "is_test.go:416: failed. context from \"component\" should have exited\n"
if out.String() != expect {
t.Fatalf("expected %q, got %q", expect, out)
}
Expand Down
9 changes: 0 additions & 9 deletions internal/snapshot/snapshot.go
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
package snapshot

import (
"encoding/base64"
"io/fs"
"os"
"path/filepath"

"github.com/livebud/bud/internal/dirhash"
"github.com/livebud/bud/internal/targz"

"github.com/cespare/xxhash"
)

func cachePath(key string) (string, error) {
Expand All @@ -20,12 +17,6 @@ func cachePath(key string) (string, error) {
return filepath.Join(dir, key+".tar.gz"), nil
}

func hash(input string) string {
hash := xxhash.New()
hash.Write([]byte(input))
return base64.RawURLEncoding.EncodeToString(hash.Sum(nil))
}

// Hash a filesystem
func Hash(fsys fs.FS) (string, error) {
return dirhash.Hash(fsys)
Expand Down
27 changes: 0 additions & 27 deletions internal/testdir/testdir.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,6 @@ type Dir struct {
NodeModules map[string]string // name[version]
}

func merge(mapfs fstest.MapFS, fsys fs.FS, base ...string) error {
basePath := path.Join(base...)
return fs.WalkDir(fsys, ".", func(filePath string, de fs.DirEntry, err error) error {
if err != nil {
return err
}
fi, err := de.Info()
if err != nil {
return err
}
fullPath := path.Join(basePath, filePath)
mapfs[fullPath] = &fstest.MapFile{
ModTime: fi.ModTime(),
Mode: fi.Mode(),
}
if de.IsDir() {
return nil
}
data, err := fs.ReadFile(fsys, filePath)
if err != nil {
return err
}
mapfs[fullPath].Data = data
return nil
})
}

func (d *Dir) mapfs() (fstest.MapFS, error) {
mapfs := fstest.MapFS{}
// Loop over files
Expand Down
9 changes: 4 additions & 5 deletions internal/testdir/testdir_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package testdir_test

import (
"context"
"io/ioutil"
"os"
"path/filepath"
"testing"
Expand Down Expand Up @@ -92,18 +91,18 @@ func TestOverwrite(t *testing.T) {
is.NoErr(td.Write(ctx))
is.NoErr(td.Exists("controller/controller.go"))
is.NoErr(td.Exists("view/index.svelte"))
controller1, err := ioutil.ReadFile(td.Path("controller/controller.go"))
controller1, err := os.ReadFile(td.Path("controller/controller.go"))
is.NoErr(err)
view1, err := ioutil.ReadFile(td.Path("view/index.svelte"))
view1, err := os.ReadFile(td.Path("view/index.svelte"))
is.NoErr(err)
is.Equal(string(view1), `<h1>hello</h1>`)
td.Files["view/index.svelte"] = `<h1>hi</h1>`
is.NoErr(td.Write(ctx))
is.NoErr(td.Exists("controller/controller.go"))
is.NoErr(td.Exists("view/index.svelte"))
controller2, err := ioutil.ReadFile(td.Path("controller/controller.go"))
controller2, err := os.ReadFile(td.Path("controller/controller.go"))
is.NoErr(err)
view2, err := ioutil.ReadFile(td.Path("view/index.svelte"))
view2, err := os.ReadFile(td.Path("view/index.svelte"))
is.NoErr(err)
is.Equal(string(controller1), string(controller2))
is.Equal(string(view2), `<h1>hi</h1>`)
Expand Down
4 changes: 2 additions & 2 deletions package/budfs/genfs/genfs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package genfs_test

import (
"errors"
"io"
"io/fs"
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
Expand Down Expand Up @@ -595,7 +595,7 @@ func TestHTTP(t *testing.T) {
handler(w, r)

response := w.Result()
body, err := ioutil.ReadAll(response.Body)
body, err := io.ReadAll(response.Body)
is.NoErr(err)
is.Equal(string(body), `bud/view/_index.svelte's data`)
is.Equal(response.StatusCode, 200)
Expand Down
1 change: 0 additions & 1 deletion package/budfs/treefs/treefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,6 @@ func (n *Node) print(tp treeprint.Tree) {
cp := tp.AddBranch(formatNode(child))
child.print(cp)
}
return
}

func (n *Node) Find(path string) (node *Node, found bool) {
Expand Down
4 changes: 2 additions & 2 deletions package/commander/subcommand.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import (
"errors"
"flag"
"fmt"
"io/ioutil"
"io"
)

func newSubcommand(config *config, name, usage string) *Subcommand {
fset := flag.NewFlagSet(name, flag.ContinueOnError)
fset.SetOutput(ioutil.Discard)
fset.SetOutput(io.Discard)
return &Subcommand{
config: config,
fset: fset,
Expand Down
3 changes: 1 addition & 2 deletions package/di/di_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package di_test
import (
"bytes"
"context"
"io/ioutil"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -81,7 +80,7 @@ func runTest(t testing.TB, test Test) {
err = os.MkdirAll(targetDir, 0755)
is.NoErr(err)
outPath := filepath.Join(targetDir, "di.go")
err = ioutil.WriteFile(outPath, []byte(code), 0644)
err = os.WriteFile(outPath, []byte(code), 0644)
is.NoErr(err)
stdout, err := goRun(ctx, modCache.Directory(), appDir)
is.NoErr(err)
Expand Down
2 changes: 1 addition & 1 deletion package/di/finder.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,5 @@ func (i *Injector) Find(currModule *gomod.Module, dep Dependency) (Declaration,
return decl, nil
}
// TODO: add breadcrumbs to help with finding the root of this error
return nil, fmt.Errorf("di: unclear how to provide %s.", dep.ID())
return nil, fmt.Errorf("di: unclear how to provide %s", dep.ID())
}
8 changes: 2 additions & 6 deletions package/gomod/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,7 @@ func (f *File) AddReplace(oldPath, oldVers, newPath, newVers string) error {
// Return a list of replaces
func (f *File) Replaces() (reps []*Replace) {
reps = make([]*Replace, len(f.file.Replace))
for i, rep := range f.file.Replace {
reps[i] = rep
}
copy(reps, f.file.Replace)
// Consistent ordering regardless of modfile formatting
sort.Slice(reps, func(i, j int) bool {
return reps[i].Old.Path < reps[j].Old.Path
Expand All @@ -55,9 +53,7 @@ func (f *File) Replaces() (reps []*Replace) {
// Return a list of requires
func (f *File) Requires() (reqs []*Require) {
reqs = make([]*Require, len(f.file.Require))
for i, req := range f.file.Require {
reqs[i] = req
}
copy(reqs, f.file.Require)
// Consistent ordering regardless of modfile formatting
sort.Slice(reqs, func(i, j int) bool {
switch {
Expand Down
Loading