Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,8 @@ linters:
- pkg: gitea.com/go-chi/cache
desc: do not use the go-chi cache package, use gitea's cache system
nolintlint:
# require-explanation: true
allow-unused: false
require-explanation: true
require-specific: true
gocritic:
disabled-checks:
Expand Down
2 changes: 1 addition & 1 deletion cmd/embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ func compileCollectPatterns(args []string) ([]glob.Glob, error) {
for i := range args {
if g, err := glob.Compile(args[i], '/'); err != nil {
return nil, fmt.Errorf("'%s': Invalid glob pattern: %w", args[i], err)
} else { //nolint:revive
} else { //nolint:revive // could be flattened, kept for readability
pat[i] = g
}
}
Expand Down
2 changes: 1 addition & 1 deletion contrib/backport/backport.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2023 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//nolint:forbidigo
//nolint:forbidigo // use of print functions is allowed in cli
package main

import (
Expand Down
2 changes: 1 addition & 1 deletion models/actions/task.go
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ func CreateTaskForRunner(ctx context.Context, runner *ActionRunner) (*ActionTask
return nil, false, fmt.Errorf("parse workflow of job %d: %w", job.ID, err)
} else if len(gots) != 1 {
return nil, false, fmt.Errorf("workflow of job %d: not single workflow", job.ID)
} else { //nolint:revive
} else { //nolint:revive // could be flattened, kept for readability
_, workflowJob = gots[0].Job()
}

Expand Down
2 changes: 1 addition & 1 deletion models/auth/auth_token.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (

var ErrAuthTokenNotExist = util.NewNotExistErrorf("auth token does not exist")

type AuthToken struct { //nolint:revive
type AuthToken struct { //nolint:revive // export stutter
ID string `xorm:"pk"`
TokenHash string
UserID int64 `xorm:"INDEX"`
Expand Down
4 changes: 2 additions & 2 deletions models/db/sql_postgres_with_schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (d *postgresSchemaDriver) Open(name string) (driver.Conn, error) {

// golangci lint is incorrect here - there is no benefit to using driver.ExecerContext here
// and in any case pq does not implement it
if execer, ok := conn.(driver.Execer); ok { //nolint:staticcheck
if execer, ok := conn.(driver.Execer); ok { //nolint:staticcheck // see above
_, err := execer.Exec(`SELECT set_config(
'search_path',
$1 || ',' || current_setting('search_path'),
Expand All @@ -64,7 +64,7 @@ func (d *postgresSchemaDriver) Open(name string) (driver.Conn, error) {
// driver.String.ConvertValue will never return err for string

// golangci lint is incorrect here - there is no benefit to using stmt.ExecWithContext here
_, err = stmt.Exec([]driver.Value{schemaValue}) //nolint:staticcheck
_, err = stmt.Exec([]driver.Value{schemaValue}) //nolint:staticcheck // see above
if err != nil {
_ = conn.Close()
return nil, err
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/base/tests.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright 2022 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT

//nolint:forbidigo
//nolint:forbidigo // prints are allowed in tests
package base

import (
Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v1_11/v112.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func RemoveAttachmentMissedRepo(x *xorm.Engine) error {
for i := 0; i < len(attachments); i++ {
uuid := attachments[i].UUID
if err = util.RemoveAll(filepath.Join(setting.Attachment.Storage.Path, uuid[0:1], uuid[1:2], uuid)); err != nil {
fmt.Printf("Error: %v", err) //nolint:forbidigo
fmt.Printf("Error: %v", err) //nolint:forbidigo // prints are allowed in migrations
}
}

Expand Down
2 changes: 1 addition & 1 deletion models/migrations/v1_13/v140.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ func FixLanguageStatsToSaveSize(x *xorm.Engine) error {

const (
// RepoIndexerTypeCode code indexer - 0
RepoIndexerTypeCode RepoIndexerType = iota //nolint:unused
RepoIndexerTypeCode RepoIndexerType = iota //nolint:unused // const is not used
// RepoIndexerTypeStats repository stats indexer - 1
RepoIndexerTypeStats
)
Expand Down
4 changes: 2 additions & 2 deletions models/migrations/v1_14/v157.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import (
)

func FixRepoTopics(x *xorm.Engine) error {
type Topic struct { //nolint:unused
type Topic struct { //nolint:unused // struct is not used
ID int64 `xorm:"pk autoincr"`
Name string `xorm:"UNIQUE VARCHAR(25)"`
RepoCount int
}

type RepoTopic struct { //nolint:unused
type RepoTopic struct { //nolint:unused // struct is not used
RepoID int64 `xorm:"pk"`
TopicID int64 `xorm:"pk"`
}
Expand Down
4 changes: 2 additions & 2 deletions models/migrations/v1_14/v165.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func ConvertHookTaskTypeToVarcharAndTrim(x *xorm.Engine) error {
return nil
}

type HookTask struct { //nolint:unused
type HookTask struct { //nolint:unused // struct is not used
Typ string `xorm:"VARCHAR(16) index"`
}

Expand All @@ -42,7 +42,7 @@ func ConvertHookTaskTypeToVarcharAndTrim(x *xorm.Engine) error {
return err
}

type Webhook struct { //nolint:unused
type Webhook struct { //nolint:unused // struct is not used
Type string `xorm:"VARCHAR(16) index"`
}

Expand Down
2 changes: 1 addition & 1 deletion models/user/badge.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ type Badge struct {
}

// UserBadge represents a user badge
type UserBadge struct { //nolint:revive
type UserBadge struct { //nolint:revive // export stutter
ID int64 `xorm:"pk autoincr"`
BadgeID int64
UserID int64 `xorm:"INDEX"`
Expand Down
2 changes: 1 addition & 1 deletion modules/auth/password/hash/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ func parseIntParam(value, param, algorithmName, config string, previousErr error
return parsed, previousErr // <- Keep the previous error as this function should still return an error once everything has been checked if any call failed
}

func parseUIntParam(value, param, algorithmName, config string, previousErr error) (uint64, error) { //nolint:unparam
func parseUIntParam(value, param, algorithmName, config string, previousErr error) (uint64, error) { //nolint:unparam // algorithmName is always argon2
parsed, err := strconv.ParseUint(value, 10, 64)
if err != nil {
log.Error("invalid integer for %s representation in %s hash spec %s", param, algorithmName, config)
Expand Down
2 changes: 1 addition & 1 deletion modules/cache/cache_redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"code.gitea.io/gitea/modules/graceful"
"code.gitea.io/gitea/modules/nosql"

"gitea.com/go-chi/cache" //nolint:depguard
"gitea.com/go-chi/cache" //nolint:depguard // we wrap this package here
"github.com/redis/go-redis/v9"
)

Expand Down
2 changes: 1 addition & 1 deletion modules/cache/cache_twoqueue.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (

"code.gitea.io/gitea/modules/json"

mc "gitea.com/go-chi/cache" //nolint:depguard
mc "gitea.com/go-chi/cache" //nolint:depguard // we wrap this package here
lru "github.com/hashicorp/golang-lru/v2"
)

Expand Down
2 changes: 1 addition & 1 deletion modules/cache/string_cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import (
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/util"

chi_cache "gitea.com/go-chi/cache" //nolint:depguard
chi_cache "gitea.com/go-chi/cache" //nolint:depguard // we wrap this package here
)

type GetJSONError struct {
Expand Down
3 changes: 1 addition & 2 deletions modules/graceful/manager_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,7 @@ func (g *Manager) start() {
// Make SVC process
run := svc.Run

//lint:ignore SA1019 We use IsAnInteractiveSession because IsWindowsService has a different permissions profile
isAnInteractiveSession, err := svc.IsAnInteractiveSession() //nolint:staticcheck
isAnInteractiveSession, err := svc.IsAnInteractiveSession() //nolint:staticcheck // SA1019 We use IsAnInteractiveSession because IsWindowsService has a different permissions profile
if err != nil {
log.Error("Unable to ascertain if running as an Windows Service: %v", err)
return
Expand Down
3 changes: 1 addition & 2 deletions modules/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,10 @@

package json

// Allow "encoding/json" import.
import (
"bytes"
"encoding/binary"
"encoding/json" //nolint:depguard
"encoding/json" //nolint:depguard // this package wraps it
"io"

jsoniter "github.com/json-iterator/go"
Expand Down
2 changes: 1 addition & 1 deletion modules/log/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,6 @@ type Logger interface {
LevelLogger
}

type LogStringer interface { //nolint:revive
type LogStringer interface { //nolint:revive // export stutter
LogString() string
}
2 changes: 1 addition & 1 deletion modules/markup/markdown/transform_blockquote.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (g *ASTTransformer) extractBlockquoteAttentionEmphasis(firstParagraph ast.N
if !ok {
return "", nil
}
val1 := string(node1.Text(reader.Source())) //nolint:staticcheck
val1 := string(node1.Text(reader.Source())) //nolint:staticcheck // Text is deprecated
attentionType := strings.ToLower(val1)
if g.attentionTypes.Contains(attentionType) {
return attentionType, []ast.Node{node1}
Expand Down
2 changes: 1 addition & 1 deletion modules/markup/markdown/transform_codespan.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func cssColorHandler(value string) bool {
}

func (g *ASTTransformer) transformCodeSpan(_ *markup.RenderContext, v *ast.CodeSpan, reader text.Reader) {
colorContent := v.Text(reader.Source()) //nolint:staticcheck
colorContent := v.Text(reader.Source()) //nolint:staticcheck // Text is deprecated
if cssColorHandler(string(colorContent)) {
v.AppendChild(v, NewColorPreview(colorContent))
}
Expand Down
2 changes: 1 addition & 1 deletion modules/markup/markdown/transform_heading.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ func (g *ASTTransformer) transformHeading(_ *markup.RenderContext, v *ast.Headin
v.SetAttribute(attr.Name, fmt.Appendf(nil, "%v", attr.Value))
}
}
txt := v.Text(reader.Source()) //nolint:staticcheck
txt := v.Text(reader.Source()) //nolint:staticcheck // Text is deprecated
header := Header{
Text: util.UnsafeBytesToString(txt),
Level: v.Level,
Expand Down
2 changes: 1 addition & 1 deletion modules/markup/mdstripper/mdstripper.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ func (r *stripRenderer) Render(w io.Writer, source []byte, doc ast.Node) error {
coalesce := prevSibIsText
r.processString(
w,
v.Text(source), //nolint:staticcheck
v.Text(source), //nolint:staticcheck // Text is deprecated
coalesce)
if v.SoftLineBreak() {
r.doubleSpace(w)
Expand Down
2 changes: 1 addition & 1 deletion modules/optional/serialization_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package optional_test

import (
std_json "encoding/json" //nolint:depguard
std_json "encoding/json" //nolint:depguard // for comparison with std
"testing"

"code.gitea.io/gitea/modules/json"
Expand Down
2 changes: 1 addition & 1 deletion modules/setting/config_env.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ func decodeEnvSectionKey(encoded string) (ok bool, section, key string) {

// decodeEnvironmentKey decode the environment key to section and key
// The environment key is in the form of GITEA__SECTION__KEY or GITEA__SECTION__KEY__FILE
func decodeEnvironmentKey(prefixGitea, suffixFile, envKey string) (ok bool, section, key string, useFileValue bool) { //nolint:unparam
func decodeEnvironmentKey(prefixGitea, suffixFile, envKey string) (ok bool, section, key string, useFileValue bool) { //nolint:unparam // prefixGitea is constant
if !strings.HasPrefix(envKey, prefixGitea) {
return false, "", "", false
}
Expand Down
2 changes: 1 addition & 1 deletion modules/setting/config_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import (
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/util"

"gopkg.in/ini.v1" //nolint:depguard
"gopkg.in/ini.v1" //nolint:depguard // wrapper for this package
)

type ConfigKey interface {
Expand Down
2 changes: 1 addition & 1 deletion modules/setting/security.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func loadSecurityFrom(rootCfg ConfigProvider) {
if SecretKey == "" {
// FIXME: https://github.com/go-gitea/gitea/issues/16832
// Until it supports rotating an existing secret key, we shouldn't move users off of the widely used default value
SecretKey = "!#@FDEWREWR&*(" //nolint:gosec
SecretKey = "!#@FDEWREWR&*("
}

CookieRememberName = sec.Key("COOKIE_REMEMBER_NAME").MustString("gitea_incredible")
Expand Down
6 changes: 3 additions & 3 deletions modules/setting/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ const (
targetSecIsSec // target section is from the name seciont [name]
)

func getStorageSectionByType(rootCfg ConfigProvider, typ string) (ConfigSection, targetSecType, error) { //nolint:unparam
func getStorageSectionByType(rootCfg ConfigProvider, typ string) (ConfigSection, targetSecType, error) { //nolint:unparam // targetSecType is always 0
targetSec, err := rootCfg.GetSection(storageSectionName + "." + typ)
if err != nil {
if !IsValidStorageType(StorageType(typ)) {
Expand Down Expand Up @@ -283,7 +283,7 @@ func getStorageForLocal(targetSec, overrideSec ConfigSection, tp targetSecType,
return &storage, nil
}

func getStorageForMinio(targetSec, overrideSec ConfigSection, tp targetSecType, name string) (*Storage, error) { //nolint:dupl
func getStorageForMinio(targetSec, overrideSec ConfigSection, tp targetSecType, name string) (*Storage, error) { //nolint:dupl // duplicates azure setup
var storage Storage
storage.Type = StorageType(targetSec.Key("STORAGE_TYPE").String())
if err := targetSec.MapTo(&storage.MinioConfig); err != nil {
Expand Down Expand Up @@ -312,7 +312,7 @@ func getStorageForMinio(targetSec, overrideSec ConfigSection, tp targetSecType,
return &storage, nil
}

func getStorageForAzureBlob(targetSec, overrideSec ConfigSection, tp targetSecType, name string) (*Storage, error) { //nolint:dupl
func getStorageForAzureBlob(targetSec, overrideSec ConfigSection, tp targetSecType, name string) (*Storage, error) { //nolint:dupl // duplicates minio setup
var storage Storage
storage.Type = StorageType(targetSec.Key("STORAGE_TYPE").String())
if err := targetSec.MapTo(&storage.AzureBlobConfig); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions modules/templates/htmlrenderer.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ var (

var ErrTemplateNotInitialized = errors.New("template system is not initialized, check your log for errors")

func (h *HTMLRender) HTML(w io.Writer, status int, tplName TplName, data any, ctx context.Context) error { //nolint:revive
func (h *HTMLRender) HTML(w io.Writer, status int, tplName TplName, data any, ctx context.Context) error { //nolint:revive // context isn't first parameter
name := string(tplName)
if respWriter, ok := w.(http.ResponseWriter); ok {
if respWriter.Header().Get("Content-Type") == "" {
Expand All @@ -57,7 +57,7 @@ func (h *HTMLRender) HTML(w io.Writer, status int, tplName TplName, data any, ct
return t.Execute(w, data)
}

func (h *HTMLRender) TemplateLookup(name string, ctx context.Context) (TemplateExecutor, error) { //nolint:revive
func (h *HTMLRender) TemplateLookup(name string, ctx context.Context) (TemplateExecutor, error) { //nolint:revive // context should be the first parameter
tmpls := h.templates.Load()
if tmpls == nil {
return nil, ErrTemplateNotInitialized
Expand Down
7 changes: 3 additions & 4 deletions modules/templates/scopedtmpl/scopedtmpl.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,13 +102,12 @@ func escapeTemplate(t *template.Template) error {
return nil
}

//nolint:unused
type htmlTemplate struct {
escapeErr error
escapeErr error //nolint:unused // field is not used
text *texttemplate.Template
}

//nolint:unused
//nolint:unused // tmpl, muTmpl, option and parseFuncs are unused
type textTemplateCommon struct {
tmpl map[string]*template.Template // Map from name to defined templates.
muTmpl sync.RWMutex // protects tmpl
Expand All @@ -120,7 +119,7 @@ type textTemplateCommon struct {
execFuncs map[string]reflect.Value
}

//nolint:unused
//nolint:unused // name, leftDelim and rightDelim are unused
type textTemplate struct {
name string
*parse.Tree
Expand Down
2 changes: 1 addition & 1 deletion routers/api/actions/artifacts_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func validateRunID(ctx *ArtifactContext) (*actions.ActionTask, int64, bool) {
return task, runID, true
}

func validateRunIDV4(ctx *ArtifactContext, rawRunID string) (*actions.ActionTask, int64, bool) { //nolint:unparam
func validateRunIDV4(ctx *ArtifactContext, rawRunID string) (*actions.ActionTask, int64, bool) { //nolint:unparam // ActionTask is never used
task := ctx.ActionTask
runID, err := strconv.ParseInt(rawRunID, 10, 64)
if err != nil || task.Job.RunID != runID {
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/container/blob.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import (

// saveAsPackageBlob creates a package blob from an upload
// The uploaded blob gets stored in a special upload version to link them to the package/image
func saveAsPackageBlob(ctx context.Context, hsr packages_module.HashedSizeReader, pci *packages_service.PackageCreationInfo) (*packages_model.PackageBlob, error) { //nolint:unparam
func saveAsPackageBlob(ctx context.Context, hsr packages_module.HashedSizeReader, pci *packages_service.PackageCreationInfo) (*packages_model.PackageBlob, error) { //nolint:unparam // PackageBlob is never used
pb := packages_service.NewPackageBlob(hsr)

exists := false
Expand Down
2 changes: 1 addition & 1 deletion routers/api/packages/nuget/nuget.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func apiError(ctx *context.Context, status int, obj any) {
})
}

func xmlResponse(ctx *context.Context, status int, obj any) { //nolint:unparam
func xmlResponse(ctx *context.Context, status int, obj any) { //nolint:unparam // status is always StatusOK
ctx.Resp.Header().Set("Content-Type", "application/atom+xml; charset=utf-8")
ctx.Resp.WriteHeader(status)
if _, err := ctx.Resp.Write([]byte(xml.Header)); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions routers/api/v1/misc/markup.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func Markup(ctx *context.APIContext) {
return
}

mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck
mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck // form.Wiki is deprecated
common.RenderMarkup(ctx.Base, ctx.Repo, mode, form.Text, form.Context, form.FilePath)
}

Expand Down Expand Up @@ -73,7 +73,7 @@ func Markdown(ctx *context.APIContext) {
return
}

mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck
mode := util.Iif(form.Wiki, "wiki", form.Mode) //nolint:staticcheck // form.Wiki is deprecated
common.RenderMarkup(ctx.Base, ctx.Repo, mode, form.Text, form.Context, "")
}

Expand Down
2 changes: 1 addition & 1 deletion routers/web/admin/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ func ChangeConfig(ctx *context.Context) {
value := ctx.FormString("value")
cfg := setting.Config()

marshalBool := func(v string) (string, error) { //nolint:unparam
marshalBool := func(v string) (string, error) { //nolint:unparam // error is always nil
if b, _ := strconv.ParseBool(v); b {
return "true", nil
}
Expand Down
Loading