From 938b59199480d1b3730388982eb87d592e976849 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 20 Apr 2023 04:08:01 +0200 Subject: [PATCH] Remove most path-based golangci exclusions (#24214) They are non-obvious and do not survive refactor. Will replace with `//nolint` comments after CI results are in. --- .golangci.yml | 51 ----------------------------- models/migrations/v1_13/v140.go | 8 ++--- models/migrations/v1_14/v157.go | 4 +-- models/migrations/v1_14/v165.go | 4 +-- models/user/badge.go | 2 +- modules/graceful/manager_windows.go | 2 +- modules/log/event.go | 4 +-- modules/log/file.go | 4 +-- modules/log/log.go | 4 +-- modules/log/logger.go | 20 +++++------ modules/log/multichannel.go | 2 +- modules/log/writer.go | 4 +-- 12 files changed, 29 insertions(+), 80 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 263149f773e..ebb90af9d50 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -111,67 +111,16 @@ issues: - linters: - gocritic text: "`ID' should not be capitalized" - - path: modules/templates/helper.go - linters: - - gocritic - linters: - unused - deadcode text: "swagger" - - path: contrib/pr/checkout.go - linters: - - errcheck - - path: models/issue.go - linters: - - errcheck - - path: models/migrations/ - linters: - - errcheck - - path: modules/log/ - linters: - - errcheck - - path: routers/api/v1/repo/issue_subscription.go - linters: - - dupl - - path: routers/repo/view.go - linters: - - dupl - - path: models/migrations/ - linters: - - unused - linters: - staticcheck text: "argument x is overwritten before first use" - - path: modules/httplib/httplib.go - linters: - - staticcheck - # Enabling this would require refactoring the methods and how they are called. - - path: models/issue_comment_list.go - linters: - - dupl - - path: models/update.go - linters: - - unused - - path: cmd/dump.go - linters: - - dupl - - path: services/webhook/webhook.go - linters: - - structcheck - text: "commentFormatting: put a space between `//` and comment text" linters: - gocritic - text: "exitAfterDefer:" linters: - gocritic - - path: modules/graceful/manager_windows.go - linters: - - staticcheck - text: "svc.IsAnInteractiveSession is deprecated: Use IsWindowsService instead." - - path: models/user/openid.go - linters: - - golint - - path: models/user/badge.go - linters: - - revive - text: "exported: type name will be used as user.UserBadge by other packages, and that stutters; consider calling this Badge" diff --git a/models/migrations/v1_13/v140.go b/models/migrations/v1_13/v140.go index 4d87b955fdf..30c1bc07d22 100644 --- a/models/migrations/v1_13/v140.go +++ b/models/migrations/v1_13/v140.go @@ -22,10 +22,10 @@ func FixLanguageStatsToSaveSize(x *xorm.Engine) error { type RepoIndexerType int const ( - // RepoIndexerTypeCode code indexer - RepoIndexerTypeCode RepoIndexerType = iota // 0 - // RepoIndexerTypeStats repository stats indexer - RepoIndexerTypeStats // 1 + // RepoIndexerTypeCode code indexer - 0 + RepoIndexerTypeCode RepoIndexerType = iota //nolint:unused + // RepoIndexerTypeStats repository stats indexer - 1 + RepoIndexerTypeStats ) // RepoIndexerStatus see models/repo_indexer.go diff --git a/models/migrations/v1_14/v157.go b/models/migrations/v1_14/v157.go index b9d8225af8a..7187278d294 100644 --- a/models/migrations/v1_14/v157.go +++ b/models/migrations/v1_14/v157.go @@ -8,13 +8,13 @@ import ( ) func FixRepoTopics(x *xorm.Engine) error { - type Topic struct { + type Topic struct { //nolint:unused ID int64 `xorm:"pk autoincr"` Name string `xorm:"UNIQUE VARCHAR(25)"` RepoCount int } - type RepoTopic struct { + type RepoTopic struct { //nolint:unused RepoID int64 `xorm:"pk"` TopicID int64 `xorm:"pk"` } diff --git a/models/migrations/v1_14/v165.go b/models/migrations/v1_14/v165.go index a784832e1c3..926350cdf78 100644 --- a/models/migrations/v1_14/v165.go +++ b/models/migrations/v1_14/v165.go @@ -16,7 +16,7 @@ func ConvertHookTaskTypeToVarcharAndTrim(x *xorm.Engine) error { return nil } - type HookTask struct { + type HookTask struct { //nolint:unused Typ string `xorm:"VARCHAR(16) index"` } @@ -42,7 +42,7 @@ func ConvertHookTaskTypeToVarcharAndTrim(x *xorm.Engine) error { return err } - type Webhook struct { + type Webhook struct { //nolint:unused Type string `xorm:"VARCHAR(16) index"` } diff --git a/models/user/badge.go b/models/user/badge.go index 948b0b10656..ee52b44cf51 100644 --- a/models/user/badge.go +++ b/models/user/badge.go @@ -17,7 +17,7 @@ type Badge struct { } // UserBadge represents a user badge -type UserBadge struct { +type UserBadge struct { //nolint:revive ID int64 `xorm:"pk autoincr"` BadgeID int64 UserID int64 `xorm:"INDEX"` diff --git a/modules/graceful/manager_windows.go b/modules/graceful/manager_windows.go index 212ddf437cc..f3606084aa0 100644 --- a/modules/graceful/manager_windows.go +++ b/modules/graceful/manager_windows.go @@ -96,7 +96,7 @@ func (g *Manager) start() { run := svc.Run //lint:ignore SA1019 We use IsAnInteractiveSession because IsWindowsService has a different permissions profile - isAnInteractiveSession, err := svc.IsAnInteractiveSession() + isAnInteractiveSession, err := svc.IsAnInteractiveSession() //nolint:staticcheck if err != nil { log.Error("Unable to ascertain if running as an Windows Service: %v", err) return diff --git a/modules/log/event.go b/modules/log/event.go index 4466f7ff34f..d23e56807b4 100644 --- a/modules/log/event.go +++ b/modules/log/event.go @@ -82,7 +82,7 @@ func (l *ChannelledLog) Start() { l.closeLogger() return } - l.loggerProvider.LogEvent(event) + l.loggerProvider.LogEvent(event) //nolint:errcheck case _, ok := <-l.flush: if !ok { l.closeLogger() @@ -119,7 +119,7 @@ func (l *ChannelledLog) emptyQueue() bool { if !ok { return false } - l.loggerProvider.LogEvent(event) + l.loggerProvider.LogEvent(event) //nolint:errcheck default: return true } diff --git a/modules/log/file.go b/modules/log/file.go index 16fe26f84d2..55147ffac82 100644 --- a/modules/log/file.go +++ b/modules/log/file.go @@ -181,7 +181,7 @@ func (log *FileLogger) DoRotate() error { } if log.Compress { - go compressOldLogFile(fname, log.CompressionLevel) + go compressOldLogFile(fname, log.CompressionLevel) //nolint:errcheck } // re-start logger @@ -216,7 +216,7 @@ func compressOldLogFile(fname string, compressionLevel int) error { if err != nil { zw.Close() fw.Close() - util.Remove(fname + ".gz") + util.Remove(fname + ".gz") //nolint:errcheck return err } reader.Close() diff --git a/modules/log/log.go b/modules/log/log.go index 9057cda37e6..eee2728bf68 100644 --- a/modules/log/log.go +++ b/modules/log/log.go @@ -245,7 +245,7 @@ func Close() { func Log(skip int, level Level, format string, v ...interface{}) { l, ok := NamedLoggers.Load(DEFAULT) if ok { - l.Log(skip+1, level, format, v...) + l.Log(skip+1, level, format, v...) //nolint:errcheck } } @@ -273,7 +273,7 @@ func (l *LoggerAsWriter) Write(p []byte) (int, error) { for _, logger := range l.ourLoggers { // Skip = 3 because this presumes that we have been called by log.Println() // If the caller has used log.Output or the like this will be wrong - logger.Log(3, l.level, string(p)) + logger.Log(3, l.level, string(p)) //nolint:errcheck } return len(p), nil } diff --git a/modules/log/logger.go b/modules/log/logger.go index 56e39c392e3..71949e29b81 100644 --- a/modules/log/logger.go +++ b/modules/log/logger.go @@ -53,7 +53,7 @@ type LevelLoggerLogger struct { // Trace records trace log func (l *LevelLoggerLogger) Trace(format string, v ...interface{}) { - l.Log(1, TRACE, format, v...) + l.Log(1, TRACE, format, v...) //nolint:errcheck } // IsTrace returns true if the logger is TRACE @@ -63,7 +63,7 @@ func (l *LevelLoggerLogger) IsTrace() bool { // Debug records debug log func (l *LevelLoggerLogger) Debug(format string, v ...interface{}) { - l.Log(1, DEBUG, format, v...) + l.Log(1, DEBUG, format, v...) //nolint:errcheck } // IsDebug returns true if the logger is DEBUG @@ -73,7 +73,7 @@ func (l *LevelLoggerLogger) IsDebug() bool { // Info records information log func (l *LevelLoggerLogger) Info(format string, v ...interface{}) { - l.Log(1, INFO, format, v...) + l.Log(1, INFO, format, v...) //nolint:errcheck } // IsInfo returns true if the logger is INFO @@ -83,7 +83,7 @@ func (l *LevelLoggerLogger) IsInfo() bool { // Warn records warning log func (l *LevelLoggerLogger) Warn(format string, v ...interface{}) { - l.Log(1, WARN, format, v...) + l.Log(1, WARN, format, v...) //nolint:errcheck } // IsWarn returns true if the logger is WARN @@ -93,12 +93,12 @@ func (l *LevelLoggerLogger) IsWarn() bool { // Error records error log func (l *LevelLoggerLogger) Error(format string, v ...interface{}) { - l.Log(1, ERROR, format, v...) + l.Log(1, ERROR, format, v...) //nolint:errcheck } // ErrorWithSkip records error log from "skip" calls back from this function func (l *LevelLoggerLogger) ErrorWithSkip(skip int, format string, v ...interface{}) { - l.Log(skip+1, ERROR, format, v...) + l.Log(skip+1, ERROR, format, v...) //nolint:errcheck } // IsError returns true if the logger is ERROR @@ -108,12 +108,12 @@ func (l *LevelLoggerLogger) IsError() bool { // Critical records critical log func (l *LevelLoggerLogger) Critical(format string, v ...interface{}) { - l.Log(1, CRITICAL, format, v...) + l.Log(1, CRITICAL, format, v...) //nolint:errcheck } // CriticalWithSkip records critical log from "skip" calls back from this function func (l *LevelLoggerLogger) CriticalWithSkip(skip int, format string, v ...interface{}) { - l.Log(skip+1, CRITICAL, format, v...) + l.Log(skip+1, CRITICAL, format, v...) //nolint:errcheck } // IsCritical returns true if the logger is CRITICAL @@ -123,14 +123,14 @@ func (l *LevelLoggerLogger) IsCritical() bool { // Fatal records fatal log and exit the process func (l *LevelLoggerLogger) Fatal(format string, v ...interface{}) { - l.Log(1, FATAL, format, v...) + l.Log(1, FATAL, format, v...) //nolint:errcheck l.Close() os.Exit(1) } // FatalWithSkip records fatal log from "skip" calls back from this function and exits the process func (l *LevelLoggerLogger) FatalWithSkip(skip int, format string, v ...interface{}) { - l.Log(skip+1, FATAL, format, v...) + l.Log(skip+1, FATAL, format, v...) //nolint:errcheck l.Close() os.Exit(1) } diff --git a/modules/log/multichannel.go b/modules/log/multichannel.go index 8ccb08179ca..6b8a9b82464 100644 --- a/modules/log/multichannel.go +++ b/modules/log/multichannel.go @@ -99,6 +99,6 @@ func (l *MultiChannelledLogger) SendLog(level Level, caller, filename string, li time: time.Now(), stacktrace: stack, } - l.LogEvent(event) + l.LogEvent(event) //nolint:errcheck return nil } diff --git a/modules/log/writer.go b/modules/log/writer.go index ac4b3c8c4e1..61f1d866ee5 100644 --- a/modules/log/writer.go +++ b/modules/log/writer.go @@ -202,7 +202,7 @@ func (logger *WriterLogger) createMsg(buf *[]byte, event *Event) { (&protectedANSIWriter{ w: &baw, mode: pawMode, - }).Write(msg) + }).Write(msg) //nolint:errcheck *buf = baw if event.stacktrace != "" && logger.StacktraceLevel <= event.level { @@ -249,7 +249,7 @@ func (logger *WriterLogger) Match(event *Event) bool { (&protectedANSIWriter{ w: &baw, mode: removeColor, - }).Write([]byte(event.msg)) + }).Write([]byte(event.msg)) //nolint:errcheck msg = baw return logger.regexp.Match(msg) }