Skip to content

Commit acdabe5

Browse files
authored
chore: upgrade golangci-lint to 2.6.1, add modernize (#1190)
* chore: upgrade golangci-lint to 2.6.1 * style: apply golangci-lint 2.6.1 autofixes * refactor: add modernize, apply autofixes
1 parent 11306c9 commit acdabe5

File tree

26 files changed

+144
-154
lines changed

26 files changed

+144
-154
lines changed

.github/workflows/lint.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@ jobs:
1818
- name: golangci-lint
1919
uses: golangci/golangci-lint-action@v8
2020
with:
21-
version: v2.5.0
21+
version: v2.6.1

.golangci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ linters:
3535
- mirror
3636
- misspell
3737
- mnd
38+
- modernize
3839
- nestif
3940
- noctx
4041
- nolintlint

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ lint: bin/golangci-lint
3737
bin/golangci-lint run --fix
3838

3939
bin/golangci-lint:
40-
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b bin/ v2.5.0
40+
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b bin/ v2.6.1
4141

4242
.ONESHELL:
4343
version:

gen/jsonschema.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func main() {
1717
r := new(jsonschema.Reflector)
1818
r.ExpandedStruct = true
1919
r.AdditionalFields = func(t reflect.Type) []reflect.StructField {
20-
if t == reflect.TypeOf(config.Config{}) {
20+
if t == reflect.TypeFor[config.Config]() {
2121
return reflect.VisibleFields(reflect.TypeOf(struct {
2222
Schema string `json:"$schema,omitempty"`
2323
PreCommit *config.Hook `json:"pre-commit,omitempty"`

integration_test.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
//go:build integration
2-
// +build integration
32

43
package main_test
54

internal/config/command.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,8 @@ type Command struct {
1515
Root string `json:"root,omitempty" mapstructure:"root" toml:"root,omitempty" yaml:",omitempty"`
1616
FailText string `json:"fail_text,omitempty" koanf:"fail_text" mapstructure:"fail_text" toml:"fail_text,omitempty" yaml:"fail_text,omitempty"`
1717

18-
Skip interface{} `json:"skip,omitempty" jsonschema:"oneof_type=boolean;array" mapstructure:"skip" toml:"skip,omitempty,inline" yaml:",omitempty"`
19-
Only interface{} `json:"only,omitempty" jsonschema:"oneof_type=boolean;array" mapstructure:"only" toml:"only,omitempty,inline" yaml:",omitempty"`
18+
Skip any `json:"skip,omitempty" jsonschema:"oneof_type=boolean;array" mapstructure:"skip" toml:"skip,omitempty,inline" yaml:",omitempty"`
19+
Only any `json:"only,omitempty" jsonschema:"oneof_type=boolean;array" mapstructure:"only" toml:"only,omitempty,inline" yaml:",omitempty"`
2020

2121
Tags []string `json:"tags,omitempty" jsonschema:"oneof_type=string;array" mapstructure:"tags" toml:"tags,omitempty" yaml:",omitempty"`
2222
FileTypes []string `json:"file_types,omitempty" koanf:"file_types" mapstructure:"file_types" toml:"file_types,omitempty" yaml:"file_types,omitempty"`

internal/config/config.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@ type Config struct {
3636

3737
Rc string `json:"rc,omitempty" jsonschema:"description=Provide an rc file - a simple sh script" mapstructure:"rc,omitempty"`
3838

39-
Output interface{} `json:"output,omitempty" jsonschema:"oneof_type=boolean;array,description=Manage verbosity by skipping the printing of output of some steps" mapstructure:"output,omitempty"`
39+
Output any `json:"output,omitempty" jsonschema:"oneof_type=boolean;array,description=Manage verbosity by skipping the printing of output of some steps" mapstructure:"output,omitempty"`
4040

41-
Colors interface{} `json:"colors,omitempty" jsonschema:"description=Enable disable or set your own colors for lefthook output,default=true,oneof_type=boolean;object" mapstructure:"colors,omitempty"`
41+
Colors any `json:"colors,omitempty" jsonschema:"description=Enable disable or set your own colors for lefthook output,default=true,oneof_type=boolean;object" mapstructure:"colors,omitempty"`
4242

4343
Extends []string `json:"extends,omitempty" jsonschema:"description=Specify files to extend config with" mapstructure:"extends,omitempty"`
4444

@@ -76,7 +76,7 @@ func (c *Config) Md5() (checksum string, err error) {
7676
}
7777

7878
func (c *Config) Dump(format DumpFormat, out io.Writer) error {
79-
res := make(map[string]interface{})
79+
res := make(map[string]any)
8080
if err := mapstructure.Decode(c, &res); err != nil {
8181
return err
8282
}
@@ -110,12 +110,12 @@ func (c *Config) Dump(format DumpFormat, out io.Writer) error {
110110
}
111111

112112
type dumper interface {
113-
Dump(map[string]interface{}, io.Writer) error
113+
Dump(map[string]any, io.Writer) error
114114
}
115115

116116
type yamlDumper struct{}
117117

118-
func (yamlDumper) Dump(input map[string]interface{}, out io.Writer) error {
118+
func (yamlDumper) Dump(input map[string]any, out io.Writer) error {
119119
encoder := yaml.NewEncoder(out)
120120
encoder.SetIndent(yamlIndent)
121121

@@ -125,7 +125,7 @@ func (yamlDumper) Dump(input map[string]interface{}, out io.Writer) error {
125125

126126
type tomlDumper struct{}
127127

128-
func (tomlDumper) Dump(input map[string]interface{}, out io.Writer) error {
128+
func (tomlDumper) Dump(input map[string]any, out io.Writer) error {
129129
encoder := toml.NewEncoder(out)
130130
err := encoder.Encode(input)
131131
if err != nil {
@@ -139,7 +139,7 @@ type jsonDumper struct {
139139
pretty bool
140140
}
141141

142-
func (j jsonDumper) Dump(input map[string]interface{}, out io.Writer) error {
142+
func (j jsonDumper) Dump(input map[string]any, out io.Writer) error {
143143
var res []byte
144144
var err error
145145
if j.pretty {

internal/config/hook.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ package config
33
const CMD = "{cmd}"
44

55
type Hook struct {
6-
Name string `json:"-" jsonschema:"-" koanf:"-" mapstructure:"-" toml:"-" yaml:"-"`
7-
Parallel bool `json:"parallel,omitempty" mapstructure:"parallel" toml:"parallel,omitempty" yaml:",omitempty"`
8-
Piped bool `json:"piped,omitempty" mapstructure:"piped" toml:"piped,omitempty" yaml:",omitempty"`
9-
Follow bool `json:"follow,omitempty" mapstructure:"follow" toml:"follow,omitempty" yaml:",omitempty"`
10-
FailOnChanges string `json:"fail_on_changes,omitempty" jsonschema:"enum=true,enum=1,enum=0,enum=false,enum=never,enum=always,enum=ci,enum=non-ci" koanf:"fail_on_changes" mapstructure:"fail_on_changes" toml:"fail_on_changes,omitempty" yaml:"fail_on_changes,omitempty"`
11-
Files string `json:"files,omitempty" mapstructure:"files" toml:"files,omitempty" yaml:",omitempty"`
12-
ExcludeTags []string `json:"exclude_tags,omitempty" koanf:"exclude_tags" mapstructure:"exclude_tags" toml:"exclude_tags,omitempty" yaml:"exclude_tags,omitempty"`
13-
Exclude []string `json:"exclude,omitempty" koanf:"exclude" mapstructure:"exclude" toml:"exclude,omitempty" yaml:"exclude,omitempty"`
14-
Skip interface{} `json:"skip,omitempty" jsonschema:"oneof_type=boolean;array" mapstructure:"skip" toml:"skip,omitempty,inline" yaml:",omitempty"`
15-
Only interface{} `json:"only,omitempty" jsonschema:"oneof_type=boolean;array" mapstructure:"only" toml:"only,omitempty,inline" yaml:",omitempty"`
6+
Name string `json:"-" jsonschema:"-" koanf:"-" mapstructure:"-" toml:"-" yaml:"-"`
7+
Parallel bool `json:"parallel,omitempty" mapstructure:"parallel" toml:"parallel,omitempty" yaml:",omitempty"`
8+
Piped bool `json:"piped,omitempty" mapstructure:"piped" toml:"piped,omitempty" yaml:",omitempty"`
9+
Follow bool `json:"follow,omitempty" mapstructure:"follow" toml:"follow,omitempty" yaml:",omitempty"`
10+
FailOnChanges string `json:"fail_on_changes,omitempty" jsonschema:"enum=true,enum=1,enum=0,enum=false,enum=never,enum=always,enum=ci,enum=non-ci" koanf:"fail_on_changes" mapstructure:"fail_on_changes" toml:"fail_on_changes,omitempty" yaml:"fail_on_changes,omitempty"`
11+
Files string `json:"files,omitempty" mapstructure:"files" toml:"files,omitempty" yaml:",omitempty"`
12+
ExcludeTags []string `json:"exclude_tags,omitempty" koanf:"exclude_tags" mapstructure:"exclude_tags" toml:"exclude_tags,omitempty" yaml:"exclude_tags,omitempty"`
13+
Exclude []string `json:"exclude,omitempty" koanf:"exclude" mapstructure:"exclude" toml:"exclude,omitempty" yaml:"exclude,omitempty"`
14+
Skip any `json:"skip,omitempty" jsonschema:"oneof_type=boolean;array" mapstructure:"skip" toml:"skip,omitempty,inline" yaml:",omitempty"`
15+
Only any `json:"only,omitempty" jsonschema:"oneof_type=boolean;array" mapstructure:"only" toml:"only,omitempty,inline" yaml:",omitempty"`
1616

1717
Jobs []*Job `json:"jobs,omitempty" mapstructure:"jobs" toml:"jobs,omitempty" yaml:",omitempty"`
1818

internal/config/job.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ type Job struct {
2020
UseStdin bool `json:"use_stdin,omitempty" koanf:"use_stdin" mapstructure:"use_stdin" toml:"use_stdin,omitempty" yaml:"use_stdin,omitempty"`
2121
StageFixed bool `json:"stage_fixed,omitempty" koanf:"stage_fixed" mapstructure:"stage_fixed" toml:"stage_fixed,omitempty" yaml:"stage_fixed,omitempty"`
2222

23-
Skip interface{} `json:"skip,omitempty" jsonschema:"oneof_type=boolean;array" mapstructure:"skip" toml:"skip,omitempty,inline" yaml:",omitempty"`
24-
Only interface{} `json:"only,omitempty" jsonschema:"oneof_type=boolean;array" mapstructure:"only" toml:"only,omitempty,inline" yaml:",omitempty"`
23+
Skip any `json:"skip,omitempty" jsonschema:"oneof_type=boolean;array" mapstructure:"skip" toml:"skip,omitempty,inline" yaml:",omitempty"`
24+
Only any `json:"only,omitempty" jsonschema:"oneof_type=boolean;array" mapstructure:"only" toml:"only,omitempty,inline" yaml:",omitempty"`
2525

2626
Group *Group `json:"group,omitempty" jsonschema:"oneof_required=Run a group" mapstructure:"group" toml:"group,omitempty" yaml:",omitempty"`
2727
}

internal/config/load.go

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -334,15 +334,15 @@ func addHook(name string, main, secondary *koanf.Koanf, c *Config) error {
334334
overrideHook := secondary.Cut(name)
335335

336336
// Special merge func to support merging {cmd} templates
337-
options := koanf.WithMergeFunc(func(src, dest map[string]interface{}) error {
337+
options := koanf.WithMergeFunc(func(src, dest map[string]any) error {
338338
var destCommands map[string]string
339339

340340
switch commands := dest["commands"].(type) {
341-
case map[string]interface{}:
341+
case map[string]any:
342342
destCommands = make(map[string]string, len(commands))
343343
for cmdName, command := range commands {
344344
switch cmd := command.(type) {
345-
case map[string]interface{}:
345+
case map[string]any:
346346
switch run := cmd["run"].(type) {
347347
case string:
348348
destCommands[cmdName] = run
@@ -354,14 +354,14 @@ func addHook(name string, main, secondary *koanf.Koanf, c *Config) error {
354354
default:
355355
}
356356

357-
var destJobs, srcJobs []interface{}
357+
var destJobs, srcJobs []any
358358
switch jobs := dest["jobs"].(type) {
359-
case []interface{}:
359+
case []any:
360360
destJobs = jobs
361361
default:
362362
}
363363
switch jobs := src["jobs"].(type) {
364-
case []interface{}:
364+
case []any:
365365
srcJobs = jobs
366366
default:
367367
}
@@ -372,14 +372,14 @@ func addHook(name string, main, secondary *koanf.Koanf, c *Config) error {
372372

373373
if len(destCommands) > 0 {
374374
switch commands := dest["commands"].(type) {
375-
case map[string]interface{}:
375+
case map[string]any:
376376
for cmdName, command := range commands {
377377
switch cmd := command.(type) {
378-
case map[string]interface{}:
378+
case map[string]any:
379379
switch run := cmd["run"].(type) {
380380
case string:
381381
newRun := strings.ReplaceAll(run, CMD, destCommands[cmdName])
382-
command.(map[string]interface{})["run"] = newRun
382+
command.(map[string]any)["run"] = newRun
383383
default:
384384
}
385385
default:
@@ -437,35 +437,35 @@ type koanfProvider struct {
437437
k *koanf.Koanf
438438
}
439439

440-
func (k koanfProvider) Read() (map[string]interface{}, error) {
440+
func (k koanfProvider) Read() (map[string]any, error) {
441441
return k.k.Raw(), nil
442442
}
443443

444444
func (k koanfProvider) ReadBytes() ([]byte, error) {
445445
panic("not implemented")
446446
}
447447

448-
func mergeJobs(src, dest map[string]interface{}) error {
449-
srcJobs := make(map[string][]interface{})
448+
func mergeJobs(src, dest map[string]any) error {
449+
srcJobs := make(map[string][]any)
450450

451451
for name, maybeHook := range src {
452452
switch hook := maybeHook.(type) {
453-
case map[string]interface{}:
453+
case map[string]any:
454454
switch jobs := hook["jobs"].(type) {
455-
case []interface{}:
455+
case []any:
456456
srcJobs[name] = jobs
457457
default:
458458
}
459459
default:
460460
}
461461
}
462462

463-
destJobs := make(map[string][]interface{})
463+
destJobs := make(map[string][]any)
464464
for name, maybeHook := range dest {
465465
switch hook := maybeHook.(type) {
466-
case map[string]interface{}:
466+
case map[string]any:
467467
switch jobs := hook["jobs"].(type) {
468-
case []interface{}:
468+
case []any:
469469
destJobs[name] = jobs
470470
default:
471471
}
@@ -493,7 +493,7 @@ func mergeJobs(src, dest map[string]interface{}) error {
493493
for name, maybeHook := range dest {
494494
if jobs, ok := destJobs[name]; ok {
495495
switch hook := maybeHook.(type) {
496-
case map[string]interface{}:
496+
case map[string]any:
497497
hook["jobs"] = jobs
498498
default:
499499
}
@@ -503,13 +503,13 @@ func mergeJobs(src, dest map[string]interface{}) error {
503503
return nil
504504
}
505505

506-
func mergeJobsSlice(src, dest []interface{}) []interface{} {
507-
mergeable := make(map[string]map[string]interface{})
508-
result := make([]interface{}, 0, len(dest))
506+
func mergeJobsSlice(src, dest []any) []any {
507+
mergeable := make(map[string]map[string]any)
508+
result := make([]any, 0, len(dest))
509509

510510
for _, maybeJob := range dest {
511511
switch destJob := maybeJob.(type) {
512-
case map[string]interface{}:
512+
case map[string]any:
513513
switch name := destJob["name"].(type) {
514514
case string:
515515
mergeable[name] = destJob
@@ -523,27 +523,27 @@ func mergeJobsSlice(src, dest []interface{}) []interface{} {
523523

524524
for _, maybeJob := range src {
525525
switch srcJob := maybeJob.(type) {
526-
case map[string]interface{}:
526+
case map[string]any:
527527
switch name := srcJob["name"].(type) {
528528
case string:
529529
destJob, ok := mergeable[name]
530530
if ok {
531-
var srcSubJobs []interface{}
532-
var destSubJobs []interface{}
531+
var srcSubJobs []any
532+
var destSubJobs []any
533533

534534
switch srcGroup := srcJob["group"].(type) {
535-
case map[string]interface{}:
535+
case map[string]any:
536536
switch subJobs := srcGroup["jobs"].(type) {
537-
case []interface{}:
537+
case []any:
538538
srcSubJobs = subJobs
539539
default:
540540
}
541541
default:
542542
}
543543
switch destGroup := destJob["group"].(type) {
544-
case map[string]interface{}:
544+
case map[string]any:
545545
switch subJobs := destGroup["jobs"].(type) {
546-
case []interface{}:
546+
case []any:
547547
destSubJobs = subJobs
548548
default:
549549
}
@@ -570,9 +570,9 @@ func mergeJobsSlice(src, dest []interface{}) []interface{} {
570570

571571
if len(destSubJobs) != 0 {
572572
switch destGroup := destJob["group"].(type) {
573-
case map[string]interface{}:
573+
case map[string]any:
574574
switch destGroup["jobs"].(type) {
575-
case []interface{}:
575+
case []any:
576576
destGroup["jobs"] = destSubJobs
577577
default:
578578
}

0 commit comments

Comments
 (0)