Skip to content

Commit 8dc6eab

Browse files
authored
Update go tool dependencies, restructure lint targets (#24239)
- Update all tool dependencies to latest tag - Remove unused errcheck, it is part of golangci-lint - Include main.go in air - Enable wastedassign again now that it's [generics-compatible](golangci/golangci-lint#3689) - Restructured lint targets to new `lint-*` namespace
1 parent 8820191 commit 8dc6eab

File tree

12 files changed

+88
-58
lines changed

12 files changed

+88
-58
lines changed

.air.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ tmp_dir = ".air"
55
cmd = "make backend"
66
bin = "gitea"
77
include_ext = ["go", "tmpl"]
8-
exclude_dir = ["modules/git/tests", "services/gitdiff/testdata", "modules/avatar/testdata", "models/fixtures", "models/migrations/fixtures", "modules/migration/file_format_testdata", "modules/avatar/identicon/testdata"]
8+
include_file = ["main.go"]
99
include_dir = ["cmd", "models", "modules", "options", "routers", "services"]
10+
exclude_dir = ["modules/git/tests", "services/gitdiff/testdata", "modules/avatar/testdata", "models/fixtures", "models/migrations/fixtures", "modules/migration/file_format_testdata", "modules/avatar/identicon/testdata"]
1011
exclude_regex = ["_test.go$", "_gen.go$"]

.drone.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ steps:
5959
- name: lint-backend-windows
6060
image: gitea/test_env:linux-1.20-amd64 # https://gitea.com/gitea/test-env
6161
commands:
62-
- make golangci-lint-windows vet
62+
- make lint-go-windows lint-go-vet
6363
environment:
6464
GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not
6565
GOSUMDB: sum.golang.org

.golangci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ linters:
2222
- unconvert
2323
- unused
2424
# - varcheck # deprecated - https://github.com/golangci/golangci-lint/issues/1841
25-
# - wastedassign # disabled - https://github.com/golangci/golangci-lint/issues/2649
25+
- wastedassign
2626
enable-all: false
2727
disable-all: true
2828
fast: false

Makefile

+71-39
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,15 @@ COMMA := ,
2525

2626
XGO_VERSION := go-1.20.x
2727

28-
AIR_PACKAGE ?= github.com/cosmtrek/air@v1.40.4
29-
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.6.0
30-
ERRCHECK_PACKAGE ?= github.com/kisielk/errcheck@v1.6.2
31-
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.4.0
32-
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2
33-
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.10
28+
AIR_PACKAGE ?= github.com/cosmtrek/air@v1.43.0
29+
EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.0
30+
GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.5.0
31+
GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2
32+
GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11
3433
MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/misspell@v0.3.4
3534
SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.30.4
3635
XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest
37-
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.5.0
36+
GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.6.0
3837
GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@latest
3938

4039
DOCKER_IMAGE ?= gitea/gitea
@@ -194,9 +193,20 @@ help:
194193
@echo " - deps-backend install backend dependencies"
195194
@echo " - deps-tools install tool dependencies"
196195
@echo " - lint lint everything"
196+
@echo " - lint-fix lint everything and fix issues"
197197
@echo " - lint-frontend lint frontend files"
198+
@echo " - lint-frontend-fix lint frontend files and fix issues"
198199
@echo " - lint-backend lint backend files"
200+
@echo " - lint-backend-fix lint backend files and fix issues"
201+
@echo " - lint-go lint go files"
202+
@echo " - lint-go-fix lint go files and fix issues"
203+
@echo " - lint-go-vet lint go files with vet"
204+
@echo " - lint-js lint js files"
205+
@echo " - lint-js-fix lint js files and fix issues"
206+
@echo " - lint-css lint css files"
207+
@echo " - lint-css-fix lint css files and fix issues"
199208
@echo " - lint-md lint markdown files"
209+
@echo " - lint-swagger lint swagger files"
200210
@echo " - checks run various consistency checks"
201211
@echo " - checks-frontend check frontend files"
202212
@echo " - checks-backend check backend files"
@@ -214,9 +224,7 @@ help:
214224
@echo " - generate-manpage generate manpage"
215225
@echo " - generate-swagger generate the swagger spec from code comments"
216226
@echo " - swagger-validate check if the swagger spec is valid"
217-
@echo " - golangci-lint run golangci-lint linter"
218227
@echo " - go-licenses regenerate go licenses"
219-
@echo " - vet examines Go source code and reports suspicious constructs"
220228
@echo " - tidy run go mod tidy"
221229
@echo " - test[\#TestSpecificName] run unit test"
222230
@echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite"
@@ -286,12 +294,6 @@ fmt-check: fmt
286294
misspell-check:
287295
go run $(MISSPELL_PACKAGE) -error $(GO_DIRS) $(WEB_DIRS)
288296

289-
.PHONY: vet
290-
vet:
291-
@echo "Running go vet..."
292-
@GOOS= GOARCH= $(GO) build code.gitea.io/gitea-vet
293-
@$(GO) vet -vettool=gitea-vet $(GO_PACKAGES)
294-
295297
.PHONY: $(TAGS_EVIDENCE)
296298
$(TAGS_EVIDENCE):
297299
@mkdir -p $(MAKE_EVIDENCE_DIR)
@@ -324,11 +326,6 @@ swagger-validate:
324326
$(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)'
325327
$(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)'
326328

327-
.PHONY: errcheck
328-
errcheck:
329-
@echo "Running errcheck..."
330-
$(GO) run $(ERRCHECK_PACKAGE) $(GO_PACKAGES)
331-
332329
.PHONY: checks
333330
checks: checks-frontend checks-backend
334331

@@ -341,18 +338,69 @@ checks-backend: tidy-check swagger-check fmt-check misspell-check swagger-valida
341338
.PHONY: lint
342339
lint: lint-frontend lint-backend
343340

341+
.PHONY: lint-fix
342+
lint-fix: lint-frontend-fix lint-backend-fix
343+
344344
.PHONY: lint-frontend
345-
lint-frontend: node_modules lint-md
345+
lint-frontend: lint-js lint-css lint-md lint-swagger
346+
347+
.PHONY: lint-frontend-fix
348+
lint-frontend-fix: lint-js-fix lint-css-fix lint-md lint-swagger
349+
350+
.PHONY: lint-backend
351+
lint-backend: lint-go lint-go-vet lint-editorconfig
352+
353+
.PHONY: lint-backend-fix
354+
lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig
355+
356+
.PHONY: lint-js
357+
lint-js: node_modules
346358
npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js docs/assets/js tests/e2e
359+
360+
.PHONY: lint-js-fix
361+
lint-js-fix: node_modules
362+
npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js docs/assets/js tests/e2e --fix
363+
364+
.PHONY: lint-css
365+
lint-css: node_modules
347366
npx stylelint --color --max-warnings=0 web_src/css
367+
368+
.PHONY: lint-css-fix
369+
lint-css-fix: node_modules
370+
npx stylelint --color --max-warnings=0 web_src/css --fix
371+
372+
.PHONY: lint-swagger
373+
lint-swagger: node_modules
348374
npx spectral lint -q -F hint $(SWAGGER_SPEC)
349375

350376
.PHONY: lint-md
351377
lint-md: node_modules
352378
npx markdownlint docs *.md
353379

354-
.PHONY: lint-backend
355-
lint-backend: golangci-lint vet editorconfig-checker
380+
.PHONY: lint-go
381+
lint-go:
382+
$(GO) run $(GOLANGCI_LINT_PACKAGE) run
383+
384+
.PHONY: lint-go-fix
385+
lint-go-fix:
386+
$(GO) run $(GOLANGCI_LINT_PACKAGE) run --fix
387+
388+
# workaround step for the lint-backend-windows CI task because 'go run' can not
389+
# have distinct GOOS/GOARCH for its build and run steps
390+
.PHONY: lint-go-windows
391+
lint-go-windows:
392+
@GOOS= GOARCH= $(GO) install $(GOLANGCI_LINT_PACKAGE)
393+
golangci-lint run
394+
395+
.PHONY: lint-go-vet
396+
lint-go-vet:
397+
@echo "Running go vet..."
398+
@GOOS= GOARCH= $(GO) build code.gitea.io/gitea-vet
399+
@$(GO) vet -vettool=gitea-vet $(GO_PACKAGES)
400+
401+
.PHONY: lint-editorconfig
402+
lint-editorconfig:
403+
$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates
356404

357405
.PHONY: watch
358406
watch:
@@ -843,7 +891,6 @@ deps-backend:
843891
deps-tools:
844892
$(GO) install $(AIR_PACKAGE)
845893
$(GO) install $(EDITORCONFIG_CHECKER_PACKAGE)
846-
$(GO) install $(ERRCHECK_PACKAGE)
847894
$(GO) install $(GOFUMPT_PACKAGE)
848895
$(GO) install $(GOLANGCI_LINT_PACKAGE)
849896
$(GO) install $(GXZ_PAGAGE)
@@ -942,21 +989,6 @@ generate-manpage:
942989
@gzip -9 man/man1/gitea.1 && echo man/man1/gitea.1.gz created
943990
@#TODO A small script that formats config-cheat-sheet.en-us.md nicely for use as a config man page
944991

945-
.PHONY: golangci-lint
946-
golangci-lint:
947-
$(GO) run $(GOLANGCI_LINT_PACKAGE) run
948-
949-
# workaround step for the lint-backend-windows CI task because 'go run' can not
950-
# have distinct GOOS/GOARCH for its build and run steps
951-
.PHONY: golangci-lint-windows
952-
golangci-lint-windows:
953-
@GOOS= GOARCH= $(GO) install $(GOLANGCI_LINT_PACKAGE)
954-
golangci-lint run
955-
956-
.PHONY: editorconfig-checker
957-
editorconfig-checker:
958-
$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates
959-
960992
.PHONY: docker
961993
docker:
962994
docker build --disable-content-trust=false -t $(DOCKER_REF) .

modules/charset/escape_stream.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@ func (e *escapeStreamer) EscapeStatus() *EscapeStatus {
4747
// Text tells the next streamer there is a text
4848
func (e *escapeStreamer) Text(data string) error {
4949
sb := &strings.Builder{}
50-
pos, until, next := 0, 0, 0
50+
var until int
51+
var next int
52+
pos := 0
5153
if len(data) > len(UTF8BOM) && data[:len(UTF8BOM)] == string(UTF8BOM) {
5254
_, _ = sb.WriteString(data[:len(UTF8BOM)])
5355
pos = len(UTF8BOM)

modules/templates/util_dict.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ func dumpVar(v any) template.HTML {
108108
return "<pre>dumpVar: only available in dev mode</pre>"
109109
}
110110
m, ok := dumpVarMarshalable(v, map[uintptr]bool{})
111-
dumpStr := ""
111+
var dumpStr string
112112
jsonBytes, err := json.MarshalIndent(m, "", " ")
113113
if err != nil {
114114
dumpStr = fmt.Sprintf("dumpVar: unable to marshal %T: %v", v, err)

modules/timeutil/since.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ const (
2323
)
2424

2525
func computeTimeDiffFloor(diff int64, lang translation.Locale) (int64, string) {
26-
diffStr := ""
26+
var diffStr string
2727
switch {
2828
case diff <= 0:
2929
diff = 0

modules/translation/i18n/localestore.go

-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ func (store *localeStore) AddLocaleByIni(langName, langDesc string, source, more
7272
l.idxToMsgMap[idx] = key.Value()
7373
}
7474
}
75-
iniFile = nil
7675

7776
return nil
7877
}

routers/common/markup.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import (
2020

2121
// RenderMarkup renders markup text for the /markup and /markdown endpoints
2222
func RenderMarkup(ctx *context.Context, mode, text, urlPrefix, filePath string, wiki bool) {
23-
markupType := ""
23+
var markupType string
2424
relativePath := ""
2525

2626
if len(text) == 0 {

services/gitdiff/gitdiff_test.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ index 0000000..6bb8f39
520520
Docker Pulls
521521
+ cut off
522522
+ cut off`
523-
result, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
523+
_, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "")
524524
if err != nil {
525525
t.Errorf("ParsePatch failed: %s", err)
526526
}
@@ -536,11 +536,10 @@ index 0000000..6bb8f39
536536
Docker Pulls
537537
+ cut off
538538
+ cut off`
539-
result, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2), "")
539+
_, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2), "")
540540
if err != nil {
541541
t.Errorf("ParsePatch failed: %s", err)
542542
}
543-
println(result)
544543

545544
diff2a := `diff --git "a/A \\ B" b/A/B
546545
--- "a/A \\ B"
@@ -553,11 +552,10 @@ index 0000000..6bb8f39
553552
Docker Pulls
554553
+ cut off
555554
+ cut off`
556-
result, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2a), "")
555+
_, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2a), "")
557556
if err != nil {
558557
t.Errorf("ParsePatch failed: %s", err)
559558
}
560-
println(result)
561559

