cmd/cue: fix linter warnings
One remaining for which a fix is
undesirable.
Change-Id: I4adbdc0f38f755f42e4bd5cc2e0d6e705a7328c2
Reviewed-on: https://cue-review.googlesource.com/c/cue/+/2875
Reviewed-by: Marcel van Lohuizen <mpvl@golang.org>
diff --git a/cmd/cue/cmd/add.go b/cmd/cue/cmd/add.go
index 68f101b..559b911 100644
--- a/cmd/cue/cmd/add.go
+++ b/cmd/cue/cmd/add.go
@@ -153,7 +153,7 @@
stdout := cmd.OutOrStdout()
for _, fi := range todo {
fmt.Fprintln(stdout, "---", fi.filename)
- io.Copy(stdout, fi.contents)
+ _, _ = io.Copy(stdout, fi.contents)
}
return nil
}
@@ -291,7 +291,7 @@
if err = ioutil.WriteFile(fi.filename, b, 0644); err != nil {
// Just in case, attempt to restore original file.
- fo.restore()
+ _ = fo.restore()
return originalFile{}, err
}
diff --git a/cmd/cue/cmd/common.go b/cmd/cue/cmd/common.go
index 992164d..0a8e36a 100644
--- a/cmd/cue/cmd/common.go
+++ b/cmd/cue/cmd/common.go
@@ -19,6 +19,7 @@
"io"
"os"
"strings"
+ "testing"
"cuelang.org/go/cue"
"cuelang.org/go/cue/build"
@@ -33,6 +34,12 @@
var inTest = false
+func mustParseFlags(t *testing.T, cmd *cobra.Command, flags ...string) {
+ if err := cmd.ParseFlags(flags); err != nil {
+ t.Fatal(err)
+ }
+}
+
func exitIfErr(cmd *cobra.Command, inst *cue.Instance, err error, fatal bool) {
exitOnErr(cmd, err, fatal)
}
@@ -67,7 +74,7 @@
})
b := w.Bytes()
- cmd.OutOrStderr().Write(b)
+ _, _ = cmd.OutOrStderr().Write(b)
if fatal {
exit()
}
diff --git a/cmd/cue/cmd/common_test.go b/cmd/cue/cmd/common_test.go
index 3399c63..50513cf 100644
--- a/cmd/cue/cmd/common_test.go
+++ b/cmd/cue/cmd/common_test.go
@@ -57,7 +57,7 @@
cfg := printConfig(t)
- filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
+ _ = filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
t.Run(path, func(t *testing.T) {
if err != nil {
t.Fatal(err)
@@ -92,8 +92,7 @@
fmt.Fprintln(wOut, err)
}
}()
- cmd.Execute()
- return nil
+ return cmd.Execute()
})
g.Go(func() error {
bOut, err = ioutil.ReadAll(rOut)
@@ -105,7 +104,7 @@
t.Error(err)
}
if *update {
- ioutil.WriteFile(testfile, bOut, 0644)
+ _ = ioutil.WriteFile(testfile, bOut, 0644)
return
}
got, want := string(bOut), string(bWant)
diff --git a/cmd/cue/cmd/custom.go b/cmd/cue/cmd/custom.go
index 74aaa24..63eb3d8 100644
--- a/cmd/cue/cmd/custom.go
+++ b/cmd/cue/cmd/custom.go
@@ -190,6 +190,9 @@
m.Lock()
obj := tasks.Lookup(t.name)
m.Unlock()
+ // NOTE: ignore the linter warning for the following line:
+ // itask.Context is an internal type and we want to break if any
+ // fields are added.
update, err := t.Run(&itask.Context{ctx, stdout, stderr}, obj)
if err == nil && update != nil {
m.Lock()
@@ -311,7 +314,7 @@
"when": "now",
}
enc := json.NewEncoder(w)
- enc.Encode(d)
+ _ = enc.Encode(d)
}))
server = s.URL
})
diff --git a/cmd/cue/cmd/eval_test.go b/cmd/cue/cmd/eval_test.go
index ccb7fa7..1d7d20a 100644
--- a/cmd/cue/cmd/eval_test.go
+++ b/cmd/cue/cmd/eval_test.go
@@ -20,10 +20,10 @@
runCommand(t, newEvalCmd(), "eval")
cmd := newEvalCmd()
- cmd.ParseFlags([]string{"-c", "-a"})
+ mustParseFlags(t, cmd, "-c", "-a")
runCommand(t, cmd, "eval_conc")
cmd = newEvalCmd()
- cmd.ParseFlags([]string{"-c", "-e", "b.a.b", "-e", "b.idx"})
+ mustParseFlags(t, cmd, "-c", "-e", "b.a.b", "-e", "b.idx")
runCommand(t, cmd, "eval_expr")
}
diff --git a/cmd/cue/cmd/get_go.go b/cmd/cue/cmd/get_go.go
index 7a05f68..20ce3cf 100644
--- a/cmd/cue/cmd/get_go.go
+++ b/cmd/cue/cmd/get_go.go
@@ -465,7 +465,7 @@
fmt.Fprintln(w)
}
fmt.Fprintln(w)
- io.Copy(w, e.w)
+ _, _ = io.Copy(w, e.w)
file := filepath.Base(p.CompiledGoFiles[i])
@@ -473,7 +473,7 @@
file += "_gen.cue"
b, err := format.Source(w.Bytes())
if err != nil {
- ioutil.WriteFile(filepath.Join(dir, file), w.Bytes(), 0644)
+ _ = ioutil.WriteFile(filepath.Join(dir, file), w.Bytes(), 0644)
fmt.Println(w.String())
fmt.Println(dir, file)
return err
diff --git a/cmd/cue/cmd/get_go_test.go b/cmd/cue/cmd/get_go_test.go
index 1034819..577ab8a 100644
--- a/cmd/cue/cmd/get_go_test.go
+++ b/cmd/cue/cmd/get_go_test.go
@@ -49,7 +49,7 @@
// for the common ground to not have breaking text if people run these
// test in GOPATH mode.
root := ""
- filepath.Walk(tmp, func(path string, info os.FileInfo, err error) error {
+ _ = filepath.Walk(tmp, func(path string, info os.FileInfo, err error) error {
if root != "" {
return filepath.SkipDir
}
@@ -72,7 +72,7 @@
}
prefix := "testdata/pkg/cuelang.org/go/cmd/cue/cmd/testdata/code/go/"
- filepath.Walk(dst, func(path string, info os.FileInfo, err error) error {
+ _ = filepath.Walk(dst, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
}
diff --git a/cmd/cue/cmd/import.go b/cmd/cue/cmd/import.go
index ce53316..54849d6 100644
--- a/cmd/cue/cmd/import.go
+++ b/cmd/cue/cmd/import.go
@@ -42,9 +42,6 @@
"golang.org/x/sync/errgroup"
)
-// importCmd represents the import command
-var importCmd = newImportCmd()
-
func newImportCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "import",
@@ -531,7 +528,6 @@
type listIndex struct {
index map[string]*listIndex
- file *ast.File // top-level only
field *ast.Field
}
diff --git a/cmd/cue/cmd/import_test.go b/cmd/cue/cmd/import_test.go
index c0ce198..9d8d3cd 100644
--- a/cmd/cue/cmd/import_test.go
+++ b/cmd/cue/cmd/import_test.go
@@ -14,31 +14,29 @@
package cmd
-import "testing"
+import (
+ "testing"
+)
func TestImport(t *testing.T) {
cmd := newImportCmd()
- cmd.ParseFlags([]string{
- "-o", "-", "-f", "--files",
- })
+ mustParseFlags(t, cmd,
+ "-o", "-", "-f", "--files")
runCommand(t, cmd, "import_files")
cmd = newImportCmd()
- cmd.ParseFlags([]string{
- "-o", "-", "-f", "-l", `"\(strings.ToLower(kind))" "\(name)"`,
- })
+ mustParseFlags(t, cmd,
+ "-o", "-", "-f", "-l", `"\(strings.ToLower(kind))" "\(name)"`)
runCommand(t, cmd, "import_path")
cmd = newImportCmd()
- cmd.ParseFlags([]string{
- "-o", "-", "-f", "-l", `"\(strings.ToLower(kind))"`, "--list",
- })
+ mustParseFlags(t, cmd,
+ "-o", "-", "-f", "-l", `"\(strings.ToLower(kind))"`, "--list")
runCommand(t, cmd, "import_list")
cmd = newImportCmd()
- cmd.ParseFlags([]string{
+ mustParseFlags(t, cmd,
"-o", "-", "-f", "--list",
- "-l", `"\(strings.ToLower(kind))" "\(name)"`, "--recursive",
- })
+ "-l", `"\(strings.ToLower(kind))" "\(name)"`, "--recursive")
runCommand(t, cmd, "import_hoiststr")
}
diff --git a/cmd/cue/cmd/interfaces/text.go b/cmd/cue/cmd/interfaces/text.go
index 0aa0270..8d716fc 100644
--- a/cmd/cue/cmd/interfaces/text.go
+++ b/cmd/cue/cmd/interfaces/text.go
@@ -20,3 +20,9 @@
textMarshaler = encoding.TextMarshaler
textUnmarshaler = encoding.TextUnmarshaler
)
+
+// Suppress incorrect linter errors (types are used).
+var (
+ _ = textMarshaler(nil)
+ _ = textUnmarshaler(nil)
+)
diff --git a/cmd/cue/cmd/interfaces/top.go b/cmd/cue/cmd/interfaces/top.go
index 0d2d9a5..2c06872 100644
--- a/cmd/cue/cmd/interfaces/top.go
+++ b/cmd/cue/cmd/interfaces/top.go
@@ -27,3 +27,11 @@
UnmarshalYAML(func(interface{}) error) error
}
)
+
+// Suppress incorrect linter errors (types are used).
+var (
+ _ = jsonMarshaler(nil)
+ _ = jsonUnmarshaler(nil)
+ _ = yamlMarshal(nil)
+ _ = yamlUnmarshal(nil)
+)
diff --git a/cmd/cue/cmd/trim.go b/cmd/cue/cmd/trim.go
index cc79744..1ca999f 100644
--- a/cmd/cue/cmd/trim.go
+++ b/cmd/cue/cmd/trim.go
@@ -535,17 +535,6 @@
return false
}
-func deleteNode(a []ast.Node, n ast.Node) []ast.Node {
- k := 0
- for _, e := range a {
- if e != n {
- a[k] = e
- k++
- }
- }
- return a[:k]
-}
-
type key struct {
label string
hidden bool
diff --git a/cmd/cue/cmd/trim_test.go b/cmd/cue/cmd/trim_test.go
index 5c5d8d0..bc8001f 100644
--- a/cmd/cue/cmd/trim_test.go
+++ b/cmd/cue/cmd/trim_test.go
@@ -20,6 +20,6 @@
func TestTrim(t *testing.T) {
cmd := newTrimCmd()
- cmd.ParseFlags([]string{"-o", "-"})
+ mustParseFlags(t, cmd, "-o", "-")
runCommand(t, cmd, "trim")
}
diff --git a/cmd/cue/cmd/vet.go b/cmd/cue/cmd/vet.go
index a55a5aa..70e7452 100644
--- a/cmd/cue/cmd/vet.go
+++ b/cmd/cue/cmd/vet.go
@@ -72,7 +72,8 @@
if !shown && err == nil {
shown = true
p := message.NewPrinter(getLang())
- p.Fprintln(w, "some instances are incomplete; use the -c flag to show errors or suppress this message")
+ _, _ = p.Fprintln(w,
+ "some instances are incomplete; use the -c flag to show errors or suppress this message")
}
}
exitIfErr(cmd, inst, err, false)