Skip to content

Commit

Permalink
chore: Bump go to 1.23 (#39)
Browse files Browse the repository at this point in the history
  • Loading branch information
JeffFaer committed Sep 23, 2024
1 parent aad93f3 commit 71c288e
Show file tree
Hide file tree
Showing 7 changed files with 16 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ repos:
- id: keep-sorted
name: keep-sorted
language: golang
language_version: 1.21.6
language_version: 1.23.1
entry: go run .
- repo: https://github.com/pre-commit/pre-commit
rev: v3.6.0
Expand Down
2 changes: 1 addition & 1 deletion .pre-commit-hooks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
- id: keep-sorted
name: keep-sorted
language: golang
language_version: 1.21.6
language_version: 1.23.1
entry: keep-sorted
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ bar = [
1. Install go: https://go.dev/doc/install

> [!NOTE]
> keep-sorted currently requires at least go 1.21.
> keep-sorted currently requires at least go 1.23.
2. Install keep-sorted:

Expand Down
6 changes: 2 additions & 4 deletions cmd/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ import (
"errors"
"fmt"
"io"
"maps"
"os"
"slices"
"strconv"
"strings"

"github.com/google/keep-sorted/keepsorted"
flag "github.com/spf13/pflag"
"golang.org/x/exp/maps"
)

type Config struct {
Expand Down Expand Up @@ -87,9 +87,7 @@ var (
)

func knownModes() []string {
ms := maps.Keys(operations)
slices.Sort(ms)
return ms
return slices.Sorted(maps.Keys(operations))
}

type operation func(fixer *keepsorted.Fixer, filenames []string, modifiedLines []keepsorted.LineRange) (ok bool, err error)
Expand Down
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@ module github.com/google/keep-sorted

// Remember to also update language_version in .pre-commit-config.yaml,
// .pre-commit-hooks.yaml, and README.md!
go 1.21
go 1.23.1

require (
github.com/Workiva/go-datastructures v1.0.53
github.com/google/go-cmp v0.5.8
github.com/mattn/go-isatty v0.0.20
github.com/rs/zerolog v1.31.0
github.com/spf13/pflag v1.0.5
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc
)

require (
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9dec
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc h1:ao2WRsKSzW6KuUY9IWPwWahcHCgR0s52IfwutMfEbdM=
golang.org/x/exp v0.0.0-20240103183307-be819d1f06fc/go.mod h1:iRJReGqOEeBhDZGkGbynYwcHlctCvnjTYIamk7uXpHI=
golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
Expand Down
23 changes: 10 additions & 13 deletions keepsorted/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@ import (
"cmp"
"errors"
"fmt"
"maps"
"math/big"
"reflect"
"regexp"
"slices"
"strconv"
"strings"
"unicode"

"golang.org/x/exp/maps"
)

var (
Expand Down Expand Up @@ -189,20 +188,20 @@ func key(f reflect.StructField) string {

func parseValue(f reflect.StructField, key, val string) (reflect.Value, error) {
switch f.Type {
case reflect.TypeOf(bool(false)):
case reflect.TypeFor[bool]():
b, ok := boolValues[val]
if !ok {
return reflect.Zero(f.Type), fmt.Errorf("option %q has unknown value %q", key, val)
}

return reflect.ValueOf(b), nil
case reflect.TypeOf([]string{}):
case reflect.TypeFor[[]string]():
if val == "" {
return reflect.Zero(f.Type), nil
}

return reflect.ValueOf(strings.Split(val, ",")), nil
case reflect.TypeOf(map[string]bool{}):
case reflect.TypeFor[map[string]bool]():
if val == "" {
return reflect.Zero(f.Type), nil
}
Expand All @@ -213,7 +212,7 @@ func parseValue(f reflect.StructField, key, val string) (reflect.Value, error) {
m[s] = true
}
return reflect.ValueOf(m), nil
case reflect.TypeOf(int(0)):
case reflect.TypeFor[int]():
if val == "" {
return reflect.Zero(f.Type), nil
}
Expand All @@ -230,15 +229,13 @@ func parseValue(f reflect.StructField, key, val string) (reflect.Value, error) {

func formatValue(val reflect.Value) string {
switch val.Type() {
case reflect.TypeOf(bool(false)):
case reflect.TypeFor[bool]():
return boolString[val.Bool()]
case reflect.TypeOf([]string{}):
case reflect.TypeFor[[]string]():
return strings.Join(val.Interface().([]string), ",")
case reflect.TypeOf(map[string]bool{}):
keys := maps.Keys(val.Interface().(map[string]bool))
slices.Sort(keys)
return strings.Join(keys, ",")
case reflect.TypeOf(int(0)):
case reflect.TypeFor[map[string]bool]():
return strings.Join(slices.Sorted(maps.Keys(val.Interface().(map[string]bool))), ",")
case reflect.TypeFor[int]():
return strconv.Itoa(int(val.Int()))
}

Expand Down

0 comments on commit 71c288e

Please sign in to comment.