this repo has no description
0
fork

Configure Feed

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

cmd/cue: appease gopls in gen_experiments_help.go

These are all warnings with suggested fixes to modernize the code.

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

+16 -18
+16 -18
cmd/cue/cmd/gen_experiments_help.go
··· 102 102 func extractExperiments() ([]Experiment, error) { 103 103 // Extract file experiments from File struct 104 104 fileExperiments, err := extractExperimentsFromStruct( 105 - reflect.TypeOf(cueexperiment.File{}), 105 + reflect.TypeFor[cueexperiment.File](), 106 106 "../../../internal/cueexperiment/file.go", 107 107 "File", 108 108 false, // IsGlobal = false for per-file experiments ··· 113 113 114 114 // Extract global experiments from Config struct 115 115 globalExperiments, err := extractExperimentsFromStruct( 116 - reflect.TypeOf(cueexperiment.Config{}), 116 + reflect.TypeFor[cueexperiment.Config](), 117 117 "../../../internal/cueexperiment/exp.go", 118 118 "Config", 119 119 true, // IsGlobal = true for global experiments ··· 152 152 153 153 func parseExperimentTag(tagStr string) *experimentInfo { 154 154 info := &experimentInfo{} 155 - for _, part := range strings.Split(tagStr, ",") { 155 + for part := range strings.SplitSeq(tagStr, ",") { 156 156 part = strings.TrimSpace(part) 157 157 key, value, found := strings.Cut(part, ":") 158 158 if !found { ··· 326 326 327 327 // Generate per-file experiments 328 328 for _, exp := range fileExperiments { 329 - sb.WriteString(fmt.Sprintf(" %s (preview: %s", exp.Name, exp.Preview)) 329 + fmt.Fprintf(&sb, " %s (preview: %s", exp.Name, exp.Preview) 330 330 if exp.Default != "" { 331 - sb.WriteString(fmt.Sprintf(", default: %s", exp.Default)) 331 + fmt.Fprintf(&sb, ", default: %s", exp.Default) 332 332 } 333 333 if exp.Stable != "" { 334 - sb.WriteString(fmt.Sprintf(", stable: %s", exp.Stable)) 334 + fmt.Fprintf(&sb, ", stable: %s", exp.Stable) 335 335 } 336 336 if exp.Withdrawn != "" { 337 - sb.WriteString(fmt.Sprintf(", withdrawn: %s", exp.Withdrawn)) 337 + fmt.Fprintf(&sb, ", withdrawn: %s", exp.Withdrawn) 338 338 } 339 339 sb.WriteString(")\n") 340 340 341 341 // Add full comment if available 342 342 if exp.Comment != "" { 343 343 // Split into lines and indent each line 344 - lines := strings.Split(exp.Comment, "\n") 345 - for _, line := range lines { 344 + for line := range strings.SplitSeq(exp.Comment, "\n") { 346 345 line = strings.TrimSpace(line) 347 346 if line != "" { 348 347 // Replace field name with lowercase version in the first occurrence 349 348 line = strings.Replace(line, exp.FieldName, exp.Name, 1) 350 349 // Escape backticks to avoid syntax errors in Go string literals 351 350 line = strings.ReplaceAll(line, "`", "`+\"`\"+`") 352 - sb.WriteString(fmt.Sprintf(" %s\n", line)) 351 + fmt.Fprintf(&sb, " %s\n", line) 353 352 } 354 353 } 355 354 } ··· 374 373 `) 375 374 376 375 for _, exp := range globalExperiments { 377 - sb.WriteString(fmt.Sprintf(" %s", exp.Name)) 376 + fmt.Fprintf(&sb, " %s", exp.Name) 378 377 if exp.Preview != "" { 379 - sb.WriteString(fmt.Sprintf(" (preview: %s", exp.Preview)) 378 + fmt.Fprintf(&sb, " (preview: %s", exp.Preview) 380 379 if exp.Default != "" { 381 - sb.WriteString(fmt.Sprintf(", default: %s", exp.Default)) 380 + fmt.Fprintf(&sb, ", default: %s", exp.Default) 382 381 } 383 382 if exp.Stable != "" { 384 - sb.WriteString(fmt.Sprintf(", stable: %s", exp.Stable)) 383 + fmt.Fprintf(&sb, ", stable: %s", exp.Stable) 385 384 } 386 385 if exp.Withdrawn != "" { 387 - sb.WriteString(fmt.Sprintf(", withdrawn: %s", exp.Withdrawn)) 386 + fmt.Fprintf(&sb, ", withdrawn: %s", exp.Withdrawn) 388 387 } 389 388 sb.WriteString(")") 390 389 } else if exp.Withdrawn != "" { ··· 395 394 // Add full comment if available 396 395 if exp.Comment != "" { 397 396 // Split into lines and indent each line 398 - lines := strings.Split(exp.Comment, "\n") 399 - for _, line := range lines { 397 + for line := range strings.SplitSeq(exp.Comment, "\n") { 400 398 line = strings.TrimSpace(line) 401 399 if line != "" { 402 400 // Replace field name with lowercase version in the first occurrence 403 401 line = strings.Replace(line, exp.FieldName, exp.Name, 1) 404 402 // Escape backticks to avoid syntax errors in Go string literals 405 403 line = strings.ReplaceAll(line, "`", "`+\"`\"+`") 406 - sb.WriteString(fmt.Sprintf(" %s\n", line)) 404 + fmt.Fprintf(&sb, " %s\n", line) 407 405 } 408 406 } 409 407 }