chore: add modernizer linter (#11936)

- Go has a suite of small linters that helps with modernizing Go code by using newer functions and catching small mistakes, https://pkg.go.dev/golang.org/x/tools/go/analysis/passes/modernize.
- Enable this linter in golangci-lint.
- There's also [`go fix`](https://go.dev/blog/gofix), which is not yet released as a linter in golangci-lint: https://github.com/golangci/golangci-lint/pull/6385

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11936
Reviewed-by: Mathieu Fenniak <mfenniak@noreply.codeberg.org>
Co-authored-by: Gusted <postmaster@gusted.xyz>
Co-committed-by: Gusted <postmaster@gusted.xyz>
This commit is contained in:
Gusted 2026-04-02 03:29:37 +02:00 committed by Gusted
parent d728fddec5
commit 77dbc35138
249 changed files with 659 additions and 1010 deletions

View file

@ -70,13 +70,13 @@ type ActionRun struct {
// the current status of this run
Status string `json:"status"`
// when the action run was started
Started time.Time `json:"started,omitempty"`
Started time.Time `json:"started"`
// when the action run was stopped
Stopped time.Time `json:"stopped,omitempty"`
Stopped time.Time `json:"stopped"`
// when the action run was created
Created time.Time `json:"created,omitempty"`
Created time.Time `json:"created"`
// when the action run was last updated
Updated time.Time `json:"updated,omitempty"`
Updated time.Time `json:"updated"`
// how long the action run ran for
Duration time.Duration `json:"duration,omitempty"`
// the url of this action run

View file

@ -204,7 +204,7 @@ func (l *IssueTemplateLabels) UnmarshalYAML(value *yaml.Node) error {
if err != nil {
return err
}
for _, v := range strings.Split(str, ",") {
for v := range strings.SplitSeq(str, ",") {
if v = strings.TrimSpace(v); v == "" {
continue
}

View file

@ -118,7 +118,7 @@ type Repository struct {
// enum: ["sha1", "sha256"]
ObjectFormatName string `json:"object_format_name"`
// swagger:strfmt date-time
MirrorUpdated time.Time `json:"mirror_updated,omitempty"`
MirrorUpdated time.Time `json:"mirror_updated"`
RepoTransfer *RepoTransfer `json:"repo_transfer"`
Topics []string `json:"topics"`
}

View file

@ -34,9 +34,9 @@ type User struct {
// Is the user an administrator
IsAdmin bool `json:"is_admin"`
// swagger:strfmt date-time
LastLogin time.Time `json:"last_login,omitempty"`
LastLogin time.Time `json:"last_login"`
// swagger:strfmt date-time
Created time.Time `json:"created,omitempty"`
Created time.Time `json:"created"`
// Is user restricted
Restricted bool `json:"restricted"`
// Is user active

View file

@ -21,9 +21,9 @@ type GPGKey struct {
CanCertify bool `json:"can_certify"`
Verified bool `json:"verified"`
// swagger:strfmt date-time
Created time.Time `json:"created_at,omitempty"`
Created time.Time `json:"created_at"`
// swagger:strfmt date-time
Expires time.Time `json:"expires_at,omitempty"`
Expires time.Time `json:"expires_at"`
}
// GPGKeyEmail an email attached to a GPGKey

View file

@ -15,7 +15,7 @@ type PublicKey struct {
Title string `json:"title,omitempty"`
Fingerprint string `json:"fingerprint,omitempty"`
// swagger:strfmt date-time
Created time.Time `json:"created_at,omitempty"`
Created time.Time `json:"created_at"`
Owner *User `json:"user,omitempty"`
ReadOnly bool `json:"read_only,omitempty"`
KeyType string `json:"key_type,omitempty"`