Skip to content

Commit

Permalink
all: remove some unused code and other minor cleanups
Browse files Browse the repository at this point in the history
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í <mvdan@mvdan.cc>
Change-Id: I351cef6bf2bb8ab3910c5d30f7085be2d7ddeac6
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cue/+/1194117
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Paul Jolly <paul@myitcv.io>
  • Loading branch information
mvdan committed May 1, 2024
1 parent 59a0d3c commit 6132343
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 146 deletions.
2 changes: 1 addition & 1 deletion cmd/cue/cmd/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ var testServerOnce = sync.OnceValue(func() string {
s := httptest.NewServer(http.HandlerFunc(
func(w http.ResponseWriter, req *http.Request) {
data, _ := io.ReadAll(req.Body)
d := map[string]interface{}{
d := map[string]string{
"data": string(data),
"when": "now",
}
Expand Down
29 changes: 0 additions & 29 deletions cmd/cue/cmd/modinit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ import (
"strings"

"github.com/spf13/cobra"
gomodule "golang.org/x/mod/module"
"golang.org/x/mod/semver"

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

return err
}

func versionForModFile() string {
version := cueversion.LanguageVersion()
earliestPossibleVersion := modfile.EarliestClosedSchemaVersion()
if semver.Compare(version, earliestPossibleVersion) < 0 {
// The reported version is earlier than it should be,
// which can occur for some pseudo versions, or
// potentially the cue command has been forked and
// published under an independent version numbering.
//
// In this case, we use the latest known schema version
// as the best guess as to a version that actually
// reflects the capabilities of the module file.
version = modfile.LatestKnownSchemaVersion()
}
if gomodule.IsPseudoVersion(version) {
// If we have a version like v0.7.1-0.20240130142347-7855e15cb701
// we want it to turn into the base version (v0.7.0 in that example).
// Subject the resulting base version to the same sanity check
// as above.
pv, _ := gomodule.PseudoVersionBase(version)
if pv != "" && semver.Compare(pv, earliestPossibleVersion) >= 0 {
version = pv
}
}
return version
}
6 changes: 3 additions & 3 deletions cue/ast/astutil/resolve.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,12 +385,12 @@ func resolveIdent(s *scope, x *ast.Ident) bool {
return false
}
if _, obj, node := s.lookup(name); node.node != nil {
switch {
case x.Node == nil:
switch x.Node {
case nil:
x.Node = node.node
x.Scope = obj

case x.Node == node.node:
case node.node:
x.Scope = obj

default: // x.Node != node
Expand Down
2 changes: 1 addition & 1 deletion cue/format/format.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ func newFormatter(p *printer) *formatter {
type whiteSpace int

const (
ignore whiteSpace = 0
_ whiteSpace = 0

// write a space, or disallow it
blank whiteSpace = 1 << iota
Expand Down
2 changes: 0 additions & 2 deletions cue/load/search.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
package load

import (
// TODO: remove this usage

"io/fs"
"path"
"path/filepath"
Expand Down
103 changes: 0 additions & 103 deletions cue/load/search_test.go

This file was deleted.

12 changes: 5 additions & 7 deletions encoding/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import (
"cuelang.org/go/cue/literal"
"cuelang.org/go/cue/parser"
"cuelang.org/go/cue/token"
"cuelang.org/go/internal/value"
)

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

v = v.Unify(inst.Value())
if v.Err() != nil {
return v.Err()
v = v.Unify(v2)
if err := v.Err(); err != nil {
return err
}
return v.Validate(cue.Final())
}
Expand Down

0 comments on commit 6132343

Please sign in to comment.