ci: Test with Go 1.23 and 1.24 (#502)

In CI, test with Go 1.23 and 1.24,
and upgrade the Hermit-managed Go and golangci-lint to latest versions.

The new golangci-lint had a number of warnings and minor issues
that were either fixed or opted-out of.
This commit is contained in:
Abhinav Gupta
2025-02-16 19:10:57 -08:00
committed by GitHub
parent cab639ab83
commit 9f71a49767
13 changed files with 24 additions and 34 deletions
+2 -2
View File
@@ -13,7 +13,7 @@ jobs:
matrix: matrix:
# These are the release channels. # These are the release channels.
# Hermit will handle installing the right patch. # Hermit will handle installing the right patch.
go: ["1.20", "1.21"] go: ["1.23", "1.24"]
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
@@ -35,7 +35,7 @@ jobs:
matrix: matrix:
# These are versions for GitHub's setup-go. # These are versions for GitHub's setup-go.
# '.x' will pick the latest patch release. # '.x' will pick the latest patch release.
go: ["1.20.x", "1.21.x"] go: ["1.23.x", "1.24.x"]
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v4 uses: actions/checkout@v4
+2 -2
View File
@@ -12,7 +12,6 @@ linters:
- wsl - wsl
- funlen - funlen
- gocognit - gocognit
- gomnd
- goprintffuncname - goprintffuncname
- paralleltest - paralleltest
- nlreturn - nlreturn
@@ -36,13 +35,14 @@ linters:
- nilnil - nilnil
- depguard # nothing to guard against yet - depguard # nothing to guard against yet
- tagalign # hurts readability of kong tags - tagalign # hurts readability of kong tags
- tenv # deprecated since v1.64, but not removed yet
- mnd - mnd
- perfsprint - perfsprint
- err113 - err113
- copyloopvar - copyloopvar
- intrange - intrange
- execinquery
- nakedret - nakedret
- recvcheck # value receivers are intentionally used for copies
linters-settings: linters-settings:
govet: govet:
+1 -1
View File
@@ -1 +1 @@
.go-1.23.6.pkg .go-1.24.0.pkg
+1 -1
View File
@@ -1 +1 @@
.go-1.23.6.pkg .go-1.24.0.pkg
+1 -1
View File
@@ -1 +1 @@
.golangci-lint-1.60.1.pkg .golangci-lint-1.64.5.pkg
+6 -9
View File
@@ -15,12 +15,10 @@ func TestMultipleConfigLoading(t *testing.T) {
} }
cli.Flag = "first" cli.Flag = "first"
first, cleanFirst := makeConfig(t, &cli) first := makeConfig(t, &cli)
defer cleanFirst()
cli.Flag = "" cli.Flag = ""
second, cleanSecond := makeConfig(t, &cli) second := makeConfig(t, &cli)
defer cleanSecond()
p := mustNew(t, &cli, kong.Configuration(kong.JSON, first, second)) p := mustNew(t, &cli, kong.Configuration(kong.JSON, first, second))
_, err := p.Parse(nil) _, err := p.Parse(nil)
@@ -34,20 +32,19 @@ func TestConfigValidation(t *testing.T) {
} }
cli.Flag = "invalid" cli.Flag = "invalid"
conf, cleanConf := makeConfig(t, &cli) conf := makeConfig(t, &cli)
defer cleanConf()
p := mustNew(t, &cli, kong.Configuration(kong.JSON, conf)) p := mustNew(t, &cli, kong.Configuration(kong.JSON, conf))
_, err := p.Parse(nil) _, err := p.Parse(nil)
assert.Error(t, err) assert.Error(t, err)
} }
func makeConfig(t *testing.T, config any) (path string, cleanup func()) { func makeConfig(t *testing.T, config any) (path string) {
t.Helper() t.Helper()
w, err := os.CreateTemp("", "") w, err := os.CreateTemp(t.TempDir(), "")
assert.NoError(t, err) assert.NoError(t, err)
defer w.Close() defer w.Close()
err = json.NewEncoder(w).Encode(config) err = json.NewEncoder(w).Encode(config)
assert.NoError(t, err) assert.NoError(t, err)
return w.Name(), func() { os.Remove(w.Name()) } return w.Name()
} }
+2 -2
View File
@@ -415,7 +415,7 @@ func (h *helpWriter) Write(w io.Writer) error {
func (h *helpWriter) Wrap(text string) { func (h *helpWriter) Wrap(text string) {
w := bytes.NewBuffer(nil) w := bytes.NewBuffer(nil)
doc.ToText(w, strings.TrimSpace(text), "", " ", h.width) doc.ToText(w, strings.TrimSpace(text), "", " ", h.width) //nolint:staticcheck // cross-package links not possible
for _, line := range strings.Split(strings.TrimSpace(w.String()), "\n") { for _, line := range strings.Split(strings.TrimSpace(w.String()), "\n") {
h.Print(line) h.Print(line)
} }
@@ -470,7 +470,7 @@ func writeTwoColumns(w *helpWriter, rows [][2]string) {
for _, row := range rows { for _, row := range rows {
buf := bytes.NewBuffer(nil) buf := bytes.NewBuffer(nil)
doc.ToText(buf, row[1], "", strings.Repeat(" ", defaultIndent), w.width-leftSize-defaultColumnPadding) doc.ToText(buf, row[1], "", strings.Repeat(" ", defaultIndent), w.width-leftSize-defaultColumnPadding) //nolint:staticcheck // cross-package links not possible
lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n") lines := strings.Split(strings.TrimRight(buf.String(), "\n"), "\n")
line := fmt.Sprintf("%-*s", leftSize, row[0]) line := fmt.Sprintf("%-*s", leftSize, row[0])
+5 -9
View File
@@ -83,8 +83,7 @@ func TestHelp(t *testing.T) {
Three threeArg `arg help:"Sub-sub-arg."` Three threeArg `arg help:"Sub-sub-arg."`
Four struct { Four struct{} `cmd help:"Sub-sub-command."`
} `cmd help:"Sub-sub-command."`
} `cmd help:"Another subcommand."` } `cmd help:"Another subcommand."`
} }
@@ -192,8 +191,7 @@ func TestFlagsLast(t *testing.T) {
Three threeArg `arg help:"Sub-sub-arg."` Three threeArg `arg help:"Sub-sub-arg."`
Four struct { Four struct{} `cmd help:"Sub-sub-command."`
} `cmd help:"Sub-sub-command."`
} `cmd help:"Another subcommand."` } `cmd help:"Another subcommand."`
} }
@@ -296,8 +294,7 @@ func TestHelpTree(t *testing.T) {
Two struct { Two struct {
Three threeArg `arg help:"Sub-sub-arg."` Three threeArg `arg help:"Sub-sub-arg."`
Four struct { Four struct{} `cmd help:"Sub-sub-command." aliases:"for,fore"`
} `cmd help:"Sub-sub-command." aliases:"for,fore"`
} `cmd help:"Another subcommand."` } `cmd help:"Another subcommand."`
} }
@@ -390,8 +387,7 @@ func TestHelpCompactNoExpand(t *testing.T) {
Two struct { Two struct {
Three threeArg `arg help:"Sub-sub-arg."` Three threeArg `arg help:"Sub-sub-arg."`
Four struct { Four struct{} `cmd help:"Sub-sub-command." aliases:"for,fore"`
} `cmd help:"Sub-sub-command." aliases:"for,fore"`
} `cmd help:"Another subcommand."` } `cmd help:"Another subcommand."`
} }
@@ -603,7 +599,7 @@ func TestAutoGroup(t *testing.T) {
if node, ok := parent.(*kong.Node); ok { if node, ok := parent.(*kong.Node); ok {
return &kong.Group{ return &kong.Group{
Key: node.Name, Key: node.Name,
Title: strings.Title(node.Name) + " flags:", Title: strings.Title(node.Name) + " flags:", //nolint:staticcheck // strings.Title in test is okay
} }
} }
return nil return nil
+2 -4
View File
@@ -268,9 +268,8 @@ func TestFileContentFlag(t *testing.T) {
var cli struct { var cli struct {
File kong.FileContentFlag File kong.FileContentFlag
} }
f, err := os.CreateTemp("", "") f, err := os.CreateTemp(t.TempDir(), "")
assert.NoError(t, err) assert.NoError(t, err)
defer os.Remove(f.Name())
fmt.Fprint(f, "hello world") fmt.Fprint(f, "hello world")
f.Close() f.Close()
_, err = mustNew(t, &cli).Parse([]string{"--file", f.Name()}) _, err = mustNew(t, &cli).Parse([]string{"--file", f.Name()})
@@ -282,9 +281,8 @@ func TestNamedFileContentFlag(t *testing.T) {
var cli struct { var cli struct {
File kong.NamedFileContentFlag File kong.NamedFileContentFlag
} }
f, err := os.CreateTemp("", "") f, err := os.CreateTemp(t.TempDir(), "")
assert.NoError(t, err) assert.NoError(t, err)
defer os.Remove(f.Name())
fmt.Fprint(f, "hello world") fmt.Fprint(f, "hello world")
f.Close() f.Close()
_, err = mustNew(t, &cli).Parse([]string{"--file", f.Name()}) _, err = mustNew(t, &cli).Parse([]string{"--file", f.Name()})
+1 -1
View File
@@ -63,6 +63,6 @@ func JSON(r io.Reader) (Resolver, error) {
} }
func snakeCase(name string) string { func snakeCase(name string) string {
name = strings.Join(strings.Split(strings.Title(name), "-"), "") name = strings.Join(strings.Split(strings.Title(name), "-"), "") //nolint:staticcheck // Unicode punctuation not an issue
return strings.ToLower(name[:1]) + name[1:] return strings.ToLower(name[:1]) + name[1:]
} }
+1 -2
View File
@@ -16,9 +16,8 @@ func TestConfigFlag(t *testing.T) {
Flag string Flag string
} }
w, err := os.CreateTemp("", "") w, err := os.CreateTemp(t.TempDir(), "")
assert.NoError(t, err) assert.NoError(t, err)
defer os.Remove(w.Name())
w.WriteString(`{"flag": "hello world"}`) //nolint: errcheck w.WriteString(`{"flag": "hello world"}`) //nolint: errcheck
w.Close() w.Close()