From 40475286edb469a3de71f705ac0da0cf084cde57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Mart=C3=AD?= Date: Wed, 4 Mar 2026 17:35:42 +0000 Subject: [PATCH] all: remove some unused code spotted by staticcheck MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit And apply gopls suggestions I spot along the way. Signed-off-by: Daniel Martí Change-Id: Idf569e70dcd0a112ffeb5a1b871932e833fa59ef Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1232775 Unity-Result: CUE porcuepine TryBot-Result: CUEcueckoo Reviewed-by: Matthew Sackman --- cue/instance.go | 20 -------------- internal/anyunique/unique_test.go | 45 +++++++++++++++---------------- internal/ci/checks/commit.go | 1 - pkg/tool/http/serve.go | 12 +++------ 4 files changed, 26 insertions(+), 52 deletions(-) diff --git a/cue/instance.go b/cue/instance.go index 6614fbd7f..0119798fc 100644 --- a/cue/instance.go +++ b/cue/instance.go @@ -85,7 +85,6 @@ func lookupInstance(x *runtime.Runtime, p *build.Instance) *Instance { func getImportFromBuild(x *runtime.Runtime, p *build.Instance, v *adt.Vertex) *Instance { inst := lookupInstance(x, p) - if inst != nil { return inst } @@ -117,25 +116,6 @@ func getImportFromNode(x *runtime.Runtime, v *adt.Vertex) *Instance { return getImportFromBuild(x, p, v) } -func getImportFromPath(x *runtime.Runtime, id string) *Instance { - node := x.LoadBuiltin(id) - if node == nil { - return nil - } - b := x.GetInstanceFromNode(node) - inst := lookupInstance(x, b) - if inst == nil { - inst = &Instance{ - ImportPath: b.ImportPath, - PkgName: b.PkgName, - root: node, - inst: b, - index: x, - } - } - return inst -} - // newInstance creates a new instance. Use Insert to populate the instance. func newInstance(x *runtime.Runtime, p *build.Instance, v *adt.Vertex) *Instance { // TODO: associate root source with structLit. diff --git a/internal/anyunique/unique_test.go b/internal/anyunique/unique_test.go index d08a24ae5..7aae8f221 100644 --- a/internal/anyunique/unique_test.go +++ b/internal/anyunique/unique_test.go @@ -75,12 +75,12 @@ func (nodeHasher) Hash(h *maphash.Hash, n *node) { } func TestNew(t *testing.T) { - s := anyunique.New[string](stringHasher{}) + s := anyunique.New(stringHasher{}) qt.Assert(t, qt.Not(qt.IsNil(s))) } func TestStore_Make_BasicEquality(t *testing.T) { - s := anyunique.New[string](stringHasher{}) + s := anyunique.New(stringHasher{}) // First call creates a new unique value u1 := s.Make("hello") @@ -98,7 +98,7 @@ func TestStore_Make_BasicEquality(t *testing.T) { } func TestStore_Make_ZeroValue(t *testing.T) { - s := anyunique.New[string](stringHasher{}) + s := anyunique.New(stringHasher{}) // Zero value should be handled specially u1 := s.Make("") @@ -113,7 +113,7 @@ func TestStore_Make_ZeroValue(t *testing.T) { } func TestStore_Make_StructPointers(t *testing.T) { - s := anyunique.New[*node](nodeHasher{}) + s := anyunique.New(nodeHasher{}) node1 := &node{values: []int{1, 2, 3}} node2 := &node{values: []int{1, 2, 3}} // same content, different pointer @@ -139,7 +139,7 @@ func TestStore_Make_StructPointers(t *testing.T) { } func TestStore_Make_IntValues(t *testing.T) { - s := anyunique.New[int](simpleIntHasher{}) + s := anyunique.New(simpleIntHasher{}) u1 := s.Make(42) u2 := s.Make(42) @@ -152,7 +152,7 @@ func TestStore_Make_IntValues(t *testing.T) { } func TestStore_Make_MultipleValues(t *testing.T) { - s := anyunique.New[string](stringHasher{}) + s := anyunique.New(stringHasher{}) values := []string{"apple", "banana", "cherry", "date", "elderberry"} uniqueValues := make(map[anyunique.Handle[string]]bool) @@ -186,7 +186,7 @@ func (badHasher) Hash(*maphash.Hash, string) { } func TestStore_Make_HashCollisions(t *testing.T) { - s := anyunique.New[string](badHasher{}) + s := anyunique.New(badHasher{}) // All these will hash to the same bucket u1 := s.Make("key1") @@ -209,7 +209,7 @@ func TestStore_Make_HashCollisions(t *testing.T) { } func TestStore_WriteHash(t *testing.T) { - s := anyunique.New[string](stringHasher{}) + s := anyunique.New(stringHasher{}) u1 := s.Make("hello") u2 := s.Make("hello") @@ -235,7 +235,7 @@ func TestStore_WriteHash(t *testing.T) { } func TestStore_WriteHash_ZeroValue(t *testing.T) { - s := anyunique.New[string](stringHasher{}) + s := anyunique.New(stringHasher{}) u1 := s.Make("") u2 := s.Make("") @@ -253,7 +253,7 @@ func TestStore_WriteHash_ZeroValue(t *testing.T) { } func TestU_Get(t *testing.T) { - s := anyunique.New[string](stringHasher{}) + s := anyunique.New(stringHasher{}) u := s.Make("test") qt.Assert(t, qt.Equals(u.Value(), "test")) @@ -264,7 +264,7 @@ func TestU_Get(t *testing.T) { } func TestStore_Make_NilPointers(t *testing.T) { - s := anyunique.New[*node](nodeHasher{}) + s := anyunique.New(nodeHasher{}) u1 := s.Make(nil) u2 := s.Make(nil) @@ -280,7 +280,7 @@ func TestStore_Make_NilPointers(t *testing.T) { } func TestStore_Make_RepeatedCalls(t *testing.T) { - s := anyunique.New[string](stringHasher{}) + s := anyunique.New(stringHasher{}) // Make the same value many times var values []anyunique.Handle[string] @@ -296,8 +296,8 @@ func TestStore_Make_RepeatedCalls(t *testing.T) { } func TestStore_Make_DifferentStores(t *testing.T) { - s1 := anyunique.New[string](stringHasher{}) - s2 := anyunique.New[string](stringHasher{}) + s1 := anyunique.New(stringHasher{}) + s2 := anyunique.New(stringHasher{}) u1 := s1.Make("hello") u2 := s2.Make("hello") @@ -321,7 +321,7 @@ func TestStore_Make_DifferentStores(t *testing.T) { } func TestStore_WriteHash_ConsistentWithMake(t *testing.T) { - s := anyunique.New[string](stringHasher{}) + s := anyunique.New(stringHasher{}) // Create several unique values values := []string{"alpha", "beta", "gamma"} @@ -346,7 +346,7 @@ func TestStore_WriteHash_ConsistentWithMake(t *testing.T) { } func TestStore_Make_StressTest(t *testing.T) { - s := anyunique.New[int](simpleIntHasher{}) + s := anyunique.New(simpleIntHasher{}) // Create many unique values n := 10000 @@ -373,7 +373,6 @@ type treeNode struct { // treeHasher implements deep equality for tree nodes type treeHasher struct { - childStore *anyunique.Store[*treeNode, treeHasher] } func (h treeHasher) Equal(a, b *treeNode) bool { @@ -406,7 +405,7 @@ func (h treeHasher) Hash(hash *maphash.Hash, n *treeNode) { } func TestStore_Make_NestedStructures(t *testing.T) { - s := anyunique.New[*treeNode](treeHasher{}) + s := anyunique.New(treeHasher{}) // Create identical tree structures with different pointers tree1 := &treeNode{ @@ -446,7 +445,7 @@ func TestStore_Make_NestedStructures(t *testing.T) { } func TestStore_Make_ZeroValueInt(t *testing.T) { - s := anyunique.New[int](simpleIntHasher{}) + s := anyunique.New(simpleIntHasher{}) u1 := s.Make(0) u2 := s.Make(0) @@ -457,7 +456,7 @@ func TestStore_Make_ZeroValueInt(t *testing.T) { } func TestStore_WriteHash_DifferentSeeds(t *testing.T) { - s := anyunique.New[string](stringHasher{}) + s := anyunique.New(stringHasher{}) u := s.Make("test") @@ -474,7 +473,7 @@ func TestStore_WriteHash_DifferentSeeds(t *testing.T) { } func TestStore_Make_LargeStructPointers(t *testing.T) { - s := anyunique.New[*node](nodeHasher{}) + s := anyunique.New(nodeHasher{}) // Create nodes with large slices largeSlice := make([]int, 1000) @@ -494,7 +493,7 @@ func TestStore_Make_LargeStructPointers(t *testing.T) { } func TestStore_Make_AlternatingPatterns(t *testing.T) { - s := anyunique.New[string](stringHasher{}) + s := anyunique.New(stringHasher{}) // Alternate between two values many times for range 100 { @@ -508,7 +507,7 @@ func TestStore_Make_AlternatingPatterns(t *testing.T) { } func TestStore_WriteHash_MultipleValues(t *testing.T) { - s := anyunique.New[string](stringHasher{}) + s := anyunique.New(stringHasher{}) values := []string{"apple", "banana", "cherry", "date"} uniques := make([]anyunique.Handle[string], len(values)) diff --git a/internal/ci/checks/commit.go b/internal/ci/checks/commit.go index 7957bcc57..dfbb65420 100644 --- a/internal/ci/checks/commit.go +++ b/internal/ci/checks/commit.go @@ -92,7 +92,6 @@ func runCmd(dir string, exe string, args ...string) (string, error) { var ( rxExtractEmail = regexp.MustCompile(`.*<(.*)\>$`) - rxUserMention = regexp.MustCompile(`(^|\s)(@[a-z0-9][a-z0-9-]*)`) ) func extractEmails(list string) []string { diff --git a/pkg/tool/http/serve.go b/pkg/tool/http/serve.go index 1b3bea82c..1bbc7be76 100644 --- a/pkg/tool/http/serve.go +++ b/pkg/tool/http/serve.go @@ -40,10 +40,7 @@ func newServeCmd(v cue.Value) (task.Runner, error) { return &listenCmd{}, nil } -type listenCmd struct { - w http.ResponseWriter - body cue.Path -} +type listenCmd struct{} // IsService indicates that http.Serve acts as a service. // Other tasks can reference request fields (which are filled @@ -75,7 +72,7 @@ type httpRequest struct { PathValues map[string]string `json:"pathValues"` } -func (c *listenCmd) Run(ctx *task.Context) (res interface{}, err error) { +func (c *listenCmd) Run(ctx *task.Context) (res any, err error) { v := ctx.Obj addr, err := v.LookupPath(listenPath).String() @@ -199,8 +196,7 @@ func extractPathVariables(pattern string) []string { } type serveCmd struct { - w http.ResponseWriter - body cue.Path + w http.ResponseWriter } // IsService indicates that http.Serve should not be reported as part @@ -209,7 +205,7 @@ func (c *serveCmd) IsService() bool { return true } -func (c *serveCmd) Run(ctx *task.Context) (res interface{}, err error) { +func (c *serveCmd) Run(ctx *task.Context) (res any, err error) { v := ctx.Obj response := v.LookupPath(responsePath) -- 2.51.2