Skip to content

Commit

Permalink
all: fix up staticcheck errors
Browse files Browse the repository at this point in the history
In a later step we add staticcheck to CI.

Signed-off-by: Paul Jolly <[email protected]>
Change-Id: I909d4a0bea7148be2306e0e9ea08f6890558c194
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cuelang.org/+/553457
TryBot-Result: CUEcueckoo <[email protected]>
Reviewed-by: Daniel Martí <[email protected]>
Reviewed-on: https://review.gerrithub.io/c/cue-lang/cuelang.org/+/1171221
TryBot-Result: CUEcueckoo <[email protected]>
  • Loading branch information
myitcv authored and mvdan committed Oct 25, 2023
1 parent 7fe5c2f commit c3669d8
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 14 deletions.
2 changes: 1 addition & 1 deletion internal/functions/snippets/snippets.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ func (fn Function) ServeHTTP(w http.ResponseWriter, r *http.Request) {
client := &http.Client{}
if r.Method == "POST" {
// Share
url := fmt.Sprintf("https://play.golang.org/share")
url := "https://play.golang.org/share"
req, err := http.NewRequest("POST", url, nil)
if err != nil {
w.WriteHeader(http.StatusInternalServerError)
Expand Down
4 changes: 2 additions & 2 deletions internal/genkubtutredirect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"

Expand All @@ -47,7 +47,7 @@ redirectURL: https://github.com/cue-lang/cue/blob/%v/doc/tutorial/kubernetes/REA
---`, url)

const target = "kubernetes.md"
if err := ioutil.WriteFile(target, []byte(content), 0666); err != nil {
if err := os.WriteFile(target, []byte(content), 0666); err != nil {
log.Fatalf("failed to write to %v; %v", target, err)
}
}
Expand Down
6 changes: 3 additions & 3 deletions internal/genspec/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"strings"
Expand All @@ -37,7 +37,7 @@ func main() {
log.Fatal(fmt.Errorf("failed to run %v: %w", strings.Join(cmd.Args, " "), err))
}
srcSpecPath := filepath.Join(strings.TrimSpace(cueDir.String()), "doc", "ref", "spec.md")
srcSpec, err := ioutil.ReadFile(srcSpecPath)
srcSpec, err := os.ReadFile(srcSpecPath)
if err != nil {
log.Fatal(fmt.Errorf("failed to read %v: %w", srcSpecPath, err))
}
Expand All @@ -49,7 +49,7 @@ layout = "spec"
+++`)
out.Write(srcSpec)
dstPath := "spec.md"
if err := ioutil.WriteFile(dstPath, out.Bytes(), 0666); err != nil {
if err := os.WriteFile(dstPath, out.Bytes(), 0666); err != nil {
log.Fatal(fmt.Errorf("failed to write to %v: %w", dstPath, err))
}
}
4 changes: 2 additions & 2 deletions internal/gentipredirect/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"

Expand All @@ -45,7 +45,7 @@ redirectURL: https://pkg.go.dev/cuelang.org/go@%v

const target = "pkg.go.dev.md"

if err := ioutil.WriteFile(target, []byte(content), 0666); err != nil {
if err := os.WriteFile(target, []byte(content), 0666); err != nil {
log.Fatalf("failed to write to %v; %v", target, err)
}
}
9 changes: 5 additions & 4 deletions play/impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"cuelang.org/go/cue"
"cuelang.org/go/cue/ast"
"cuelang.org/go/cue/cuecontext"
"cuelang.org/go/cue/errors"
"cuelang.org/go/cue/format"
"cuelang.org/go/cue/load"
Expand Down Expand Up @@ -80,9 +81,10 @@ func handleCUECompile(in input, fn function, out output, inputVal string) (strin
return "", fmt.Errorf("failed to load: %w", err)
}

insts := cue.Build(builds)
inst := insts[0]
if err := inst.Err; err != nil {
ctx := cuecontext.New()

v := ctx.BuildInstance(builds[0])
if err := v.Err(); err != nil {
return "", fmt.Errorf("failed to build: %w", err)
}
concrete := true
Expand All @@ -93,7 +95,6 @@ func handleCUECompile(in input, fn function, out output, inputVal string) (strin
default:
return "", fmt.Errorf("unknown ouput type: %v", out)
}
v := insts[0].Value()
if err := v.Validate(cue.Concrete(concrete)); err != nil {
return "", err
}
Expand Down
4 changes: 2 additions & 2 deletions play/internal/genversion/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ package main
import (
"bytes"
"fmt"
"io/ioutil"
"log"
"os"
"os/exec"
"strings"

Expand All @@ -39,7 +39,7 @@ func main() {
log.Fatal(fmt.Errorf("failed to run %v; %w", strings.Join(cmd.Args, " "), err))
}
out := fmt.Sprintf("export const CUEVersion = \"%v\";\n", strings.TrimSpace(cueDir.String()))
if err := ioutil.WriteFile("gen_cuelang_org_go_version.ts", []byte(out), 0666); err != nil {
if err := os.WriteFile("gen_cuelang_org_go_version.ts", []byte(out), 0666); err != nil {
log.Fatal(fmt.Errorf("failed to write generated version file: %v", err))
}
}

0 comments on commit c3669d8

Please sign in to comment.