Update golangci-lint to v1.62.2, fix issues (#32845)

Update it and fix new issues related to `redefines-builtin-id`
This commit is contained in:
silverwind 2024-12-15 03:31:07 +01:00 committed by GitHub
parent 7616aeb2ea
commit 1cfb718976
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
13 changed files with 36 additions and 36 deletions

View File

@ -28,7 +28,7 @@ XGO_VERSION := go-1.23.x
AIR_PACKAGE ?= github.com/air-verse/air@v1 AIR_PACKAGE ?= github.com/air-verse/air@v1
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.0 EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.0
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.7.0 GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.7.0
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.60.3 GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.62.2
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11 GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.5.1 MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.5.1
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0 SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0

View File

@ -18,12 +18,12 @@ func RecalculateIssueIndexForRepo(ctx context.Context, repoID int64) error {
} }
defer committer.Close() defer committer.Close()
var max int64 var maxIndex int64
if _, err = db.GetEngine(ctx).Select(" MAX(`index`)").Table("issue").Where("repo_id=?", repoID).Get(&max); err != nil { if _, err = db.GetEngine(ctx).Select(" MAX(`index`)").Table("issue").Where("repo_id=?", repoID).Get(&maxIndex); err != nil {
return err return err
} }
if err = db.SyncMaxResourceIndex(ctx, "issue_index", repoID, max); err != nil { if err = db.SyncMaxResourceIndex(ctx, "issue_index", repoID, maxIndex); err != nil {
return err return err
} }

View File

