Skip to content

Commit efb3fdc

Browse files
committed
refactor: apply go fix modernizations for Go 1.26
Run `go fix ./...` to apply automated code modernizations: - interface{} → any - Remove unnecessary loop variable copies (Go 1.22+ semantics) - String concatenation → strings.Builder - Manual loops → slices.Contains, maps.Copy - strings.Split → strings.SplitSeq where applicable - Remove redundant struct tags 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> https://claude.ai/code/session_01WLKDmB7kemgPsjsj9KFEXa
1 parent 03369a7 commit efb3fdc

File tree

37 files changed

+72
-82
lines changed

37 files changed

+72
-82
lines changed

internal/cmd/cmd.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ var initCmd = &cobra.Command{
100100
if err != nil {
101101
return err
102102
}
103-
var yamlConfig interface{}
103+
var yamlConfig any
104104
if useV1 {
105105
yamlConfig = config.V1GenerateSettings{Version: "1"}
106106
} else {

internal/cmd/createdb.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@ func CreateDB(ctx context.Context, dir, filename, querySetName string, o *Option
4747
var queryset *config.SQL
4848
var count int
4949
for _, sql := range conf.SQL {
50-
sql := sql
5150
if querySetName != "" && sql.Name != querySetName {
5251
continue
5352
}

internal/codegen/golang/field.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -97,23 +97,23 @@ func toPascalCase(s string) string {
9797
}
9898

9999
func toCamelInitCase(name string, initUpper bool) string {
100-
out := ""
100+
var out strings.Builder
101101
for i, p := range strings.Split(name, "_") {
102102
if !initUpper && i == 0 {
103-
out += p
103+
out.WriteString(p)
104104
continue
105105
}
106106
if p == "id" {
107-
out += "ID"
107+
out.WriteString("ID")
108108
} else {
109-
out += strings.Title(p)
109+
out.WriteString(strings.Title(p))
110110
}
111111
}
112-
return out
112+
return out.String()
113113
}
114114

115115
func toJsonCamelCase(name string, idUppercase bool) string {
116-
out := ""
116+
var out strings.Builder
117117
idStr := "Id"
118118

119119
if idUppercase {
@@ -122,16 +122,16 @@ func toJsonCamelCase(name string, idUppercase bool) string {
122122

123123
for i, p := range strings.Split(name, "_") {
124124
if i == 0 {
125-
out += p
125+
out.WriteString(p)
126126
continue
127127
}
128128
if p == "id" {
129-
out += idStr
129+
out.WriteString(idStr)
130130
} else {
131-
out += strings.Title(p)
131+
out.WriteString(strings.Title(p))
132132
}
133133
}
134-
return out
134+
return out.String()
135135
}
136136

137137
func toLowerCase(str string) string {

internal/codegen/golang/gen.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"errors"
88
"fmt"
99
"go/format"
10+
"slices"
1011
"strings"
1112
"text/template"
1213

@@ -344,10 +345,8 @@ func usesCopyFrom(queries []Query) bool {
344345

345346
func usesBatch(queries []Query) bool {
346347
for _, q := range queries {
347-
for _, cmd := range []string{metadata.CmdBatchExec, metadata.CmdBatchMany, metadata.CmdBatchOne} {
348-
if q.Cmd == cmd {
349-
return true
350-
}
348+
if slices.Contains([]string{metadata.CmdBatchExec, metadata.CmdBatchMany, metadata.CmdBatchOne}, q.Cmd) {
349+
return true
351350
}
352351
}
353352
return false

internal/codegen/golang/go_type.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package golang
22

33
import (
4+
"maps"
45
"strings"
56

67
"github.com/sqlc-dev/sqlc/internal/codegen/golang/opts"
@@ -15,9 +16,7 @@ func addExtraGoStructTags(tags map[string]string, req *plugin.GenerateRequest, o
1516
continue
1617
}
1718
if override.MatchesColumn(col) {
18-
for k, v := range oride.GoType.StructTags {
19-
tags[k] = v
20-
}
19+
maps.Copy(tags, oride.GoType.StructTags)
2120
continue
2221
}
2322
if !override.Matches(col.Table, req.Catalog.DefaultSchema) {
@@ -33,9 +32,7 @@ func addExtraGoStructTags(tags map[string]string, req *plugin.GenerateRequest, o
3332
continue
3433
}
3534
// Add the extra tags.
36-
for k, v := range oride.GoType.StructTags {
37-
tags[k] = v
38-
}
35+
maps.Copy(tags, oride.GoType.StructTags)
3936
}
4037
}
4138

internal/codegen/golang/opts/go_type.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ func (o *GoType) UnmarshalJSON(data []byte) error {
5151
return nil
5252
}
5353

54-
func (o *GoType) UnmarshalYAML(unmarshal func(interface{}) error) error {
54+
func (o *GoType) UnmarshalYAML(unmarshal func(any) error) error {
5555
var spec string
5656
if err := unmarshal(&spec); err == nil {
5757
*o = GoType{Spec: spec}

internal/codegen/golang/result.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,17 @@ func paramName(p *plugin.Parameter) string {
168168
}
169169

170170
func argName(name string) string {
171-
out := ""
171+
var out strings.Builder
172172
for i, p := range strings.Split(name, "_") {
173173
if i == 0 {
174-
out += strings.ToLower(p)
174+
out.WriteString(strings.ToLower(p))
175175
} else if p == "id" {
176-
out += "ID"
176+
out.WriteString("ID")
177177
} else {
178-
out += strings.Title(p)
178+
out.WriteString(strings.Title(p))
179179
}
180180
}
181-
return out
181+
return out.String()
182182
}
183183

184184
func buildQueries(req *plugin.GenerateRequest, options *opts.Options, structs []Struct) ([]Query, error) {

internal/codegen/golang/struct.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ func StructName(name string, options *opts.Options) string {
3131
return rune('_')
3232
}, name)
3333

34-
for _, p := range strings.Split(name, "_") {
34+
for p := range strings.SplitSeq(name, "_") {
3535
if _, found := options.InitialismsMap[p]; found {
3636
out += strings.ToUpper(p)
3737
} else {

internal/compiler/output_columns.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -517,7 +517,6 @@ func (c *Compiler) sourceTables(qc *QueryCatalog, node ast.Node) ([]*Table, erro
517517

518518
var tables []*Table
519519
for _, item := range list.Items {
520-
item := item
521520
switch n := item.(type) {
522521

523522
case *ast.RangeFunction:

internal/config/config.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ func (p *Paths) UnmarshalJSON(data []byte) error {
3636
return nil
3737
}
3838

39-
func (p *Paths) UnmarshalYAML(unmarshal func(interface{}) error) error {
39+
func (p *Paths) UnmarshalYAML(unmarshal func(any) error) error {
4040
out := []string{}
4141
if sliceErr := unmarshal(&out); sliceErr != nil {
4242
var ele string
@@ -61,7 +61,7 @@ type Config struct {
6161
Cloud Cloud `json:"cloud" yaml:"cloud"`
6262
Servers []Server `json:"servers" yaml:"servers"`
6363
SQL []SQL `json:"sql" yaml:"sql"`
64-
Overrides Overrides `json:"overrides,omitempty" yaml:"overrides"`
64+
Overrides Overrides `json:"overrides" yaml:"overrides"`
6565
Plugins []Plugin `json:"plugins" yaml:"plugins"`
6666
Rules []Rule `json:"rules" yaml:"rules"`
6767
Options map[string]yaml.Node `json:"options" yaml:"options"`
@@ -125,8 +125,8 @@ type SQL struct {
125125
// AnalyzerDatabase represents the database analyzer setting.
126126
// It can be a boolean (true/false) or the string "only" for database-only mode.
127127
type AnalyzerDatabase struct {
128-
value *bool // nil means not set, true/false for boolean values
129-
isOnly bool // true when set to "only"
128+
value *bool // nil means not set, true/false for boolean values
129+
isOnly bool // true when set to "only"
130130
}
131131

132132
// IsEnabled returns true if the database analyzer should be used.
@@ -166,7 +166,7 @@ func (a *AnalyzerDatabase) UnmarshalJSON(data []byte) error {
166166
return errors.New("analyzer.database must be true, false, or \"only\"")
167167
}
168168

169-
func (a *AnalyzerDatabase) UnmarshalYAML(unmarshal func(interface{}) error) error {
169+
func (a *AnalyzerDatabase) UnmarshalYAML(unmarshal func(any) error) error {
170170
// Try to unmarshal as boolean first
171171
var b bool
172172
if err := unmarshal(&b); err == nil {

0 commit comments

Comments
 (0)