2
0

chore(ui): update golangci-lint config and cleanup package docs

Updates golangci-lint configuration to v2 format with Go 1.23, streamlines linter settings by removing deprecated options and unnecessary exclusions. Adds package documentation and renames CleanupResult to Result for consistency. Marks unused context parameter with underscore.
This commit is contained in:
2026-01-19 01:03:07 -05:00
parent 4d6900b7a3
commit 22f1ea6e76
2 changed files with 32 additions and 101 deletions

View File

@@ -1,53 +1,42 @@
version: "2"
linters: linters:
default: none
enable: enable:
- gosimple
- typecheck
- govet - govet
- errcheck - errcheck
- staticcheck - staticcheck
- unused - unused
- dupl - dupl
#- gocyclo # The cyclomatic complexety of a lot of functions is too high, we should refactor those another time.
- gofmt
- misspell - misspell
- gocritic - gocritic
- bidichk - bidichk
- ineffassign - ineffassign
- revive - revive
- gofumpt
- depguard
- nakedret - nakedret
- unconvert - unconvert
- wastedassign - wastedassign
- nolintlint - nolintlint
- stylecheck
enable-all: false formatters:
disable-all: true enable:
fast: false - gofmt
- gofumpt
run: run:
go: 1.18 go: "1.23"
timeout: 10m timeout: 10m
skip-dirs:
- node_modules
- public
- web_src
linters-settings: linters-settings:
stylecheck:
checks: ["all", "-ST1005", "-ST1003"]
nakedret: nakedret:
max-func-lines: 0 max-func-lines: 0
gocritic: gocritic:
disabled-checks: disabled-checks:
- ifElseChain - ifElseChain
- singleCaseSwitch # Every time this occurred in the code, there was no other way. - singleCaseSwitch
revive: revive:
ignore-generated-header: false
severity: warning severity: warning
confidence: 0.8 confidence: 0.8
errorCode: 1
warningCode: 1
rules: rules:
- name: blank-imports - name: blank-imports
- name: context-as-argument - name: context-as-argument
@@ -72,94 +61,25 @@ linters-settings:
- name: modifies-value-receiver - name: modifies-value-receiver
gofumpt: gofumpt:
extra-rules: true extra-rules: true
lang-version: "1.18"
depguard:
# TODO: use depguard to replace import checks in gitea-vet
list-type: denylist
# Check the list against standard lib.
include-go-root: true
packages-with-error-message:
- github.com/unknwon/com: "use gitea's util and replacements"
issues: issues:
exclude-rules: exclude-rules:
# Exclude some linters from running on tests files.
- path: _test\.go - path: _test\.go
linters: linters:
- gocyclo
- errcheck - errcheck
- dupl - dupl
- gosec
- unparam
- staticcheck
- path: models/migrations/v
linters:
- gocyclo
- errcheck
- dupl
- gosec
- linters: - linters:
- dupl - dupl
text: "webhook" text: "webhook"
- linters: - linters:
- gocritic - gocritic
text: "`ID' should not be capitalized" text: "`ID' should not be capitalized"
- path: modules/templates/helper.go
linters:
- gocritic
- linters:
- unused
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
- linters: - linters:
- misspell - misspell
text: '`Unknwon` is a misspelling of `Unknown`' text: '`Unknwon` is a misspelling of `Unknown`'
- path: models/update.go
linters:
- unused
- path: cmd/dump.go
linters:
- dupl
- text: "commentFormatting: put a space between `//` and comment text" - text: "commentFormatting: put a space between `//` and comment text"
linters: linters:
- gocritic - gocritic
- text: "exitAfterDefer:" - text: "exitAfterDefer:"
linters: linters:
- gocritic - gocritic
- path: modules/graceful/manager_windows.go
linters:
- staticcheck
text: "svc.IsAnInteractiveSession is deprecated: Use IsWindowsService instead."
- path: models/user/openid.go
linters:
- golint

View File

