Skip to content

Commit

Permalink
Upgrade golangci-lint to v1.64.5 (#33654)
Browse files Browse the repository at this point in the history
Use `usetesting` instead of deprecated `tenv`.
1. Follow up #33648
2. Make lint pass and add some comments
  • Loading branch information
wxiaoguang authored Feb 20, 2025
1 parent cd225d7 commit 3ee5ee2
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 20 deletions.
4 changes: 3 additions & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ linters:
- revive
- staticcheck
- stylecheck
- tenv
- testifylint
- typecheck
- unconvert
- unused
- unparam
- usetesting
- wastedassign

run:
Expand Down Expand Up @@ -102,6 +102,8 @@ linters-settings:
desc: do not use the ini package, use gitea's config system instead
- pkg: gitea.com/go-chi/cache
desc: do not use the go-chi cache package, use gitea's cache system
usetesting:
os-temp-dir: true

issues:
max-issues-per-linter: 0
Expand Down
12 changes: 6 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ XGO_VERSION := go-1.24.x
AIR_PACKAGE ?= github.com/air-verse/air@v1
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/editorconfig-checker@v3.1.2
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
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/misspell@v0.6.0
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.31.0
Expand Down Expand Up @@ -255,7 +255,7 @@ fmt-check: fmt
@diff=$$(git diff --color=always $(GO_SOURCES) templates $(WEB_DIRS)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make fmt' and commit the result:"; \
echo "$${diff}"; \
printf "%s" "$${diff}"; \
exit 1; \
fi

Expand All @@ -281,7 +281,7 @@ swagger-check: generate-swagger
@diff=$$(git diff --color=always '$(SWAGGER_SPEC)'); \
if [ -n "$$diff" ]; then \
echo "Please run 'make generate-swagger' and commit the result:"; \
echo "$${diff}"; \
printf "%s" "$${diff}"; \
exit 1; \
fi

Expand Down Expand Up @@ -426,7 +426,7 @@ test-check:
@diff=$$(git status -s); \
if [ -n "$$diff" ]; then \
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 "Do not simply add these files to .gitignore"; \
exit 1; \
Expand Down Expand Up @@ -879,7 +879,7 @@ svg-check: svg
@diff=$$(git diff --color=always --cached $(SVG_DEST_DIR)); \
if [ -n "$$diff" ]; then \
echo "Please run 'make svg' and 'git add $(SVG_DEST_DIR)' and commit the result:"; \
echo "$${diff}"; \
printf "%s" "$${diff}"; \
exit 1; \
fi

Expand All @@ -890,7 +890,7 @@ lockfile-check:
if [ -n "$$diff" ]; then \
echo "package-lock.json is inconsistent with package.json"; \
echo "Please run 'npm install --package-lock-only' and commit the result:"; \
echo "$${diff}"; \
printf "%s" "$${diff}"; \
exit 1; \
fi

Expand Down
6 changes: 4 additions & 2 deletions modules/secret/secret.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import (
)

// 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) {
block, err := aes.NewCipher(key)
if err != nil {
Expand All @@ -27,12 +28,13 @@ func AesEncrypt(key, text []byte) ([]byte, error) {
if _, err = io.ReadFull(rand.Reader, iv); err != nil {
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))
return ciphertext, nil
}

// 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) {
block, err := aes.NewCipher(key)
if err != nil {
Expand All @@ -43,7 +45,7 @@ func AesDecrypt(key, text []byte) ([]byte, error) {
}
iv := 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)
data, err := base64.StdEncoding.DecodeString(string(text))
if err != nil {
Expand Down
5 changes: 1 addition & 4 deletions modules/storage/local_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
package storage

import (
"os"
"path/filepath"
"testing"

"code.gitea.io/gitea/modules/setting"
Expand Down Expand Up @@ -56,6 +54,5 @@ func TestBuildLocalPath(t *testing.T) {
}

func TestLocalStorageIterator(t *testing.T) {
dir := filepath.Join(os.TempDir(), "TestLocalStorageIteratorTestDir")
testStorageIterator(t, setting.LocalStorageType, &setting.Storage{Path: dir})
testStorageIterator(t, setting.LocalStorageType, &setting.Storage{Path: t.TempDir()})
}
2 changes: 1 addition & 1 deletion modules/util/legacy_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
func TestCopyFile(t *testing.T) {
testContent := []byte("hello")

tmpDir := os.TempDir()
tmpDir := t.TempDir()
now := time.Now()
srcFile := fmt.Sprintf("%s/copy-test-%d-src.txt", tmpDir, now.UnixMicro())
dstFile := fmt.Sprintf("%s/copy-test-%d-dst.txt", tmpDir, now.UnixMicro())
Expand Down
8 changes: 2 additions & 6 deletions tests/integration/dump_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import (
base "code.gitea.io/gitea/modules/migration"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/structs"
"code.gitea.io/gitea/modules/util"
"code.gitea.io/gitea/services/migrations"

"github.com/stretchr/testify/assert"
Expand All @@ -43,10 +42,7 @@ func TestDumpRestore(t *testing.T) {

reponame := "repo1"

basePath, err := os.MkdirTemp("", reponame)
assert.NoError(t, err)
defer util.RemoveAll(basePath)

basePath := t.TempDir()
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame})
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
session := loginUser(t, repoOwner.Name)
Expand All @@ -68,7 +64,7 @@ func TestDumpRestore(t *testing.T) {
CloneAddr: repo.CloneLinkGeneral(t.Context()).HTTPS,
RepoName: reponame,
}
err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
err := migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
assert.NoError(t, err)

//
Expand Down

0 comments on commit 3ee5ee2

Please sign in to comment.