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
2625type 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
3534var (
@@ -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}
0 commit comments