Upgrade golangci-lint to v1.64.5 (#33654)

Use `usetesting` instead of deprecated `tenv`.
1. Follow up #33648
2. Make lint pass and add some comments
This commit is contained in:
wxiaoguang 2025-02-21 00:05:40 +08:00 committed by GitHub
parent cd225d7034
commit 3ee5ee2029
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 17 additions and 20 deletions

View file

@ -19,12 +19,12 @@ linters:
- revive - revive
- staticcheck - staticcheck
- stylecheck - stylecheck
- tenv
- testifylint - testifylint
- typecheck - typecheck
- unconvert - unconvert
- unused - unused
- unparam - unparam
- usetesting
- wastedassign - wastedassign
run: run:
@ -102,6 +102,8 @@ linters-settings:
desc: do not use the ini package, use gitea's config system instead desc: do not use the ini package, use gitea's config system instead
- pkg: gitea.com/go-chi/cache - pkg: gitea.com/go-chi/cache
desc: do not use the go-chi cache package, use gitea's cache system desc: do not use the go-chi cache package, use gitea's cache system
usetesting:
os-temp-dir: true
issues: issues:
max-issues-per-linter: 0 max-issues-per-linter: 0

View file

@ -28,7 +28,7 @@ XGO_VERSION := go-1.24.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/v3/cmd/editorconfig-checker@v3.1.2 EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.1.2
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.63.4 GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.5
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.12 GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.12
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.6.0 MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.6.0
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
@ -255,7 +255,7 @@ fmt-check: fmt
@diff=$$(git diff --color=always $(GO_SOURCES) templates $(WEB_DIRS)); \ @diff=$$(git diff --color=always $(GO_SOURCES) templates $(WEB_DIRS)); \
if [ -n "$$diff" ]; then \ if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \ echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \ printf "%s" "$${diff}"; \
exit 1; \ exit 1; \
fi fi
@ -281,7 +281,7 @@ swagger-check: generate-swagger
@diff=$$(git diff --color=always '$(SWAGGER_SPEC)'); \ @diff=$$(git diff --color=always '$(SWAGGER_SPEC)'); \
if [ -n "$$diff" ]; then \ if [ -n "$$diff" ]; then \
echo "Please run 'make generate-swagger' and commit the result:"; \ echo "Please run 'make generate-swagger' and commit the result:"; \
echo "$${diff}"; \ printf "%s" "$${diff}"; \
exit 1; \ exit 1; \
fi fi
@ -426,7 +426,7 @@ test-check:
@diff=$$(git status -s); \ @diff=$$(git status -s); \
if [ -n "$$diff" ]; then \ if [ -n "$$diff" ]; then \
echo "make test-backend has changed files in the source tree:"; \ echo "make test-backend has changed files in the source tree:"; \
echo "$${diff}"; \ printf "%s" "$${diff}"; \
echo "You should change the tests to create these files in a temporary directory."; \ echo "You should change the tests to create these files in a temporary directory."; \
echo "Do not simply add these files to .gitignore"; \ echo "Do not simply add these files to .gitignore"; \
exit 1; \ exit 1; \
@ -879,7 +879,7 @@ svg-check: svg
@diff=$$(git diff --color=always --cached $(SVG_DEST_DIR)); \ @diff=$$(git diff --color=always --cached $(SVG_DEST_DIR)); \
if [ -n "$$diff" ]; then \ if [ -n "$$diff" ]; then \
echo "Please run 'make svg' and 'git add $(SVG_DEST_DIR)' and commit the result:"; \ echo "Please run 'make svg' and 'git add $(SVG_DEST_DIR)' and commit the result:"; \
echo "$${diff}"; \ printf "%s" "$${diff}"; \
exit 1; \ exit 1; \
fi fi
@ -890,7 +890,7 @@ lockfile-check:
if [ -n "$$diff" ]; then \ if [ -n "$$diff" ]; then \
echo "package-lock.json is inconsistent with package.json"; \ echo "package-lock.json is inconsistent with package.json"; \
echo "Please run 'npm install --package-lock-only' and commit the result:"; \ echo "Please run 'npm install --package-lock-only' and commit the result:"; \
echo "$${diff}"; \ printf "%s" "$${diff}"; \
exit 1; \ exit 1; \
fi fi

View file

@ -16,6 +16,7 @@ import (
) )
// AesEncrypt encrypts text and given key with AES. // AesEncrypt encrypts text and given key with AES.
// It is only internally used at the moment to use "SECRET_KEY" for some database values.
func AesEncrypt(key, text []byte) ([]byte, error) { func AesEncrypt(key, text []byte) ([]byte, error) {
block, err := aes.NewCipher(key) block, err := aes.NewCipher(key)
if err != nil { if err != nil {
@ -27,12 +28,13 @@ func AesEncrypt(key, text []byte) ([]byte, error) {
if _, err = io.ReadFull(rand.Reader, iv); err != nil { if _, err = io.ReadFull(rand.Reader, iv); err != nil {
return nil, fmt.Errorf("AesEncrypt unable to read IV: %w", err) return nil, fmt.Errorf("AesEncrypt unable to read IV: %w", err)
} }
cfb := cipher.NewCFBEncrypter(block, iv) cfb := cipher.NewCFBEncrypter(block, iv) //nolint:staticcheck // need to migrate and refactor to a new approach
cfb.XORKeyStream(ciphertext[aes.BlockSize:], []byte(b)) cfb.XORKeyStream(ciphertext[aes.BlockSize:], []byte(b))
return ciphertext, nil return ciphertext, nil
} }
// AesDecrypt decrypts text and given key with AES. // AesDecrypt decrypts text and given key with AES.
// It is only internally used at the moment to use "SECRET_KEY" for some database values.
func AesDecrypt(key, text []byte) ([]byte, error) { func AesDecrypt(key, text []byte) ([]byte, error) {
block, err := aes.NewCipher(key) block, err := aes.NewCipher(key)
if err != nil { if err != nil {
@ -43,7 +45,7 @@ func AesDecrypt(key, text []byte) ([]byte, error) {
} }
iv := text[:aes.BlockSize] iv := text[:aes.BlockSize]
text = text[aes.BlockSize:] text = text[aes.BlockSize:]
cfb := cipher.NewCFBDecrypter(block, iv) cfb := cipher.NewCFBDecrypter(block, iv) //nolint:staticcheck // need to migrate and refactor to a new approach
cfb.XORKeyStream(text, text) cfb.XORKeyStream(text, text)
data, err := base64.StdEncoding.DecodeString(string(text)) data, err := base64.StdEncoding.DecodeString(string(text))
if err != nil { if err != nil {

View file

@ -4,8 +4,6 @@
package storage package storage
import ( import (
"os"
"path/filepath"
"testing" "testing"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
@ -56,6 +54,5 @@ func TestBuildLocalPath(t *testing.T) {
} }
func TestLocalStorageIterator(t *testing.T) { func TestLocalStorageIterator(t *testing.T) {
dir := filepath.Join(os.TempDir(), "TestLocalStorageIteratorTestDir") testStorageIterator(t, setting.LocalStorageType, &setting.Storage{Path: t.TempDir()})
testStorageIterator(t, setting.LocalStorageType, &setting.Storage{Path: dir})
} }

View file

@ -17,7 +17,7 @@ import (
func TestCopyFile(t *testing.T) { func TestCopyFile(t *testing.T) {
testContent := []byte("hello") testContent := []byte("hello")
tmpDir := os.TempDir() tmpDir := t.TempDir()
now := time.Now() now := time.Now()
srcFile := fmt.Sprintf("%s/copy-test-%d-src.txt", tmpDir, now.UnixMicro()) srcFile := fmt.Sprintf("%s/copy-test-%d-src.txt", tmpDir, now.UnixMicro())
dstFile := fmt.Sprintf("%s/copy-test-%d-dst.txt", tmpDir, now.UnixMicro()) dstFile := fmt.Sprintf("%s/copy-test-%d-dst.txt", tmpDir, now.UnixMicro())

View file

@ -20,7 +20,6 @@ import (
base "code.gitea.io/gitea/modules/migration" base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/setting" "code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs" "code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/migrations" "code.gitea.io/gitea/services/migrations"
"github.com/stretchr/testify/assert" "github.com/stretchr/testify/assert"
@ -43,10 +42,7 @@ func TestDumpRestore(t *testing.T) {
reponame := "repo1" reponame := "repo1"
basePath, err := os.MkdirTemp("", reponame) basePath := t.TempDir()
assert.NoError(t, err)
defer util.RemoveAll(basePath)
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame}) repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID}) repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
session := loginUser(t, repoOwner.Name) session := loginUser(t, repoOwner.Name)
@ -68,7 +64,7 @@ func TestDumpRestore(t *testing.T) {
CloneAddr: repo.CloneLinkGeneral(t.Context()).HTTPS, CloneAddr: repo.CloneLinkGeneral(t.Context()).HTTPS,
RepoName: reponame, RepoName: reponame,
} }
err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts) err := migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
assert.NoError(t, err) assert.NoError(t, err)
// //