Skip to content

Commit c52b603

Browse files
committed
MAJOR: update to go 1.26
1 parent e01a8b4 commit c52b603

File tree

20 files changed

+384
-81
lines changed

20 files changed

+384
-81
lines changed

.aspell.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,31 @@ allowed:
3939
- junit
4040
- deps
4141
- alternative
42+
- awk
43+
- betteralign
44+
- cmd
45+
- cmds
46+
- cyclomatic
47+
- desc
48+
- dotenv
49+
- eval
50+
- fmt
51+
- formatter
52+
- gobin
53+
- gofumpt
54+
- gotestsum
55+
- govulncheck
56+
- hivis
57+
- linters
58+
- Printf
59+
- Println
60+
- staticcheck
61+
- struct
62+
- structs
63+
- taskfile
64+
- testdox
65+
- tmp
66+
- toml
67+
- unexported
68+
- unhandled
69+
- yml

.github/workflows/actions.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@ jobs:
1111
with:
1212
go-version-file: 'go.mod'
1313
check-latest: true
14-
- name: golangci-lint
15-
uses: golangci/golangci-lint-action@v6
14+
- name: Install Task
15+
uses: arduino/setup-task@v2
16+
with:
17+
version: 3.x
18+
- name: lint
19+
run: task lint
1620
go_build:
1721
name: Go build
1822
runs-on: ubuntu-latest

.golangci.yml

Lines changed: 0 additions & 5 deletions
This file was deleted.

aspell/aspell.go

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"log"
77
"os/exec"
88
"slices"
9-
"sort"
109
"strings"
1110

1211
"github.com/haproxytech/check-commit/v5/junit"
@@ -24,12 +23,12 @@ type RemoteFile struct {
2423
}
2524

2625
type Aspell struct {
27-
Mode mode `yaml:"mode"`
2826
RemoteFile RemoteFile `yaml:"remote_file"`
29-
MinLength int `yaml:"min_length"`
27+
Mode mode `yaml:"mode"`
28+
HelpText string `yaml:"-"`
3029
IgnoreFiles []string `yaml:"ignore_files"`
3130
AllowedWords []string `yaml:"allowed"`
32-
HelpText string `yaml:"-"`
31+
MinLength int `yaml:"min_length"`
3332
}
3433

