chore: update golangci-lint to v2.13.0

Migrate the deprecated gofumpt `extra-rules` to `extra.group-params`, as
the alias now also enables the new `clothe-returns` and `balance-calls`
rules. Disable SA4023, which hangs on go 1.27, see
https://github.com/golangci/golangci-lint/issues/6732.

Apply the resulting modernize fixes, mostly flattening embedded struct
literals and switching errors.As to errors.AsType.

Assisted-by: Claude:Opus 5
This commit is contained in:
silverwind
2026-08-20 06:21:34 +02:00
parent b227ad8a5f
commit bef127f188
173 changed files with 1161 additions and 1659 deletions
+1 -2
View File
@@ -114,8 +114,7 @@ func (c *Commit) HasPreviousCommit(ctx context.Context, gitRepo *Repository, obj
if err == nil {
return true, nil
}
var exitError *exec.ExitError
if errors.As(err, &exitError) {
if exitError, ok := errors.AsType[*exec.ExitError](err); ok {
if exitError.ProcessState.ExitCode() == 1 && len(exitError.Stderr) == 0 {
return false, nil
}
+8 -8
View File
@@ -11,7 +11,7 @@ import (
func TestCommitMessageSanitizesInvalidUTF8(t *testing.T) {
commit := &Commit{
CommitMessage: CommitMessage{MessageRaw: "title \xff\n\n\n\nbody \xff\n\n\n"},
MessageRaw: "title \xff\n\n\n\nbody \xff\n\n\n",
}
assert.Equal(t, "title ÿ", commit.MessageTitle())
assert.Equal(t, "body ÿ", commit.MessageBody())
@@ -65,7 +65,7 @@ func TestCommitMessageParticipants(t *testing.T) {
"CommitterExcluded",
&Commit{
Author: sig("a", "a@m.com"), Committer: sig("c", "c@m.com"),
CommitMessage: CommitMessage{MessageRaw: "CO-Authored-BY: Full Name <x@m.com>"},
MessageRaw: "CO-Authored-BY: Full Name <x@m.com>",
},
[]*CommitIdentity{idt("a", "a@m.com", roleAuthor), idt("Full Name", "x@m.com", roleCoAuthor)},
},
@@ -73,7 +73,7 @@ func TestCommitMessageParticipants(t *testing.T) {
"AuthorIsCoAuthor",
&Commit{
Author: sig("a", "a@m.com"), Committer: sig("c", "c@m.com"),
CommitMessage: CommitMessage{MessageRaw: "CO-Authored-BY: other-name <a@m.com>"},
MessageRaw: "CO-Authored-BY: other-name <a@m.com>",
},
[]*CommitIdentity{idt("a", "a@m.com", roleAuthor)},
},
@@ -81,7 +81,7 @@ func TestCommitMessageParticipants(t *testing.T) {
"EmptyAuthor", // synthesized commits (push feed) may have no author signature at all
&Commit{
Author: sig("", ""), Committer: sig("", ""),
CommitMessage: CommitMessage{MessageRaw: "Co-authored-by: c <c@m.com>"},
MessageRaw: "Co-authored-by: c <c@m.com>",
},
// but if the commit message contains co-authors, the co-authors are still parsed for "all authors"
// if it is a problem, the caller should fix the problem (provide correct "author")
@@ -98,7 +98,7 @@ func TestCommitMessageParticipants(t *testing.T) {
"GenuineCoAuthor",
&Commit{
Author: sig("a", "a@m.com"), Committer: sig("c", "c@m.com"),
CommitMessage: CommitMessage{MessageRaw: "Co-authored-by: x <x@m.com>"},
MessageRaw: "Co-authored-by: x <x@m.com>",
},
[]*CommitIdentity{idt("x", "x@m.com", roleCoAuthor)},
},
@@ -106,7 +106,7 @@ func TestCommitMessageParticipants(t *testing.T) {
"CoAuthorIsCommitter",
&Commit{
Author: sig("a", "a@m.com"), Committer: sig("c", "c@m.com"),
CommitMessage: CommitMessage{MessageRaw: "Co-authored-by: c <c@m.com>"},
MessageRaw: "Co-authored-by: c <c@m.com>",
},
[]*CommitIdentity{idt("c", "c@m.com", roleCoAuthor)},
},
@@ -114,7 +114,7 @@ func TestCommitMessageParticipants(t *testing.T) {
"CoAuthorIsAuthor",
&Commit{
Author: sig("a", "a@m.com"), Committer: sig("c", "c@m.com"),
CommitMessage: CommitMessage{MessageRaw: "Co-authored-by: a <a@m.com>"},
MessageRaw: "Co-authored-by: a <a@m.com>",
},
[]*CommitIdentity{},
},
@@ -122,7 +122,7 @@ func TestCommitMessageParticipants(t *testing.T) {
"CoAuthorNameOnlyAndDuplicate",
&Commit{
Author: sig("a", "a@m.com"), Committer: sig("c", "c@m.com"),
CommitMessage: CommitMessage{MessageRaw: "Co-authored-by: b\nCo-authored-by: b\nCo-authored-by: c"},
MessageRaw: "Co-authored-by: b\nCo-authored-by: b\nCo-authored-by: c",
},
[]*CommitIdentity{idt("b", "", roleCoAuthor), idt("c", "", roleCoAuthor)},
},
+1 -1
View File
@@ -79,7 +79,7 @@ func TestGrepSearch(t *testing.T) {
assert.NoError(t, err)
assert.Empty(t, res)
nonExistingRepo := &Repository{RepositoryBase: RepositoryBase{repoFacade: gitrepo.RepositoryUnmanaged("no-such-git-repo")}}
nonExistingRepo := &Repository{repoFacade: gitrepo.RepositoryUnmanaged("no-such-git-repo")}
res, err = GrepSearch(t.Context(), nonExistingRepo, "no-such-content", GrepOptions{})
assert.Error(t, err)
assert.Empty(t, res)
+8 -4
View File
@@ -54,24 +54,28 @@ func GetSigningKey(ctx context.Context) (*SigningKey, *Signature) {
return nil, nil
}
return &SigningKey{
key := &SigningKey{
KeyID: strings.TrimSpace(signingKey),
Format: strings.TrimSpace(format),
}, &Signature{
}
sig := &Signature{
Name: strings.TrimSpace(signingName),
Email: strings.TrimSpace(signingEmail),
}
return key, sig
}
if setting.Repository.Signing.SigningKey == "" {
return nil, nil
}
return &SigningKey{
key := &SigningKey{
KeyID: setting.Repository.Signing.SigningKey,
Format: setting.Repository.Signing.SigningFormat,
}, &Signature{
}
sig := &Signature{
Name: setting.Repository.Signing.SigningName,
Email: setting.Repository.Signing.SigningEmail,
}
return key, sig
}
+1 -1
View File
@@ -70,7 +70,7 @@ func OpenRepository(catFileBatchCtx context.Context, repo RepositoryFacade) (*Re
return nil, util.NewNotExistErrorf("no such file or directory")
}
gitRepo := &Repository{
RepositoryBase: RepositoryBase{tagCache: newObjectCache[*Tag](), repoFacade: repo, catFileBatchCtx: catFileBatchCtx},
tagCache: newObjectCache[*Tag](), repoFacade: repo, catFileBatchCtx: catFileBatchCtx,
}
gitRepo.RepositoryBase.LastCommitCache = &LastCommitCache{
repo: gitRepo,
+20 -20
View File
@@ -211,13 +211,13 @@ func TestRepository_parseTagRef(t *testing.T) {
},
want: &Tag{
Name: "v1.9.1",
ID: MustIDFromString("ab23e4b7f4cd0caafe0174c0e7ef6d651ba72889"),
Object: MustIDFromString("ab23e4b7f4cd0caafe0174c0e7ef6d651ba72889"),
Type: "commit",
Tagger: parseSignatureFromCommitLine("Foo Bar <foo@bar.com> 1565789218 +0300"),
CommitMessage: CommitMessage{MessageRaw: "Add changelog of v1.9.1 (#7859)\n\n* add changelog of v1.9.1\n* Update CHANGELOG.md\n"},
Signature: nil,
Name: "v1.9.1",
ID: MustIDFromString("ab23e4b7f4cd0caafe0174c0e7ef6d651ba72889"),
Object: MustIDFromString("ab23e4b7f4cd0caafe0174c0e7ef6d651ba72889"),
Type: "commit",
Tagger: parseSignatureFromCommitLine("Foo Bar <foo@bar.com> 1565789218 +0300"),
MessageRaw: "Add changelog of v1.9.1 (#7859)\n\n* add changelog of v1.9.1\n* Update CHANGELOG.md\n",
Signature: nil,
},
},
@@ -240,13 +240,13 @@ func TestRepository_parseTagRef(t *testing.T) {
},
want: &Tag{
Name: "v0.0.1",
ID: MustIDFromString("8c68a1f06fc59c655b7e3905b159d761e91c53c9"),
Object: MustIDFromString("3325fd8a973321fd59455492976c042dde3fd1ca"),
Type: "tag",
Tagger: parseSignatureFromCommitLine("Foo Bar <foo@bar.com> 1565789218 +0300"),
CommitMessage: CommitMessage{MessageRaw: "Add changelog of v1.9.1 (#7859)\n\n* add changelog of v1.9.1\n* Update CHANGELOG.md\n"},
Signature: nil,
Name: "v0.0.1",
ID: MustIDFromString("8c68a1f06fc59c655b7e3905b159d761e91c53c9"),
Object: MustIDFromString("3325fd8a973321fd59455492976c042dde3fd1ca"),
Type: "tag",
Tagger: parseSignatureFromCommitLine("Foo Bar <foo@bar.com> 1565789218 +0300"),
MessageRaw: "Add changelog of v1.9.1 (#7859)\n\n* add changelog of v1.9.1\n* Update CHANGELOG.md\n",
Signature: nil,
},
},
@@ -299,12 +299,12 @@ qbHDASXl
},
want: &Tag{
Name: "v0.0.1",
ID: MustIDFromString("8c68a1f06fc59c655b7e3905b159d761e91c53c9"),
Object: MustIDFromString("3325fd8a973321fd59455492976c042dde3fd1ca"),
Type: "tag",
Tagger: parseSignatureFromCommitLine("Foo Bar <foo@bar.com> 1565789218 +0300"),
CommitMessage: CommitMessage{MessageRaw: "Add changelog of v1.9.1 (#7859)\n\n* add changelog of v1.9.1\n* Update CHANGELOG.md\n"},
Name: "v0.0.1",
ID: MustIDFromString("8c68a1f06fc59c655b7e3905b159d761e91c53c9"),
Object: MustIDFromString("3325fd8a973321fd59455492976c042dde3fd1ca"),
Type: "tag",
Tagger: parseSignatureFromCommitLine("Foo Bar <foo@bar.com> 1565789218 +0300"),
MessageRaw: "Add changelog of v1.9.1 (#7859)\n\n* add changelog of v1.9.1\n* Update CHANGELOG.md\n",
Signature: &CommitSignature{
Signature: `-----BEGIN PGP SIGNATURE-----
+1 -1
View File
@@ -17,7 +17,7 @@ type TreeCommon struct {
}
func newTree(id ObjectID) *Tree {
return &Tree{TreeCommon: TreeCommon{ID: id}}
return &Tree{ID: id}
}
// SubTree get a subtree by the sub dir path