Skip to content

Commit

Permalink
all: various very small cleanups from gopls and staticcheck
Browse files Browse the repository at this point in the history
I had been accumulating tiny tweaks and cleanups that were too small
to require a commit or review of their own.

* doTasks has had an unused parameter for a long time.
* publishRegistryResolverShim has an unused field.
* writeIndex did not actually check an error from os.WriteFile.
* extractFeatures can prepare the right slice capacities ahead of time.
* A few places can avoid the type parameter in generic func calls;
  note that type inference got much better with Go 1.21.
* zeroReader.Read can make use of the new clear builtin in Go 1.21

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: I4206073007191c28782acebe926c00ce3c3498db
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194842
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Noam Dolovich <noam.tzvi.dolovich@gmail.com>
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>
  • Loading branch information
mvdan committed May 16, 2024
1 parent fa64c62 commit 96f16f0
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 12 deletions.
4 changes: 2 additions & 2 deletions cmd/cue/cmd/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,15 +141,15 @@ func customCommand(c *Command, typ, name string, tools *cue.Instance) (*cobra.Co
// - parse flags and env vars
// - constrain current config with config section

return doTasks(cmd, typ, name, tools)
return doTasks(cmd, name, tools)
}),
}

// TODO: implement var/flag handling.
return sub, nil
}

func doTasks(cmd *Command, typ, command string, root *cue.Instance) error {
func doTasks(cmd *Command, command string, root *cue.Instance) error {
cfg := &flow.Config{
Root: cue.MakePath(cue.Str(commandSection), cue.Str(command)),
InferTasks: true,
Expand Down
5 changes: 2 additions & 3 deletions cmd/cue/cmd/modpublish.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ func runModUpload(cmd *Command, args []string) error {
if err != nil {
return err
}
if err := modzip.Create[string](zf, mv, files, osFileIO{
if err := modzip.Create(zf, mv, files, osFileIO{
modRoot: modRoot,
}); err != nil {
return err
Expand Down Expand Up @@ -253,7 +253,6 @@ func (fio osFileIO) absPath(f string) string {
// module's zip file.
type publishRegistryResolverShim struct {
resolver *modconfig.Resolver
registry ociregistry.Interface
dryRun bool
recordFiles bool
outDir string
Expand Down Expand Up @@ -320,7 +319,7 @@ func (r *publishRegistryResolverShim) writeIndex() error {
return err
}
data = append(data, '\n')
if os.WriteFile(filepath.Join(r.outDir, "index.json"), data, 0o666); err != nil {
if err := os.WriteFile(filepath.Join(r.outDir, "index.json"), data, 0o666); err != nil {
return err
}
return nil
Expand Down
5 changes: 3 additions & 2 deletions internal/core/export/toposort.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,10 @@ func VertexFeatures(c *adt.OpContext, v *adt.Vertex) []adt.Feature {
}

func extractFeatures(in []*adt.StructInfo) (a [][]adt.Feature) {
a = make([][]adt.Feature, 0, len(in))
for _, s := range in {
sorted := []adt.Feature{}
for _, e := range s.StructLit.Decls {
sorted := make([]adt.Feature, 0, len(s.Decls))
for _, e := range s.Decls {
switch x := e.(type) {
case *adt.Field:
sorted = append(sorted, x.Label)
Expand Down
4 changes: 2 additions & 2 deletions mod/modzip/zip.go
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ func CheckDir(dir string) (CheckedFiles, error) {
if err != nil {
return CheckedFiles{}, err
}
cf, cfErr := CheckFiles[dirFile](files, dirFileIO{})
cf, cfErr := CheckFiles(files, dirFileIO{})
_ = cfErr // ignore this error; we'll generate our own after rewriting paths.

// Replace all paths with file system paths.
Expand Down Expand Up @@ -595,7 +595,7 @@ func CreateFromDir(w io.Writer, m module.Version, dir string) (err error) {
return err
}

return Create[dirFile](w, m, files, dirFileIO{})
return Create(w, m, files, dirFileIO{})
}

type dirFile struct {
Expand Down
4 changes: 1 addition & 3 deletions mod/modzip/zip_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,7 @@ func (fi fakeFileInfo) Sys() interface{} { return nil }
type zeroReader struct{}

func (r zeroReader) Read(b []byte) (int, error) {
for i := range b {
b[i] = 0
}
clear(b)
return len(b), nil
}

Expand Down

0 comments on commit 96f16f0

Please sign in to comment.