Skip to content

Commit 3ee5ee2

Browse files
authored
Upgrade golangci-lint to v1.64.5 (go-gitea#33654)
Use `usetesting` instead of deprecated `tenv`. 1. Follow up go-gitea#33648 2. Make lint pass and add some comments
1 parent cd225d7 commit 3ee5ee2

File tree

6 files changed

+17
-20
lines changed

6 files changed

+17
-20
lines changed

.golangci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ linters:
1919
- revive
2020
- staticcheck
2121
- stylecheck
22-
- tenv
2322
- testifylint
2423
- typecheck
2524
- unconvert
2625
- unused
2726
- unparam
27+
- usetesting
2828
- wastedassign
2929

3030
run:
@@ -102,6 +102,8 @@ linters-settings:
102102
desc: do not use the ini package, use gitea's config system instead
103103
- pkg: gitea.com/go-chi/cache
104104
desc: do not use the go-chi cache package, use gitea's cache system
105+
usetesting:
106+
os-temp-dir: true
105107

106108
issues:
107109
max-issues-per-linter: 0

Makefile

+6-6
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ XGO_VERSION := go-1.24.x
2828
AIR_PACKAGE ?= github.com/air-verse/air@v1
2929
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/v3/cmd/[email protected]
3030
GOFUMPT_PACKAGE ?= mvdan.cc/[email protected]
31-
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.63.4
31+
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.64.5
3232
GXZ_PACKAGE ?= github.com/ulikunitz/xz/cmd/[email protected]
3333
MISSPELL_PACKAGE ?= github.com/golangci/misspell/cmd/[email protected]
3434
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/[email protected]
@@ -255,7 +255,7 @@ fmt-check: fmt
255255
@diff=$$(git diff --color=always $(GO_SOURCES) templates $(WEB_DIRS)); \
256256
if [ -n "$$diff" ]; then \
257257
echo "Please run 'make fmt' and commit the result:"; \
258-
echo "$${diff}"; \
258+
printf "%s" "$${diff}"; \
259259
exit 1; \
260260
fi
261261

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

@@ -426,7 +426,7 @@ test-check:
426426
@diff=$$(git status -s); \
427427
if [ -n "$$diff" ]; then \
428428
echo "make test-backend has changed files in the source tree:"; \
429-
echo "$${diff}"; \
429+
printf "%s" "$${diff}"; \
430430
echo "You should change the tests to create these files in a temporary directory."; \
431431
echo "Do not simply add these files to .gitignore"; \
432432
exit 1; \
@@ -879,7 +879,7 @@ svg-check: svg
879879
@diff=$$(git diff --color=always --cached $(SVG_DEST_DIR)); \
880880
if [ -n "$$diff" ]; then \
881881
echo "Please run 'make svg' and 'git add $(SVG_DEST_DIR)' and commit the result:"; \
882-
echo "$${diff}"; \
882+
printf "%s" "$${diff}"; \
883883
exit 1; \
884884
fi
885885

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

modules/secret/secret.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
// AesEncrypt encrypts text and given key with AES.
19+
// It is only internally used at the moment to use "SECRET_KEY" for some database values.
1920
func AesEncrypt(key, text []byte) ([]byte, error) {
2021
block, err := aes.NewCipher(key)
2122
if err != nil {
@@ -27,12 +28,13 @@ func AesEncrypt(key, text []byte) ([]byte, error) {
2728
if _, err = io.ReadFull(rand.Reader, iv); err != nil {
2829
return nil, fmt.Errorf("AesEncrypt unable to read IV: %w", err)
2930
}
30-
cfb := cipher.NewCFBEncrypter(block, iv)
31+
cfb := cipher.NewCFBEncrypter(block, iv) //nolint:staticcheck // need to migrate and refactor to a new approach
3132
cfb.XORKeyStream(ciphertext[aes.BlockSize:], []byte(b))
3233
return ciphertext, nil
3334
}
3435

3536
// AesDecrypt decrypts text and given key with AES.
37+
// It is only internally used at the moment to use "SECRET_KEY" for some database values.
3638
func AesDecrypt(key, text []byte) ([]byte, error) {
3739
block, err := aes.NewCipher(key)
3840
if err != nil {
@@ -43,7 +45,7 @@ func AesDecrypt(key, text []byte) ([]byte, error) {
4345
}
4446
iv := text[:aes.BlockSize]
4547
text = text[aes.BlockSize:]
46-
cfb := cipher.NewCFBDecrypter(block, iv)
48+
cfb := cipher.NewCFBDecrypter(block, iv) //nolint:staticcheck // need to migrate and refactor to a new approach
4749
cfb.XORKeyStream(text, text)
4850
data, err := base64.StdEncoding.DecodeString(string(text))
4951
if err != nil {

modules/storage/local_test.go

+1-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@
44
package storage
55

66
import (
7-
"os"
8-
"path/filepath"
97
"testing"
108

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

5856
func TestLocalStorageIterator(t *testing.T) {
59-
dir := filepath.Join(os.TempDir(), "TestLocalStorageIteratorTestDir")
60-
testStorageIterator(t, setting.LocalStorageType, &setting.Storage{Path: dir})
57+
testStorageIterator(t, setting.LocalStorageType, &setting.Storage{Path: t.TempDir()})
6158
}

modules/util/legacy_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ import (
1717
func TestCopyFile(t *testing.T) {
1818
testContent := []byte("hello")
1919

20-
tmpDir := os.TempDir()
20+
tmpDir := t.TempDir()
2121
now := time.Now()
2222
srcFile := fmt.Sprintf("%s/copy-test-%d-src.txt", tmpDir, now.UnixMicro())
2323
dstFile := fmt.Sprintf("%s/copy-test-%d-dst.txt", tmpDir, now.UnixMicro())

tests/integration/dump_restore_test.go

+2-6
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ import (
2020
base "code.gitea.io/gitea/modules/migration"
2121
"code.gitea.io/gitea/modules/setting"
2222
"code.gitea.io/gitea/modules/structs"
23-
"code.gitea.io/gitea/modules/util"
2423
"code.gitea.io/gitea/services/migrations"
2524

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

4443
reponame := "repo1"
4544

46-
basePath, err := os.MkdirTemp("", reponame)
47-
assert.NoError(t, err)
48-
defer util.RemoveAll(basePath)
49-
45+
basePath := t.TempDir()
5046
repo := unittest.AssertExistsAndLoadBean(t, &repo_model.Repository{Name: reponame})
5147
repoOwner := unittest.AssertExistsAndLoadBean(t, &user_model.User{ID: repo.OwnerID})
5248
session := loginUser(t, repoOwner.Name)
@@ -68,7 +64,7 @@ func TestDumpRestore(t *testing.T) {
6864
CloneAddr: repo.CloneLinkGeneral(t.Context()).HTTPS,
6965
RepoName: reponame,
7066
}
71-
err = migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
67+
err := migrations.DumpRepository(ctx, basePath, repoOwner.Name, opts)
7268
assert.NoError(t, err)
7369

7470
//

0 commit comments

Comments
 (0)