this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

all: resolve unused value and yoda conditionals staticcheck warnings

Values which are assigned to a variable but unused are either benign,
which cause the code to be confusing to the reader,
or actually lead to bugs, such as missed error checks in some tests.

Also, consistently place the constant on the right side in comparisons.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Icb5ef7c57fd26c6e2f82bf7309ebcbea1c5d0fbe
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1195056
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Roger Peppe <rogpeppe@gmail.com>

+17 -15
+4 -4
cue/build/import.go
··· 89 89 90 90 if inst.loadFunc != nil { 91 91 for i, path := range paths { 92 - isLocal := IsLocalImport(path) 93 - if isLocal { 94 - // path = dirToImportPath(filepath.Join(dir, path)) 95 - } 92 + // isLocal := IsLocalImport(path) 93 + // if isLocal { 94 + // path = dirToImportPath(filepath.Join(dir, path)) 95 + // } 96 96 97 97 imp := c.imports[path] 98 98 if imp == nil {
+1 -1
cue/format/simplify.go
··· 52 52 for _, d := range decls { 53 53 switch x := d.(type) { 54 54 case *ast.Field: 55 - x = astutil.Apply(x, sc.replace, nil).(*ast.Field) 55 + astutil.Apply(x, sc.replace, nil) 56 56 } 57 57 } 58 58 }
-1
cue/types.go
··· 2368 2368 2369 2369 case 1: 2370 2370 // the default case, processed below. 2371 - env = c.Env 2372 2371 env, expr = c.EnvExpr() 2373 2372 if w, ok := expr.(*adt.Vertex); ok { 2374 2373 return Value{v.idx, w, v.parent_}.Expr()
+1
internal/httplog/client_test.go
··· 32 32 resp, err := client.Get(srv.URL + "/foo/bar?foo=bar") 33 33 qt.Assert(t, qt.IsNil(err)) 34 34 data, err := io.ReadAll(resp.Body) 35 + qt.Assert(t, qt.IsNil(err)) 35 36 resp.Body.Close() 36 37 qt.Assert(t, qt.Equals(string(data), "hello")) 37 38
+2
internal/vcs/vcs_test.go
··· 76 76 qt.Assert(t, qt.IsTrue(!status.CommitTime.Before(commitTime))) 77 77 qt.Assert(t, qt.Matches(status.Revision, `[0-9a-f]+`)) 78 78 files, err := v.ListFiles(ctx, filepath.Join(dir, "subdir")) 79 + qt.Assert(t, qt.IsNil(err)) 79 80 qt.Assert(t, qt.DeepEquals(files, []string{ 80 81 "bar/baz", 81 82 "foo", 82 83 })) 83 84 files, err = v.ListFiles(ctx, dir) 85 + qt.Assert(t, qt.IsNil(err)) 84 86 qt.Assert(t, qt.DeepEquals(files, []string{ 85 87 "bar.txt", 86 88 "baz/something",
+9 -9
pkg/list/math.go
··· 24 24 25 25 // Avg returns the average value of a non empty list xs. 26 26 func Avg(xs []*internal.Decimal) (*internal.Decimal, error) { 27 - if 0 == len(xs) { 27 + if len(xs) == 0 { 28 28 return nil, fmt.Errorf("empty list") 29 29 } 30 30 ··· 47 47 48 48 // Max returns the maximum value of a non empty list xs. 49 49 func Max(xs []*internal.Decimal) (*internal.Decimal, error) { 50 - if 0 == len(xs) { 50 + if len(xs) == 0 { 51 51 return nil, fmt.Errorf("empty list") 52 52 } 53 53 54 54 max := xs[0] 55 55 for _, x := range xs[1:] { 56 - if -1 == max.Cmp(x) { 56 + if max.Cmp(x) == -1 { 57 57 max = x 58 58 } 59 59 } ··· 62 62 63 63 // Min returns the minimum value of a non empty list xs. 64 64 func Min(xs []*internal.Decimal) (*internal.Decimal, error) { 65 - if 0 == len(xs) { 65 + if len(xs) == 0 { 66 66 return nil, fmt.Errorf("empty list") 67 67 } 68 68 69 69 min := xs[0] 70 70 for _, x := range xs[1:] { 71 - if +1 == min.Cmp(x) { 71 + if min.Cmp(x) == +1 { 72 72 min = x 73 73 } 74 74 } ··· 102 102 return nil, fmt.Errorf("step must be non zero") 103 103 } 104 104 105 - if !step.Negative && +1 == start.Cmp(limit) { 105 + if !step.Negative && start.Cmp(limit) == +1 { 106 106 return nil, fmt.Errorf("end must be greater than start when step is positive") 107 107 } 108 108 109 - if step.Negative && -1 == start.Cmp(limit) { 109 + if step.Negative && start.Cmp(limit) == -1 { 110 110 return nil, fmt.Errorf("end must be less than start when step is negative") 111 111 } 112 112 113 113 var vals []*internal.Decimal 114 114 num := start 115 115 for { 116 - if !step.Negative && -1 != num.Cmp(limit) { 116 + if !step.Negative && num.Cmp(limit) != -1 { 117 117 break 118 118 } 119 119 120 - if step.Negative && +1 != num.Cmp(limit) { 120 + if step.Negative && num.Cmp(limit) != +1 { 121 121 break 122 122 } 123 123