@@ -1,6 +1,7 @@
// Copyright 2026 MarketAlly. All rights reserved. // Copyright 2026 MarketAlly. All rights reserved.
// SPDX-License-Identifier: MIT // SPDX-License-Identifier: MIT
// Package cleanup provides disk cleanup utilities for CI runners.
package cleanup package cleanup
import ( import (
@@ -15,18 +16,18 @@ import (
log "github.com/sirupsen/logrus" log "github.com/sirupsen/logrus"
) )
// CleanupResult contains the results of a cleanup operation // Result contains the results of a cleanup operation.
type CleanupResult struct { type Result struct {
BytesFreed int64 BytesFreed int64
FilesDeleted int FilesDeleted int
Errors []error Errors []error
Duration time.Duration Duration time.Duration
} }
// RunCleanup performs cleanup operations to free disk space // RunCleanup performs cleanup operations to free disk space.
func RunCleanup(ctx context.Context, cfg *config.Config) (*CleanupResult, error) { func RunCleanup(_ context.Context, cfg *config.Config) (*Result, error) {
start := time.Now() start := time.Now()
result := &CleanupResult{} result := &Result{}
log.Info("Starting runner cleanup...") log.Info("Starting runner cleanup...")
@@ -207,8 +208,15 @@ func cleanTempDir(maxAge time.Duration) (int64, int, error) {
return 0, 0, err return 0, 0, err
} }
// Only clean files/dirs that look like runner/act artifacts // Only clean files/dirs that look like runner/act artifacts or build tool temp files
runnerPatterns := []string{"act-", "runner-", "gitea-", "workflow-", "go-build", "go-link", "node-compile-cache", "npm-", "yarn-", "pnpm-"} runnerPatterns := []string{
"act-", "runner-", "gitea-", "workflow-",
"go-build", "go-link",
"node-compile-cache", "npm-", "yarn-", "yarn--", "pnpm-",
"ts-node-", "tsx-", "jiti", "v8-compile-cache",
"text-diff-expansion-test", "DiagOutputDir",
"dugite-native-", "reorderCommitMessage-", "squashCommitMessage-",
}
for _, entry := range entries { for _, entry := range entries {
name := entry.Name() name := entry.Name()
isRunner := false isRunner := false
@@ -246,10 +254,10 @@ func cleanTempDir(maxAge time.Duration) (int64, int, error) {
return bytesFreed, filesDeleted, nil return bytesFreed, filesDeleted, nil
} }
// dirSize calculates the total size of a directory // dirSize calculates the total size of a directory.
func dirSize(path string) int64 { func dirSize(path string) int64 {
var size int64 var size int64
filepath.Walk(path, func(_ string, info os.FileInfo, err error) error { _ = filepath.Walk(path, func(_ string, info os.FileInfo, err error) error {
if err != nil { if err != nil {
return nil return nil
} }
@@ -308,6 +316,9 @@ func cleanBuildCaches(maxAge time.Duration) (int64, int, error) {
{filepath.Join(os.Getenv("LOCALAPPDATA"), "Yarn", "Cache"), "Yarn cache (Windows)", 0}, {filepath.Join(os.Getenv("LOCALAPPDATA"), "Yarn", "Cache"), "Yarn cache (Windows)", 0},
{filepath.Join(os.Getenv("LOCALAPPDATA"), "NuGet", "v3-cache"), "NuGet cache (Windows)", 0}, {filepath.Join(os.Getenv("LOCALAPPDATA"), "NuGet", "v3-cache"), "NuGet cache (Windows)", 0},
{filepath.Join(os.Getenv("LOCALAPPDATA"), "pip", "Cache"), "pip cache (Windows)", 0}, {filepath.Join(os.Getenv("LOCALAPPDATA"), "pip", "Cache"), "pip cache (Windows)", 0},
// Windows custom paths used by some CI setups
{"C:\\L\\Yarn", "Yarn global cache (Windows)", 0},
{filepath.Join(os.TempDir(), "chocolatey"), "Chocolatey temp cache", 0},
} }
for _, cache := range cacheDirs { for _, cache := range cacheDirs {
@@ -349,13 +360,13 @@ func cleanBuildCaches(maxAge time.Duration) (int64, int, error) {
} }
// Also remove empty directories // Also remove empty directories
filepath.Walk(cache.path, func(path string, info os.FileInfo, err error) error { _ = filepath.Walk(cache.path, func(path string, info os.FileInfo, err error) error {
if err != nil || !info.IsDir() || path == cache.path { if err != nil || !info.IsDir() || path == cache.path {
return nil return nil
} }
entries, _ := os.ReadDir(path) entries, _ := os.ReadDir(path)
if len(entries) == 0 { if len(entries) == 0 {
os.Remove(path) _ = os.Remove(path)
} }
return nil return nil
}) })