From dc3ba30322ca1e1fdf3e12e6cc8a9c145397181d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 14 Aug 2024 10:51:43 +0100 Subject: [PATCH] all: minor code cleanups MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit While skimming the pkg/tool/cli code, I noticed that a switch can be replaced by a boolean expression. While here, apply three staticcheck suggestions around unused values. Signed-off-by: Daniel Martí Change-Id: I02b2d768b1fc9176a5f0d913b2de1e9f5ab549ae Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1199478 Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo Reviewed-by: Matthew Sackman --- internal/core/compile/builtin.go | 1 - internal/vcs/vcs_test.go | 1 + pkg/path/match.go | 2 +- pkg/tool/cli/cli.go | 7 +------ 4 files changed, 3 insertions(+), 8 deletions(-) diff --git a/internal/core/compile/builtin.go b/internal/core/compile/builtin.go index 4178b57a7..62c6acc04 100644 --- a/internal/core/compile/builtin.go +++ b/internal/core/compile/builtin.go @@ -24,7 +24,6 @@ import ( const supportedByLen = adt.StructKind | adt.BytesKind | adt.StringKind | adt.ListKind var ( - stringParam = adt.Param{Value: &adt.BasicType{K: adt.StringKind}} structParam = adt.Param{Value: &adt.BasicType{K: adt.StructKind}} listParam = adt.Param{Value: &adt.BasicType{K: adt.ListKind}} intParam = adt.Param{Value: &adt.BasicType{K: adt.IntKind}} diff --git a/internal/vcs/vcs_test.go b/internal/vcs/vcs_test.go index 459366be7..947e9a111 100644 --- a/internal/vcs/vcs_test.go +++ b/internal/vcs/vcs_test.go @@ -138,6 +138,7 @@ func TestGit(t *testing.T) { err = os.WriteFile(filepath.Join(dir, "bar.txt"), []byte("something else"), 0o666) qt.Assert(t, qt.IsNil(err)) statuschanged, err := v.Status(ctx) + qt.Assert(t, qt.IsNil(err)) qt.Assert(t, qt.IsTrue(statuschanged.Uncommitted)) status1, err := v.Status(ctx, subdir) qt.Assert(t, qt.IsNil(err)) diff --git a/pkg/path/match.go b/pkg/path/match.go index 4e191cb72..fe1a5d0a6 100644 --- a/pkg/path/match.go +++ b/pkg/path/match.go @@ -103,7 +103,7 @@ Pattern: // Before returning false with no error, // check that the remainder of the pattern is syntactically valid. for len(pattern) > 0 { - _, chunk, pattern, err = scanChunk(pattern, os) + _, _, pattern, err = scanChunk(pattern, os) if err != nil { return false, err } diff --git a/pkg/tool/cli/cli.go b/pkg/tool/cli/cli.go index 3efd7ab17..32f80bc96 100644 --- a/pkg/tool/cli/cli.go +++ b/pkg/tool/cli/cli.go @@ -94,12 +94,7 @@ func (c *askCmd) Run(ctx *task.Context) (res interface{}, err error) { switch v := ctx.Lookup("response"); v.IncompleteKind() { case cue.BoolKind: - switch strings.ToLower(response) { - case "yes": - update["response"] = true - default: - update["response"] = false - } + update["response"] = strings.ToLower(response) == "yes" case cue.StringKind: // already set above } -- 2.51.2