3534
var (
@@ -116,7 +115,7 @@ func (a Aspell) checkSingle(data string, allowedWords []string) error {
116115
for k := range m {
117116
badWords = append(badWords, k)
118117
}
119-
sort.Strings(badWords)
118+
slices.Sort(badWords)
120119
return fmt.Errorf("aspell: %s", badWords)
121120
}
122121
return nil
@@ -126,8 +125,8 @@ func (a Aspell) Check(subjects []string, commitsFull []string, content []map[str
126125
var commitsFullData []string
127126
for _, c := range commitsFull {
128127
commit := []string{}
129-
lines := strings.Split(c, "\n")
130-
for _, l := range lines {
128+
lines := strings.SplitSeq(c, "\n")
129+
for l := range lines {
131130
c2 := strings.TrimSpace(l)
132131
if strings.HasPrefix(c2, "Signed-off-by:") ||
133132
strings.HasPrefix(c2, "Reviewed-by:") ||
@@ -144,7 +143,7 @@ func (a Aspell) Check(subjects []string, commitsFull []string, content []map[str
144143
commitsFullData = append(commitsFullData, strings.Join(commit, "\n"))
145144
}
146145

147-
var response string
146+
var response strings.Builder
148147
var checks []string
149148
switch a.Mode {
150149
case modeDisabled:
@@ -174,25 +173,23 @@ func (a Aspell) Check(subjects []string, commitsFull []string, content []map[str
174173
if err := a.checkSingle(v, imports); err != nil {
175174
junitSuite.AddMessageFailed(name, "aspell check failed", err.Error())
176175
log.Println(name, err.Error())
177-
response += fmt.Sprintf("%s\n", err)
176+
response.WriteString(fmt.Sprintf("%s\n", err))
178177
}
179178
}
180179
}
181180
checks = commitsFullData
182-
default:
183-
checks = subjects
184181
}
185182

186183
for _, subject := range checks {
187184
if err := a.checkSingle(subject, []string{}); err != nil {
188185
junitSuite.AddMessageFailed("commit message", "aspell check failed", err.Error())
189186
log.Println("commit message", err.Error())
190-
response += fmt.Sprintf("%s\n", err)
187+
response.WriteString(fmt.Sprintf("%s\n", err))
191188
}
192189
}
193190

194-
if len(response) > 0 {
195-
return fmt.Errorf("%s", response)
191+
if len(response.String()) > 0 {
192+
return fmt.Errorf("%s", response.String())
196193
}
197194
return nil
198195
}

aspell/new.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ func New(filename string) (Aspell, error) {
3232
return Aspell{}, err
3333
}
3434
if len(extraAllowedWords) == 0 {
35-
log.Printf("warning: aspell remote file is empty")
35+
log.Print("warning: aspell remote file is empty")
3636
}
3737
}
3838

@@ -48,10 +48,7 @@ func New(filename string) (Aspell, error) {
4848
}
4949

5050
switch aspell.Mode {
51-
case modeDisabled:
52-
case modeSubject:
53-
case modeCommit:
54-
case modeAll:
51+
case modeDisabled, modeSubject, modeCommit, modeAll:
5552
case "":
5653
aspell.Mode = modeSubject
5754
default:

aspell/remote.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package aspell
22

33
import (
44
"encoding/json"
5+
"errors"
56
"fmt"
67
"log"
78
"net/http"
@@ -21,7 +22,7 @@ func fetchRemoteFile(aspell Aspell) ([]string, error) {
2122
}
2223

2324
if url == "" {
24-
return nil, fmt.Errorf("aspell remote file: URL is empty")
25+
return nil, errors.New("aspell remote file: URL is empty")
2526
}
2627

2728
req, err := http.NewRequest("GET", url, nil)
@@ -55,15 +56,15 @@ func fetchRemoteFile(aspell Aspell) ([]string, error) {
5556
return nil, fmt.Errorf("error fetching remote file: %s", resp.Status)
5657
}
5758

58-
var data map[string]interface{}
59+
var data map[string]any
5960
err = json.NewDecoder(resp.Body).Decode(&data)
6061
if err != nil {
6162
return nil, fmt.Errorf("aspell remote file: failed to decode JSON: %w", err)
6263
}
6364

6465
var allowedWords []string
6566

66-
items, ok := data[aspell.RemoteFile.AllowedItemsKey].([]interface{})
67+
items, ok := data[aspell.RemoteFile.AllowedItemsKey].([]any)
6768
if !ok {
6869
content, ok := data[aspell.RemoteFile.AllowedItemsKey].(string)
6970
if !ok {

aspell_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"bufio"
55
"log"
66
"os"
7+
"strings"
78
"testing"
89

910
"github.com/haproxytech/check-commit/v5/aspell"
@@ -13,7 +14,7 @@ import (
1314
func Test_Aspell(t *testing.T) {
1415
log.SetFlags(log.LstdFlags | log.Lshortfile)
1516

16-
aspell, err := aspell.New(".aspell.yml")
17+
aspellCheck, err := aspell.New(".aspell.yml")
1718
if err != nil {
1819
t.Errorf("checkWithAspell() error = %v", err)
1920
}
@@ -27,15 +28,15 @@ func Test_Aspell(t *testing.T) {
2728
defer readmeFile.Close()
2829

2930
scanner := bufio.NewScanner(readmeFile)
30-
readme := ""
31+
var readme strings.Builder
3132
for scanner.Scan() {
32-
readme += scanner.Text() + "\n"
33+
readme.WriteString(scanner.Text() + "\n")
3334
}
3435
if err := scanner.Err(); err != nil {
3536
t.Errorf("could not read "+filename+" file: %v", err)
3637
}
37-
err = aspell.Check([]string{"subject"}, []string{"body"}, []map[string]string{
38-
{filename: readme},
38+
err = aspellCheck.Check([]string{"subject"}, []string{"body"}, []map[string]string{
39+
{filename: readme.String()},
3940
}, &junit.JunitSuiteDummy{})
4041
if err != nil {
4142
t.Errorf("checkWithAspell() error = %v", err)

0 commit comments

Comments
 (0)