@ -99,10 +99,10 @@ func IsComplexEnough(pwd string) bool {
func Generate(n int) (string, error) { func Generate(n int) (string, error) {
NewComplexity() NewComplexity()
buffer := make([]byte, n) buffer := make([]byte, n)
max := big.NewInt(int64(len(validChars))) maxInt := big.NewInt(int64(len(validChars)))
for { for {
for j := 0; j < n; j++ { for j := 0; j < n; j++ {
rnd, err := rand.Int(rand.Reader, max) rnd, err := rand.Int(rand.Reader, maxInt)
if err != nil { if err != nil {
return "", err return "", err
} }

View File

@ -465,15 +465,15 @@ func (repo *Repository) getBranches(env []string, commitID string, limit int) ([
refs := strings.Split(stdout, "\n") refs := strings.Split(stdout, "\n")
var max int var maxNum int
if len(refs) > limit { if len(refs) > limit {
max = limit maxNum = limit
} else { } else {
max = len(refs) - 1 maxNum = len(refs) - 1
} }
branches := make([]string, max) branches := make([]string, maxNum)
for i, ref := range refs[:max] { for i, ref := range refs[:maxNum] {
parts := strings.Fields(ref) parts := strings.Fields(ref)
branches[i] = parts[len(parts)-1] branches[i] = parts[len(parts)-1]

View File

@ -218,13 +218,13 @@ func (g *Manager) ServerDone() {
g.runningServerWaitGroup.Done() g.runningServerWaitGroup.Done()
} }
func (g *Manager) setStateTransition(old, new state) bool { func (g *Manager) setStateTransition(oldState, newState state) bool {
g.lock.Lock() g.lock.Lock()
if g.state != old { if g.state != oldState {
g.lock.Unlock() g.lock.Unlock()
return false return false
} }
g.state = new g.state = newState
g.lock.Unlock() g.lock.Unlock()
return true return true
} }

View File

@ -35,18 +35,18 @@ func BoolFieldQuery(value bool, field string) *query.BoolFieldQuery {
return q return q
} }
func NumericRangeInclusiveQuery(min, max optional.Option[int64], field string) *query.NumericRangeQuery { func NumericRangeInclusiveQuery(minOption, maxOption optional.Option[int64], field string) *query.NumericRangeQuery {
var minF, maxF *float64 var minF, maxF *float64
var minI, maxI *bool var minI, maxI *bool
if min.Has() { if minOption.Has() {
minF = new(float64) minF = new(float64)
*minF = float64(min.Value()) *minF = float64(minOption.Value())
minI = new(bool) minI = new(bool)
*minI = true *minI = true
} }
if max.Has() { if maxOption.Has() {
maxF = new(float64) maxF = new(float64)
*maxF = float64(max.Value()) *maxF = float64(maxOption.Value())
maxI = new(bool) maxI = new(bool)
*maxI = true *maxI = true
} }

View File

@ -10,12 +10,12 @@ import (
) )
// ParsePaginator parses a db.Paginator into a skip and limit // ParsePaginator parses a db.Paginator into a skip and limit
func ParsePaginator(paginator *db.ListOptions, max ...int) (int, int) { func ParsePaginator(paginator *db.ListOptions, maxNums ...int) (int, int) {
// Use a very large number to indicate no limit // Use a very large number to indicate no limit
unlimited := math.MaxInt32 unlimited := math.MaxInt32
if len(max) > 0 { if len(maxNums) > 0 {
// Some indexer engines have a limit on the page size, respect that // Some indexer engines have a limit on the page size, respect that
unlimited = max[0] unlimited = maxNums[0]
} }
if paginator == nil || paginator.IsListAll() { if paginator == nil || paginator.IsListAll() {

View File

@ -110,10 +110,10 @@ func EventFormatTextMessage(mode *WriterMode, event *Event, msgFormat string, ms
buf = append(buf, ' ') buf = append(buf, ' ')
} }
if flags&(Ltime|Lmicroseconds) != 0 { if flags&(Ltime|Lmicroseconds) != 0 {
hour, min, sec := t.Clock() hour, minNum, sec := t.Clock()
buf = itoa(buf, hour, 2) buf = itoa(buf, hour, 2)
buf = append(buf, ':') buf = append(buf, ':')
buf = itoa(buf, min, 2) buf = itoa(buf, minNum, 2)
buf = append(buf, ':') buf = append(buf, ':')
buf = itoa(buf, sec, 2) buf = itoa(buf, sec, 2)
if flags&Lmicroseconds != 0 { if flags&Lmicroseconds != 0 {

View File

@ -164,9 +164,9 @@ func newKeywords() {
}) })
} }
func doNewKeywords(close, reopen []string) { func doNewKeywords(closeKeywords, reopenKeywords []string) {
issueCloseKeywordsPat = makeKeywordsPat(close) issueCloseKeywordsPat = makeKeywordsPat(closeKeywords)
issueReopenKeywordsPat = makeKeywordsPat(reopen) issueReopenKeywordsPat = makeKeywordsPat(reopenKeywords)
} }
// getGiteaHostName returns a normalized string with the local host name, with no scheme or port information // getGiteaHostName returns a normalized string with the local host name, with no scheme or port information

View File

@ -53,8 +53,8 @@ func parseLegacy(datetime string) time.Time {
return t return t
} }
func anyToTime(any any) (t time.Time, isZero bool) { func anyToTime(value any) (t time.Time, isZero bool) {
switch v := any.(type) { switch v := value.(type) {
case nil: case nil:
// it is zero // it is zero
case *time.Time: case *time.Time:
@ -72,7 +72,7 @@ func anyToTime(any any) (t time.Time, isZero bool) {
case int64: case int64:
t = timeutil.TimeStamp(v).AsTime() t = timeutil.TimeStamp(v).AsTime()
default: default:
panic(fmt.Sprintf("Unsupported time type %T", any)) panic(fmt.Sprintf("Unsupported time type %T", value))
} }
return t, t.IsZero() || t.Unix() == 0 return t, t.IsZero() || t.Unix() == 0
} }

View File

@ -53,8 +53,8 @@ func (su *StringUtils) Cut(s, sep string) []any {
return []any{before, after, found} return []any{before, after, found}
} }
func (su *StringUtils) EllipsisString(s string, max int) string { func (su *StringUtils) EllipsisString(s string, maxLength int) string {
return base.EllipsisString(s, max) return base.EllipsisString(s, maxLength)
} }
func (su *StringUtils) ToUpper(s string) string { func (su *StringUtils) ToUpper(s string) string {

View File

@ -338,7 +338,7 @@ func GetIssueBlocks(ctx *context.APIContext) {
} }
skip := (page - 1) * limit skip := (page - 1) * limit
max := page * limit maxNum := page * limit
deps, err := issue.BlockingDependencies(ctx) deps, err := issue.BlockingDependencies(ctx)
if err != nil { if err != nil {
@ -352,7 +352,7 @@ func GetIssueBlocks(ctx *context.APIContext) {
repoPerms[ctx.Repo.Repository.ID] = ctx.Repo.Permission repoPerms[ctx.Repo.Repository.ID] = ctx.Repo.Permission
for i, depMeta := range deps { for i, depMeta := range deps {
if i < skip || i >= max { if i < skip || i >= maxNum {
continue continue
} }

View File

@ -308,7 +308,7 @@ func ListWikiPages(ctx *context.APIContext) {
} }
skip := (page - 1) * limit skip := (page - 1) * limit
max := page * limit maxNum := page * limit
entries, err := commit.ListEntries() entries, err := commit.ListEntries()
if err != nil { if err != nil {
@ -317,7 +317,7 @@ func ListWikiPages(ctx *context.APIContext) {
} }
pages := make([]*api.WikiPageMetaData, 0, len(entries)) pages := make([]*api.WikiPageMetaData, 0, len(entries))
for i, entry := range entries { for i, entry := range entries {
if i < skip || i >= max || !entry.IsRegular() { if i < skip || i >= maxNum || !entry.IsRegular() {
continue continue
} }
c, err := wikiRepo.GetCommitByPath(entry.Name()) c, err := wikiRepo.GetCommitByPath(entry.Name())