562560
diff3 := `diff --git a/README.md b/README.md
563561
--- a/README.md
@@ -570,11 +568,10 @@ index 0000000..6bb8f39
570568
Docker Pulls
571569
+ cut off
572570
+ cut off`
573-
result, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff3), "")
571+
_, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff3), "")
574572
if err != nil {
575573
t.Errorf("ParsePatch failed: %s", err)
576574
}
577-
println(result)
578575
}
579576

580577
func setupDefaultDiff() *Diff {

tests/integration/api_packages_pub_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ description: ` + packageDescription
120120
assert.NoError(t, err)
121121
assert.Equal(t, int64(len(content)), pb.Size)
122122

123-
resp = uploadFile(t, result.URL, content, http.StatusBadRequest)
123+
_ = uploadFile(t, result.URL, content, http.StatusBadRequest)
124124
})
125125

126126
t.Run("Download", func(t *testing.T) {

tests/integration/api_repo_test.go

+2-3
Original file line numberDiff line numberDiff line change
@@ -183,18 +183,17 @@ func TestAPISearchRepo(t *testing.T) {
183183
for _, testCase := range testCases {
184184
t.Run(testCase.name, func(t *testing.T) {
185185
for userToLogin, expected := range testCase.expectedResults {
186-
var session *TestSession
187186
var testName string
188187
var userID int64
189188
var token string
190189
if userToLogin != nil && userToLogin.ID > 0 {
191190
testName = fmt.Sprintf("LoggedUser%d", userToLogin.ID)
192-
session = loginUser(t, userToLogin.Name)
191+
session := loginUser(t, userToLogin.Name)
193192
token = getTokenForLoggedInUser(t, session)
194193
userID = userToLogin.ID
195194
} else {
196195
testName = "AnonymousUser"
197-
session = emptyTestSession(t)
196+
_ = emptyTestSession(t)
198197
}
199198

200199
t.Run(testName, func(t *testing.T) {

0 commit comments

Comments
 (0)