this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

all: go fix -any=false ./...

Using Go at master as of this week.
This applies all modernizer fix except the rewrite of `interace{}`
with `any`, which is quite noisy, so that is left for a separate step.

Signed-off-by: Daniel Martí <mvdan@mvdan.cc>
Change-Id: Ib486b69063203d1774bb3b63fed1d7c716f5f436
Reviewed-on: https://cue.gerrithub.io/c/cue-lang/cue/+/1230267
TryBot-Result: CUEcueckoo <cueckoo@cuelang.org>
Unity-Result: CUE porcuepine <cue.porcuepine@gmail.com>
Reviewed-by: Matthew Sackman <matthew@cue.works>

+68 -91
+2 -2
cmd/cue/cmd/custom.go
··· 49 49 // splitLine splits the first line and the rest of the string. 50 50 func splitLine(s string) (line, tail string) { 51 51 line = s 52 - if p := strings.IndexByte(s, '\n'); p >= 0 { 53 - line, tail = strings.TrimSpace(s[:p]), strings.TrimSpace(s[p+1:]) 52 + if before, after, ok := strings.Cut(s, "\n"); ok { 53 + line, tail = strings.TrimSpace(before), strings.TrimSpace(after) 54 54 } 55 55 return 56 56 }
+2 -2
cue/format/printer.go
··· 401 401 } 402 402 403 403 func (p *printer) writeByte(ch byte, n int) { 404 - for i := 0; i < n; i++ { 404 + for range n { 405 405 p.output = append(p.output, ch) 406 406 } 407 407 ··· 412 412 p.pos.Column = 1 413 413 414 414 n := p.cfg.Indent + p.indent // include base indentation 415 - for i := 0; i < n; i++ { 415 + for range n { 416 416 p.output = append(p.output, '\t') 417 417 } 418 418
+1 -1
cue/literal/string.go
··· 405 405 err = errSyntax 406 406 return 407 407 } 408 - for j := 0; j < 2; j++ { // one digit already; two more 408 + for j := range 2 { // one digit already; two more 409 409 x := rune(s[j]) - '0' 410 410 if x < 0 || x > 7 { 411 411 err = errSyntax
+1 -1
cue/load/loader_test.go
··· 855 855 856 856 func race(t *testing.T, f func() error) { 857 857 var wg sync.WaitGroup 858 - for i := 0; i < 2; i++ { 858 + for range 2 { 859 859 wg.Add(1) 860 860 go func() { 861 861 if err := f(); err != nil {
+2 -2
cue/load/search.go
··· 147 147 // 148 148 // TODO this logic entirely ignores the pattern that's 149 149 // after the "...". See cuelang.org/issue/3212 150 - i := strings.Index(pattern, "...") 151 - dir, _ := path.Split(pattern[:i]) 150 + before, _, _ := strings.Cut(pattern, "...") 151 + dir, _ := path.Split(before) 152 152 153 153 root := l.abs(dir) 154 154
+1 -1
encoding/jsonschema/decode.go
··· 855 855 } 856 856 857 857 // do multiple passes over the constraints to ensure they are done in order. 858 - for pass := 0; pass < numPhases; pass++ { 858 + for pass := range numPhases { 859 859 s.processMap(n, func(key string, value cue.Value) { 860 860 if pass == 0 && key == "$ref" { 861 861 // Before 2019-19, keywords alongside $ref are ignored so keep
+4 -4
internal/anyunique/unique_test.go
··· 284 284 285 285 // Make the same value many times 286 286 var values []anyunique.Handle[string] 287 - for i := 0; i < 100; i++ { 287 + for range 100 { 288 288 values = append(values, s.Make("repeated")) 289 289 } 290 290 ··· 352 352 n := 10000 353 353 uniqueMap := make(map[int]anyunique.Handle[int]) 354 354 355 - for i := 0; i < n; i++ { 355 + for i := range n { 356 356 u := s.Make(i) 357 357 uniqueMap[i] = u 358 358 qt.Assert(t, qt.Equals(u.Value(), i)) 359 359 } 360 360 361 361 // Verify all values are stored correctly and re-making gives equal results 362 - for i := 0; i < n; i++ { 362 + for i := range n { 363 363 u := s.Make(i) 364 364 qt.Assert(t, qt.Equals(u, uniqueMap[i])) 365 365 } ··· 497 497 s := anyunique.New[string](stringHasher{}) 498 498 499 499 // Alternate between two values many times 500 - for i := 0; i < 100; i++ { 500 + for range 100 { 501 501 u1 := s.Make("a") 502 502 u2 := s.Make("b") 503 503 u3 := s.Make("a")
+19 -18
internal/astinternal/debug.go
··· 447 447 return out 448 448 449 449 case *ast.Field: 450 - out := DebugStr(v.Label) 450 + var out strings.Builder 451 + out.WriteString(DebugStr(v.Label)) 451 452 if v.Alias != nil { 452 - out += "~" 453 + out.WriteString("~") 453 454 if v.Alias.Label != nil { 454 455 // Dual form 455 - out += "(" 456 - out += DebugStr(v.Alias.Label) 457 - out += "," 458 - out += DebugStr(v.Alias.Field) 459 - out += ")" 456 + out.WriteString("(") 457 + out.WriteString(DebugStr(v.Alias.Label)) 458 + out.WriteString(",") 459 + out.WriteString(DebugStr(v.Alias.Field)) 460 + out.WriteString(")") 460 461 } else { 461 462 // Simple form 462 - out += DebugStr(v.Alias.Field) 463 + out.WriteString(DebugStr(v.Alias.Field)) 463 464 } 464 465 } 465 466 if t := v.Constraint; t != token.ILLEGAL { 466 - out += t.String() 467 + out.WriteString(t.String()) 467 468 } 468 469 if v.Value != nil { 469 - out += ": " 470 - out += DebugStr(v.Value) 470 + out.WriteString(": ") 471 + out.WriteString(DebugStr(v.Value)) 471 472 for _, a := range v.Attrs { 472 - out += " " 473 - out += DebugStr(a) 473 + out.WriteString(" ") 474 + out.WriteString(DebugStr(a)) 474 475 } 475 476 } 476 - return out 477 + return out.String() 477 478 478 479 case *ast.Attribute: 479 480 return v.Text ··· 578 579 if len(v) == 0 { 579 580 return "" 580 581 } 581 - out := "" 582 + var out strings.Builder 582 583 for _, c := range v { 583 - out += DebugStr(c) 584 - out += " " 584 + out.WriteString(DebugStr(c)) 585 + out.WriteString(" ") 585 586 } 586 - return out 587 + return out.String() 587 588 588 589 case []ast.Expr: 589 590 if len(v) == 0 {
+1 -1
internal/attrs.go
··· 273 273 274 274 func tokenMaskStr(m uint64) string { 275 275 var buf strings.Builder 276 - for t := token.Token(0); t < 64; t++ { 276 + for t := range token.Token(64) { 277 277 if (m & (1 << t)) != 0 { 278 278 if buf.Len() > 0 { 279 279 buf.WriteByte('|')
+1 -1
internal/core/adt/composite.go
··· 126 126 } 127 127 128 128 func (e *Environment) up(ctx *OpContext, count int32) *Environment { 129 - for i := int32(0); i < count; i++ { 129 + for range count { 130 130 e = e.Up 131 131 ctx.Assertf(ctx.Pos(), e.DerefVertex(ctx) != nil, "Environment.up encountered a nil vertex") 132 132 }
+1 -1
internal/core/adt/debug.go
··· 491 491 } 492 492 493 493 func indent(w io.Writer, level int) { 494 - for i := 0; i < level; i++ { 494 + for range level { 495 495 io.WriteString(w, " ") 496 496 } 497 497 }
+1 -1
internal/core/adt/disjunct2.go
··· 288 288 289 289 // Slow path for processing all disjunctions. Do not use `range` in case 290 290 // evaluation adds more disjunctions. 291 - for i := 0; i < len(a); i++ { 291 + for i := range a { 292 292 d := &a[i] 293 293 n.nextDisjunction(i, len(a), d.holeID) 294 294
+1 -1
internal/core/adt/eval_test.go
··· 261 261 b.StopTimer() 262 262 ctx := cuecontext.New() 263 263 v := ctx.CompileString("") 264 - for j := 0; j < 500; j++ { 264 + for j := range 500 { 265 265 if j == 400 { 266 266 b.StartTimer() 267 267 }
+1 -1
internal/core/export/toposort.go
··· 53 53 if len(sorted) > 0 { 54 54 occurrences := 1 + s.Repeats 55 55 // Add this front (1 + Repeats) times to give it proper weight 56 - for i := 0; i < occurrences; i++ { 56 + for range occurrences { 57 57 a = append(a, sorted) 58 58 } 59 59 }
-1
internal/golangorgx/gopls/lsprpc/autostart_posix.go
··· 3 3 // license that can be found in the LICENSE file. 4 4 5 5 //go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris 6 - // +build darwin dragonfly freebsd linux netbsd openbsd solaris 7 6 8 7 package lsprpc 9 8
+1 -1
internal/golangorgx/gopls/lsprpc/dialer.go
··· 97 97 const retries = 5 98 98 // It can take some time for the newly started server to bind to our address, 99 99 // so we retry for a bit. 100 - for retry := 0; retry < retries; retry++ { 100 + for retry := range retries { 101 101 startDial := time.Now() 102 102 netConn, err = net.DialTimeout(d.network, d.addr, dialTimeout) 103 103 if err == nil {
+1 -1
internal/golangorgx/gopls/protocol/semantic.go
··· 33 33 func SemMods(n int) []string { 34 34 tokMods := SemanticModifiers() 35 35 mods := []string{} 36 - for i := 0; i < len(tokMods); i++ { 36 + for i := range tokMods { 37 37 if (n & (1 << uint(i))) != 0 { 38 38 mods = append(mods, tokMods[i]) 39 39 }
+1 -1
internal/golangorgx/gopls/protocol/semtok/semtok.go
··· 65 65 x := make([]uint32, 5*len(tokens)) 66 66 var j int 67 67 var last Token 68 - for i := 0; i < len(tokens); i++ { 68 + for i := range tokens { 69 69 item := tokens[i] 70 70 typ, ok := typeMap[item.Type] 71 71 if !ok {
+4 -9
internal/golangorgx/gopls/settings/settings.go
··· 7 7 import ( 8 8 "context" 9 9 "fmt" 10 + "maps" 10 11 "path/filepath" 11 12 "regexp" 12 13 "runtime" ··· 709 710 // and UserOptions can be modified. 710 711 copyStringMap := func(src map[string]bool) map[string]bool { 711 712 dst := make(map[string]bool) 712 - for k, v := range src { 713 - dst[k] = v 714 - } 713 + maps.Copy(dst, src) 715 714 return dst 716 715 } 717 716 result.Analyses = copyStringMap(o.Analyses) ··· 729 728 730 729 copyAnalyzerMap := func(src map[string]*Analyzer) map[string]*Analyzer { 731 730 dst := make(map[string]*Analyzer) 732 - for k, v := range src { 733 - dst[k] = v 734 - } 731 + maps.Copy(dst, src) 735 732 return dst 736 733 } 737 734 result.DefaultAnalyzers = copyAnalyzerMap(o.DefaultAnalyzers) ··· 921 918 if o.Codelenses == nil { 922 919 o.Codelenses = make(map[string]bool) 923 920 } 924 - for lens, enabled := range lensOverrides { 925 - o.Codelenses[lens] = enabled 926 - } 921 + maps.Copy(o.Codelenses, lensOverrides) 927 922 } 928 923 929 924 case "staticcheck":
+4 -7
internal/golangorgx/gopls/test/integration/expectation.go
··· 6 6 7 7 import ( 8 8 "fmt" 9 + "maps" 9 10 "regexp" 10 - "sort" 11 + "slices" 11 12 "strings" 12 13 13 14 "cuelang.org/go/internal/golangorgx/gopls/protocol" ··· 200 201 func ReadAllDiagnostics(into *map[string]*protocol.PublishDiagnosticsParams) Expectation { 201 202 check := func(s State) Verdict { 202 203 allDiags := make(map[string]*protocol.PublishDiagnosticsParams) 203 - for name, diags := range s.diagnostics { 204 - allDiags[name] = diags 205 - } 204 + maps.Copy(allDiags, s.diagnostics) 206 205 *into = allDiags 207 206 return Met 208 207 } ··· 311 310 } 312 311 313 312 // Sort for stability. 314 - sort.Slice(expected, func(i, j int) bool { 315 - return expected[i] < expected[j] 316 - }) 313 + slices.Sort(expected) 317 314 318 315 var all []Expectation 319 316 for _, source := range expected {
+1 -3
internal/golangorgx/gopls/test/integration/fake/editor.go
··· 228 228 // makeSettings builds the settings map for use in LSP settings RPCs. 229 229 func makeSettings(sandbox *Sandbox, config EditorConfig, scopeURI *protocol.URI) map[string]any { 230 230 env := make(map[string]string) 231 - for k, v := range config.Env { 232 - env[k] = v 233 - } 231 + maps.Copy(env, config.Env) 234 232 for k, v := range env { 235 233 v = strings.ReplaceAll(v, "$SANDBOX_WORKDIR", sandbox.Workdir.RootURI().Path()) 236 234 env[k] = v
+4 -6
internal/golangorgx/gopls/test/integration/options.go
··· 5 5 package integration 6 6 7 7 import ( 8 + "maps" 9 + 8 10 "cuelang.org/go/internal/golangorgx/gopls/protocol" 9 11 "cuelang.org/go/internal/golangorgx/gopls/test/integration/fake" 10 12 "cuelang.org/go/internal/lsp/cache" ··· 92 94 if opts.editor.Settings == nil { 93 95 opts.editor.Settings = make(map[string]interface{}) 94 96 } 95 - for k, v := range s { 96 - opts.editor.Settings[k] = v 97 - } 97 + maps.Copy(opts.editor.Settings, s) 98 98 } 99 99 100 100 // WorkspaceFolders configures the workdir-relative workspace folders to send ··· 156 156 if opts.editor.Env == nil { 157 157 opts.editor.Env = make(map[string]string) 158 158 } 159 - for k, v := range e { 160 - opts.editor.Env[k] = v 161 - } 159 + maps.Copy(opts.editor.Env, e) 162 160 } 163 161 164 162 // MessageResponder configures the editor to respond to
+1 -4
internal/golangorgx/tools/diff/lcs/old.go
··· 376 376 if (df+db+e.delta)%2 != 0 { 377 377 return 0, false // diagonals cannot overlap 378 378 } 379 - kmin := -db + e.delta 380 - if -df > kmin { 381 - kmin = -df 382 - } 379 + kmin := max(-df, -db+e.delta) 383 380 kmax := db + e.delta 384 381 if df < kmax { 385 382 kmax = df
-8
internal/golangorgx/tools/diff/lcs/sequence.go
··· 103 103 } 104 104 return i 105 105 } 106 - 107 - func min(x, y int) int { 108 - if x < y { 109 - return x 110 - } else { 111 - return y 112 - } 113 - }
+1 -1
internal/golangorgx/tools/diff/ndiff.go
··· 72 72 func runes(bytes []byte) []rune { 73 73 n := utf8.RuneCount(bytes) 74 74 runes := make([]rune, n) 75 - for i := 0; i < n; i++ { 75 + for i := range n { 76 76 r, sz := utf8.DecodeRune(bytes) 77 77 bytes = bytes[sz:] 78 78 runes[i] = r
+2 -2
internal/golangorgx/tools/event/export/ocagent/metrics.go
··· 104 104 startTimestamp := convertTimestamp(start) 105 105 timeseries := make([]*wire.TimeSeries, 0, numRows) 106 106 107 - for i := 0; i < numRows; i++ { 107 + for i := range numRows { 108 108 timeseries = append(timeseries, &wire.TimeSeries{ 109 109 StartTimestamp: &startTimestamp, 110 110 // TODO: labels? ··· 175 175 // supplied counts, count, and sum. 176 176 func distributionToPoints(counts []int64, count int64, sum float64, bucketBounds []float64, end time.Time) []*wire.Point { 177 177 buckets := make([]*wire.Bucket, len(counts)) 178 - for i := 0; i < len(counts); i++ { 178 + for i := range counts { 179 179 buckets[i] = &wire.Bucket{ 180 180 Count: counts[i], 181 181 }
+4 -4
internal/mod/mvs/mvs_test.go
··· 481 481 if strings.HasPrefix(line, "#") || line == "" { 482 482 continue 483 483 } 484 - i := strings.Index(line, ":") 485 - if i < 0 { 484 + before, after, ok := strings.Cut(line, ":") 485 + if !ok { 486 486 t.Fatalf("missing colon: %q", line) 487 487 } 488 - key := strings.TrimSpace(line[:i]) 489 - val := strings.TrimSpace(line[i+1:]) 488 + key := strings.TrimSpace(before) 489 + val := strings.TrimSpace(after) 490 490 if key == "" { 491 491 t.Fatalf("missing key: %q", line) 492 492 }
+2 -2
mod/modconfig/modconfig_test.go
··· 194 194 for i := range registries { 195 195 reg := &registries[i] 196 196 reg.mod = fmt.Sprintf("foo.mod%02d", i) 197 - fsys, err := txtar.FS(txtar.Parse([]byte(fmt.Sprintf(` 197 + fsys, err := txtar.FS(txtar.Parse(fmt.Appendf(nil, ` 198 198 -- %s_v0.0.1/cue.mod/module.cue -- 199 199 module: "%s@v0" 200 200 language: version: "v0.8.0" 201 201 -- %s_v0.0.1/bar/bar.cue -- 202 202 package bar 203 - `, reg.mod, reg.mod, reg.mod)))) 203 + `, reg.mod, reg.mod, reg.mod))) 204 204 qt.Assert(t, qt.IsNil(err)) 205 205 mux := http.NewServeMux() 206 206 r := ocimem.New()
+3 -3
mod/modzip/zip_test.go
··· 58 58 if line == "" || line[0] == '#' { 59 59 continue 60 60 } 61 - eq := strings.IndexByte(line, '=') 62 - if eq < 0 { 61 + before, after, ok := strings.Cut(line, "=") 62 + if !ok { 63 63 return testParams{}, fmt.Errorf("%s:%d: missing = separator", file, n) 64 64 } 65 - key, value := strings.TrimSpace(line[:eq]), strings.TrimSpace(line[eq+1:]) 65 + key, value := strings.TrimSpace(before), strings.TrimSpace(after) 66 66 if strings.HasPrefix(value, "\"") { 67 67 unq, err := strconv.Unquote(value) 68 68 if err != nil {
+1 -1
pkg/path/path.go
··· 319 319 } 320 320 buf := make([]byte, size) 321 321 n := copy(buf, "..") 322 - for i := 0; i < seps; i++ { 322 + for range seps { 323 323 buf[n] = x.Separator 324 324 copy(buf[n+1:], "..") 325 325 n += 3