Skip to content

Commit 6132343

Browse files
committed
all: remove some unused code and other minor cleanups
From bits in git stashes I have accumulated in the last few weeks. versionForModFile has been unused since https://cuelang.org/cl/1194044, matchPattern was deleted as unused in https://cuelang.org/cl/1177665, and replace the uses of deprecated APIs in encoding/json. Signed-off-by: Daniel Martí <[email protected]> Change-Id: I351cef6bf2bb8ab3910c5d30f7085be2d7ddeac6 Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194117 TryBot-Result: CUEcueckoo <[email protected]> Unity-Result: CUE porcuepine <[email protected]> Reviewed-by: Paul Jolly <[email protected]>
1 parent 59a0d3c commit 6132343

File tree

7 files changed

+10
-146
lines changed

7 files changed

+10
-146
lines changed

cmd/cue/cmd/custom.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ var testServerOnce = sync.OnceValue(func() string {
281281
s := httptest.NewServer(http.HandlerFunc(
282282
func(w http.ResponseWriter, req *http.Request) {
283283
data, _ := io.ReadAll(req.Body)
284-
d := map[string]interface{}{
284+
d := map[string]string{
285285
"data": string(data),
286286
"when": "now",
287287
}

cmd/cue/cmd/modinit.go

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,6 @@ import (
2121
"strings"
2222

2323
"github.com/spf13/cobra"
24-
gomodule "golang.org/x/mod/module"
25-
"golang.org/x/mod/semver"
2624

2725
"cuelang.org/go/internal/cueexperiment"
2826
"cuelang.org/go/internal/cueversion"
@@ -122,30 +120,3 @@ func runModInit(cmd *Command, args []string) (err error) {
122120

123121
return err
124122
}
125-
126-
func versionForModFile() string {
127-
version := cueversion.LanguageVersion()
128-
earliestPossibleVersion := modfile.EarliestClosedSchemaVersion()
129-
if semver.Compare(version, earliestPossibleVersion) < 0 {
130-
// The reported version is earlier than it should be,
131-
// which can occur for some pseudo versions, or
132-
// potentially the cue command has been forked and
133-
// published under an independent version numbering.
134-
//
135-
// In this case, we use the latest known schema version
136-
// as the best guess as to a version that actually
137-
// reflects the capabilities of the module file.
138-
version = modfile.LatestKnownSchemaVersion()
139-
}
140-
if gomodule.IsPseudoVersion(version) {
141-
// If we have a version like v0.7.1-0.20240130142347-7855e15cb701
142-
// we want it to turn into the base version (v0.7.0 in that example).
143-
// Subject the resulting base version to the same sanity check
144-
// as above.
145-
pv, _ := gomodule.PseudoVersionBase(version)
146-
if pv != "" && semver.Compare(pv, earliestPossibleVersion) >= 0 {
147-
version = pv
148-
}
149-
}
150-
return version
151-
}

cue/ast/astutil/resolve.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -385,12 +385,12 @@ func resolveIdent(s *scope, x *ast.Ident) bool {
385385
return false
386386
}
387387
if _, obj, node := s.lookup(name); node.node != nil {
388-
switch {
389-
case x.Node == nil:
388+
switch x.Node {
389+
case nil:
390390
x.Node = node.node
391391
x.Scope = obj
392392

393-
case x.Node == node.node:
393+
case node.node:
394394
x.Scope = obj
395395

396396
default: // x.Node != node

cue/format/format.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ func newFormatter(p *printer) *formatter {
202202
type whiteSpace int
203203

204204
const (
205-
ignore whiteSpace = 0
205+
_ whiteSpace = 0
206206

207207
// write a space, or disallow it
208208
blank whiteSpace = 1 << iota

cue/load/search.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
package load
1616

1717
import (
18-
// TODO: remove this usage
19-
2018
"io/fs"
2119
"path"
2220
"path/filepath"

cue/load/search_test.go

Lines changed: 0 additions & 103 deletions
This file was deleted.

encoding/json/json.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ import (
2828
"cuelang.org/go/cue/literal"
2929
"cuelang.org/go/cue/parser"
3030
"cuelang.org/go/cue/token"
31-
"cuelang.org/go/internal/value"
3231
)
3332

3433
// Valid reports whether data is a valid JSON encoding.
@@ -42,15 +41,14 @@ func Validate(b []byte, v cue.Value) error {
4241
if !json.Valid(b) {
4342
return fmt.Errorf("json: invalid JSON")
4443
}
45-
r := value.ConvertToRuntime(v.Context())
46-
inst, err := r.Compile("json.Validate", b)
47-
if err != nil {
44+
v2 := v.Context().CompileBytes(b, cue.Filename("json.Validate"))
45+
if err := v2.Err(); err != nil {
4846
return err
4947
}
5048

51-
v = v.Unify(inst.Value())
52-
if v.Err() != nil {
53-
return v.Err()
49+
v = v.Unify(v2)
50+
if err := v.Err(); err != nil {
51+
return err
5452
}
5553
return v.Validate(cue.Final())
5654
}

0 commit comments

Comments
 (0)