From ea2c30b730faa34bbe6a1e9741faf8d65bb55a69 Mon Sep 17 00:00:00 2001 From: silverwind Date: Thu, 20 Apr 2023 19:11:09 +0200 Subject: [PATCH 01/20] Update go tool dependencies - Update all tool dependencies to latest tag - Remove unused errcheck, it is part of golangci-lint - Include main.go in air --- .air.toml | 3 ++- Makefile | 19 ++++++------------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.air.toml b/.air.toml index 069a88924388b..fccd89b46c9d4 100644 --- a/.air.toml +++ b/.air.toml @@ -5,6 +5,7 @@ tmp_dir = ".air" cmd = "make backend" bin = "gitea" include_ext = ["go", "tmpl"] -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"] +include_file = ["main.go"] include_dir = ["cmd", "models", "modules", "options", "routers", "services"] +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"] exclude_regex = ["_test.go$", "_gen.go$"] diff --git a/Makefile b/Makefile index 59cc27ee8a102..693089170be37 100644 --- a/Makefile +++ b/Makefile @@ -25,16 +25,15 @@ COMMA := , XGO_VERSION := go-1.20.x -AIR_PACKAGE ?= github.com/cosmtrek/air@v1.40.4 -EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.6.0 -ERRCHECK_PACKAGE ?= github.com/kisielk/errcheck@v1.6.2 -GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.4.0 -GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.51.2 -GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.10 +AIR_PACKAGE ?= github.com/cosmtrek/air@v1.43.0 +EDITORCONFIG_CHECKER_PACKAGE ?= github.com/editorconfig-checker/editorconfig-checker/cmd/editorconfig-checker@2.7.0 +GOFUMPT_PACKAGE ?= mvdan.cc/gofumpt@v0.5.0 +GOLANGCI_LINT_PACKAGE ?= github.com/golangci/golangci-lint/cmd/golangci-lint@v1.52.2 +GXZ_PAGAGE ?= github.com/ulikunitz/xz/cmd/gxz@v0.5.11 MISSPELL_PACKAGE ?= github.com/client9/misspell/cmd/misspell@v0.3.4 SWAGGER_PACKAGE ?= github.com/go-swagger/go-swagger/cmd/swagger@v0.30.4 XGO_PACKAGE ?= src.techknowlogick.com/xgo@latest -GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.5.0 +GO_LICENSES_PACKAGE ?= github.com/google/go-licenses@v1.6.0 GOVULNCHECK_PACKAGE ?= golang.org/x/vuln/cmd/govulncheck@latest DOCKER_IMAGE ?= gitea/gitea @@ -324,11 +323,6 @@ swagger-validate: $(GO) run $(SWAGGER_PACKAGE) validate './$(SWAGGER_SPEC)' $(SED_INPLACE) '$(SWAGGER_SPEC_S_TMPL)' './$(SWAGGER_SPEC)' -.PHONY: errcheck -errcheck: - @echo "Running errcheck..." - $(GO) run $(ERRCHECK_PACKAGE) $(GO_PACKAGES) - .PHONY: checks checks: checks-frontend checks-backend @@ -843,7 +837,6 @@ deps-backend: deps-tools: $(GO) install $(AIR_PACKAGE) $(GO) install $(EDITORCONFIG_CHECKER_PACKAGE) - $(GO) install $(ERRCHECK_PACKAGE) $(GO) install $(GOFUMPT_PACKAGE) $(GO) install $(GOLANGCI_LINT_PACKAGE) $(GO) install $(GXZ_PAGAGE) From 32c0c888c08910189af40f9c1d4e49b44b488c66 Mon Sep 17 00:00:00 2001 From: silverwind Date: Fri, 21 Apr 2023 01:24:04 +0200 Subject: [PATCH 02/20] try enable wastedassign --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index ebb90af9d5049..1be6b63ef3a9a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -22,7 +22,7 @@ linters: - unconvert - unused # - varcheck # deprecated - https://github.com/golangci/golangci-lint/issues/1841 - # - wastedassign # disabled - https://github.com/golangci/golangci-lint/issues/2649 + - wastedassign enable-all: false disable-all: true fast: false From 83223b6080378fa01bf0d70e40a284d2f9fc8db9 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 09:02:00 +0200 Subject: [PATCH 03/20] add golangci-lint-fix target --- Makefile | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/Makefile b/Makefile index 693089170be37..4fc75d76e8829 100644 --- a/Makefile +++ b/Makefile @@ -214,6 +214,7 @@ help: @echo " - generate-swagger generate the swagger spec from code comments" @echo " - swagger-validate check if the swagger spec is valid" @echo " - golangci-lint run golangci-lint linter" + @echo " - golangci-lint run golangci-lint linter with --fix" @echo " - go-licenses regenerate go licenses" @echo " - vet examines Go source code and reports suspicious constructs" @echo " - tidy run go mod tidy" @@ -939,6 +940,10 @@ generate-manpage: golangci-lint: $(GO) run $(GOLANGCI_LINT_PACKAGE) run +.PHONY: golangci-lint-fix +golangci-lint-fix: + $(GO) run $(GOLANGCI_LINT_PACKAGE) run --fix + # workaround step for the lint-backend-windows CI task because 'go run' can not # have distinct GOOS/GOARCH for its build and run steps .PHONY: golangci-lint-windows From b8c35669dcc54deb0803d6f88b60feba1e53ebe2 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 09:12:20 +0200 Subject: [PATCH 04/20] fix some lints --- modules/translation/i18n/localestore.go | 1 - tests/integration/api_packages_pub_test.go | 2 -- 2 files changed, 3 deletions(-) diff --git a/modules/translation/i18n/localestore.go b/modules/translation/i18n/localestore.go index 90f574127d110..0664bcfd1a227 100644 --- a/modules/translation/i18n/localestore.go +++ b/modules/translation/i18n/localestore.go @@ -72,7 +72,6 @@ func (store *localeStore) AddLocaleByIni(langName, langDesc string, source, more l.idxToMsgMap[idx] = key.Value() } } - iniFile = nil return nil } diff --git a/tests/integration/api_packages_pub_test.go b/tests/integration/api_packages_pub_test.go index 24975ab6210a4..f53ef5333a684 100644 --- a/tests/integration/api_packages_pub_test.go +++ b/tests/integration/api_packages_pub_test.go @@ -119,8 +119,6 @@ description: ` + packageDescription pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID) assert.NoError(t, err) assert.Equal(t, int64(len(content)), pb.Size) - - resp = uploadFile(t, result.URL, content, http.StatusBadRequest) }) t.Run("Download", func(t *testing.T) { From defad27bd1803ba9ecebb0b05083eea1d3a94b88 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 09:20:17 +0200 Subject: [PATCH 05/20] fix more lints --- modules/charset/escape_stream.go | 3 ++- modules/timeutil/since.go | 2 +- routers/common/markup.go | 2 +- services/gitdiff/gitdiff_test.go | 1 + 4 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/charset/escape_stream.go b/modules/charset/escape_stream.go index 89bf36edce1aa..aea7860538bac 100644 --- a/modules/charset/escape_stream.go +++ b/modules/charset/escape_stream.go @@ -47,7 +47,8 @@ func (e *escapeStreamer) EscapeStatus() *EscapeStatus { // Text tells the next streamer there is a text func (e *escapeStreamer) Text(data string) error { sb := &strings.Builder{} - pos, until, next := 0, 0, 0 + var until + pos, next := 0, 0 if len(data) > len(UTF8BOM) && data[:len(UTF8BOM)] == string(UTF8BOM) { _, _ = sb.WriteString(data[:len(UTF8BOM)]) pos = len(UTF8BOM) diff --git a/modules/timeutil/since.go b/modules/timeutil/since.go index e6a2519d2120b..dfbc03c5d37fc 100644 --- a/modules/timeutil/since.go +++ b/modules/timeutil/since.go @@ -23,7 +23,7 @@ const ( ) func computeTimeDiffFloor(diff int64, lang translation.Locale) (int64, string) { - diffStr := "" + var diffStr switch { case diff <= 0: diff = 0 diff --git a/routers/common/markup.go b/routers/common/markup.go index 89f24e00075cc..91440009d8ae0 100644 --- a/routers/common/markup.go +++ b/routers/common/markup.go @@ -20,7 +20,7 @@ import ( // RenderMarkup renders markup text for the /markup and /markdown endpoints func RenderMarkup(ctx *context.Context, mode, text, urlPrefix, filePath string, wiki bool) { - markupType := "" + var markupType relativePath := "" if len(text) == 0 { diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go index eb9ed862e82f4..597d648068ce7 100644 --- a/services/gitdiff/gitdiff_test.go +++ b/services/gitdiff/gitdiff_test.go @@ -524,6 +524,7 @@ index 0000000..6bb8f39 if err != nil { t.Errorf("ParsePatch failed: %s", err) } + println(result) diff2 := `diff --git "a/A \\ B" "b/A \\ B" --- "a/A \\ B" From bf7fa9f13bb812e6e781c20cf0bf76cd2ab5881b Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 09:22:42 +0200 Subject: [PATCH 06/20] fix one more lint --- tests/integration/api_repo_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go index b3a184edddae7..9cf95bc8a6b94 100644 --- a/tests/integration/api_repo_test.go +++ b/tests/integration/api_repo_test.go @@ -194,7 +194,7 @@ func TestAPISearchRepo(t *testing.T) { userID = userToLogin.ID } else { testName = "AnonymousUser" - session = emptyTestSession(t) + _ := emptyTestSession(t) } t.Run(testName, func(t *testing.T) { From 28b945638250b88745f26e29f69508ae84d41528 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 09:26:26 +0200 Subject: [PATCH 07/20] fix build --- modules/charset/escape_stream.go | 2 +- modules/timeutil/since.go | 2 +- routers/common/markup.go | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/charset/escape_stream.go b/modules/charset/escape_stream.go index aea7860538bac..b4fc8bceda8e8 100644 --- a/modules/charset/escape_stream.go +++ b/modules/charset/escape_stream.go @@ -47,7 +47,7 @@ func (e *escapeStreamer) EscapeStatus() *EscapeStatus { // Text tells the next streamer there is a text func (e *escapeStreamer) Text(data string) error { sb := &strings.Builder{} - var until + var until int pos, next := 0, 0 if len(data) > len(UTF8BOM) && data[:len(UTF8BOM)] == string(UTF8BOM) { _, _ = sb.WriteString(data[:len(UTF8BOM)]) diff --git a/modules/timeutil/since.go b/modules/timeutil/since.go index dfbc03c5d37fc..4aee814ecdc68 100644 --- a/modules/timeutil/since.go +++ b/modules/timeutil/since.go @@ -23,7 +23,7 @@ const ( ) func computeTimeDiffFloor(diff int64, lang translation.Locale) (int64, string) { - var diffStr + var diffStr string switch { case diff <= 0: diff = 0 diff --git a/routers/common/markup.go b/routers/common/markup.go index 91440009d8ae0..3acd12721e854 100644 --- a/routers/common/markup.go +++ b/routers/common/markup.go @@ -20,7 +20,7 @@ import ( // RenderMarkup renders markup text for the /markup and /markdown endpoints func RenderMarkup(ctx *context.Context, mode, text, urlPrefix, filePath string, wiki bool) { - var markupType + var markupType string relativePath := "" if len(text) == 0 { From 6769108675cbe8154e95eea17d89e5de40da3de5 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 09:30:19 +0200 Subject: [PATCH 08/20] try disable gocritic --- .golangci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.golangci.yml b/.golangci.yml index 1be6b63ef3a9a..3814dcbd249e8 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,7 +5,7 @@ linters: - depguard - dupl - errcheck - - gocritic + # - gocritic # disabled for performance # - gocyclo # The cyclomatic complexety of a lot of functions is too high, we should refactor those another time. - gofmt - gofumpt From ec7abf50e79523a6681b29244b1a394c3f74d231 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 09:31:23 +0200 Subject: [PATCH 09/20] fix last lint --- modules/charset/escape_stream.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/modules/charset/escape_stream.go b/modules/charset/escape_stream.go index b4fc8bceda8e8..03d4cfc0c17bc 100644 --- a/modules/charset/escape_stream.go +++ b/modules/charset/escape_stream.go @@ -48,7 +48,8 @@ func (e *escapeStreamer) EscapeStatus() *EscapeStatus { func (e *escapeStreamer) Text(data string) error { sb := &strings.Builder{} var until int - pos, next := 0, 0 + var next int + pos := 0 if len(data) > len(UTF8BOM) && data[:len(UTF8BOM)] == string(UTF8BOM) { _, _ = sb.WriteString(data[:len(UTF8BOM)]) pos = len(UTF8BOM) From 39477b1976c327a01d0002b86801e4875f51f7e9 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 09:40:25 +0200 Subject: [PATCH 10/20] fix lints, re-enable gocritic --- .golangci.yml | 2 +- tests/integration/api_repo_test.go | 5 ++--- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/.golangci.yml b/.golangci.yml index 3814dcbd249e8..1be6b63ef3a9a 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -5,7 +5,7 @@ linters: - depguard - dupl - errcheck - # - gocritic # disabled for performance + - gocritic # - gocyclo # The cyclomatic complexety of a lot of functions is too high, we should refactor those another time. - gofmt - gofumpt diff --git a/tests/integration/api_repo_test.go b/tests/integration/api_repo_test.go index 9cf95bc8a6b94..ecaa9fe9866b9 100644 --- a/tests/integration/api_repo_test.go +++ b/tests/integration/api_repo_test.go @@ -183,18 +183,17 @@ func TestAPISearchRepo(t *testing.T) { for _, testCase := range testCases { t.Run(testCase.name, func(t *testing.T) { for userToLogin, expected := range testCase.expectedResults { - var session *TestSession var testName string var userID int64 var token string if userToLogin != nil && userToLogin.ID > 0 { testName = fmt.Sprintf("LoggedUser%d", userToLogin.ID) - session = loginUser(t, userToLogin.Name) + session := loginUser(t, userToLogin.Name) token = getTokenForLoggedInUser(t, session) userID = userToLogin.ID } else { testName = "AnonymousUser" - _ := emptyTestSession(t) + _ = emptyTestSession(t) } t.Run(testName, func(t *testing.T) { From 2f4f35f3c0ec443277ffe0dd21814981b59c5b7f Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 15:58:55 +0200 Subject: [PATCH 11/20] restore deleted line --- tests/integration/api_packages_pub_test.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/integration/api_packages_pub_test.go b/tests/integration/api_packages_pub_test.go index f53ef5333a684..4d4ce12402725 100644 --- a/tests/integration/api_packages_pub_test.go +++ b/tests/integration/api_packages_pub_test.go @@ -119,6 +119,8 @@ description: ` + packageDescription pb, err := packages.GetBlobByID(db.DefaultContext, pfs[0].BlobID) assert.NoError(t, err) assert.Equal(t, int64(len(content)), pb.Size) + + _ = uploadFile(t, result.URL, content, http.StatusBadRequest) }) t.Run("Download", func(t *testing.T) { From 87f3327e02af0be4eec547207b2201168143333e Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 16:04:53 +0200 Subject: [PATCH 12/20] remove all println in gitdiff_test.go --- services/gitdiff/gitdiff_test.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/services/gitdiff/gitdiff_test.go b/services/gitdiff/gitdiff_test.go index 597d648068ce7..389f787dfc442 100644 --- a/services/gitdiff/gitdiff_test.go +++ b/services/gitdiff/gitdiff_test.go @@ -520,11 +520,10 @@ index 0000000..6bb8f39 Docker Pulls + cut off + cut off` - result, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") + _, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff), "") if err != nil { t.Errorf("ParsePatch failed: %s", err) } - println(result) diff2 := `diff --git "a/A \\ B" "b/A \\ B" --- "a/A \\ B" @@ -537,11 +536,10 @@ index 0000000..6bb8f39 Docker Pulls + cut off + cut off` - result, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2), "") + _, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2), "") if err != nil { t.Errorf("ParsePatch failed: %s", err) } - println(result) diff2a := `diff --git "a/A \\ B" b/A/B --- "a/A \\ B" @@ -554,11 +552,10 @@ index 0000000..6bb8f39 Docker Pulls + cut off + cut off` - result, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2a), "") + _, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff2a), "") if err != nil { t.Errorf("ParsePatch failed: %s", err) } - println(result) diff3 := `diff --git a/README.md b/README.md --- a/README.md @@ -571,11 +568,10 @@ index 0000000..6bb8f39 Docker Pulls + cut off + cut off` - result, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff3), "") + _, err = ParsePatch(setting.Git.MaxGitDiffLines, setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles, strings.NewReader(diff3), "") if err != nil { t.Errorf("ParsePatch failed: %s", err) } - println(result) } func setupDefaultDiff() *Diff { From 8b0a1fa6147ed83ad263d3689636788b93fae287 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 16:18:09 +0200 Subject: [PATCH 13/20] restructure lint targets --- .drone.yml | 2 +- Makefile | 84 ++++++++++++++++++++++++++++++++++-------------------- 2 files changed, 54 insertions(+), 32 deletions(-) diff --git a/.drone.yml b/.drone.yml index 789f1ffca4155..d1eca955fcc31 100644 --- a/.drone.yml +++ b/.drone.yml @@ -59,7 +59,7 @@ steps: - name: lint-backend-windows image: gitea/test_env:linux-1.20-amd64 # https://gitea.com/gitea/test-env commands: - - make golangci-lint-windows vet + - make lint-go-windows lint-go-vet environment: GOPROXY: https://goproxy.io # proxy.golang.org is blocked in China, this proxy is not GOSUMDB: sum.golang.org diff --git a/Makefile b/Makefile index 4fc75d76e8829..4f1108acd0280 100644 --- a/Makefile +++ b/Makefile @@ -195,6 +195,14 @@ help: @echo " - lint lint everything" @echo " - lint-frontend lint frontend files" @echo " - lint-backend lint backend files" + @echo " - lint-go lint go files" + @echo " - lint-go-fix lint go files and fix issues" + @echo " - lint-go-vet lint go files with vet" + @echo " - lint-swagger lint swagger files" + @echo " - lint-js lint js files" + @echo " - lint-js-fix lint js files and fix issues" + @echo " - lint-css lint css files" + @echo " - lint-css-fix lint css files and fix issues" @echo " - lint-md lint markdown files" @echo " - checks run various consistency checks" @echo " - checks-frontend check frontend files" @@ -213,10 +221,7 @@ help: @echo " - generate-manpage generate manpage" @echo " - generate-swagger generate the swagger spec from code comments" @echo " - swagger-validate check if the swagger spec is valid" - @echo " - golangci-lint run golangci-lint linter" - @echo " - golangci-lint run golangci-lint linter with --fix" @echo " - go-licenses regenerate go licenses" - @echo " - vet examines Go source code and reports suspicious constructs" @echo " - tidy run go mod tidy" @echo " - test[\#TestSpecificName] run unit test" @echo " - test-sqlite[\#TestSpecificName] run integration test for sqlite" @@ -286,12 +291,6 @@ fmt-check: fmt misspell-check: go run $(MISSPELL_PACKAGE) -error $(GO_DIRS) $(WEB_DIRS) -.PHONY: vet -vet: - @echo "Running go vet..." - @GOOS= GOARCH= $(GO) build code.gitea.io/gitea-vet - @$(GO) vet -vettool=gitea-vet $(GO_PACKAGES) - .PHONY: $(TAGS_EVIDENCE) $(TAGS_EVIDENCE): @mkdir -p $(MAKE_EVIDENCE_DIR) @@ -337,17 +336,59 @@ checks-backend: tidy-check swagger-check fmt-check misspell-check swagger-valida lint: lint-frontend lint-backend .PHONY: lint-frontend -lint-frontend: node_modules lint-md +lint-frontend: lint-js lint-css lint-md lint-swagger + +.PHONY: lint-backend +lint-backend: lint-go lint-go-vet lint-editorconfig + +.PHONY: lint-js +lint-js: node_modules npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js docs/assets/js tests/e2e + +.PHONY: lint-js-fix +lint-js-fix: node_modules + npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js docs/assets/js tests/e2e --fix + +.PHONY: lint-css +lint-css: node_modules npx stylelint --color --max-warnings=0 web_src/css + +.PHONY: lint-css-fix +lint-css-fix: node_modules + npx stylelint --color --max-warnings=0 web_src/css --fix + +.PHONY: lint-swagger +lint-swagger: node_modules npx spectral lint -q -F hint $(SWAGGER_SPEC) .PHONY: lint-md lint-md: node_modules npx markdownlint docs *.md -.PHONY: lint-backend -lint-backend: golangci-lint vet editorconfig-checker +.PHONY: lint-go +lint-go: + $(GO) run $(GOLANGCI_LINT_PACKAGE) run + +.PHONY: lint-go-fix +lint-go-fix: + $(GO) run $(GOLANGCI_LINT_PACKAGE) run --fix + +# workaround step for the lint-backend-windows CI task because 'go run' can not +# have distinct GOOS/GOARCH for its build and run steps +.PHONY: lint-go-windows +lint-go-windows: + @GOOS= GOARCH= $(GO) install $(GOLANGCI_LINT_PACKAGE) + golangci-lint run + +.PHONY: lint-go-vet +lint-go-vet: + @echo "Running go vet..." + @GOOS= GOARCH= $(GO) build code.gitea.io/gitea-vet + @$(GO) vet -vettool=gitea-vet $(GO_PACKAGES) + +.PHONY: lint-editorconfig +lint-editorconfig: + $(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates .PHONY: watch watch: @@ -936,25 +977,6 @@ generate-manpage: @gzip -9 man/man1/gitea.1 && echo man/man1/gitea.1.gz created @#TODO A small script that formats config-cheat-sheet.en-us.md nicely for use as a config man page -.PHONY: golangci-lint -golangci-lint: - $(GO) run $(GOLANGCI_LINT_PACKAGE) run - -.PHONY: golangci-lint-fix -golangci-lint-fix: - $(GO) run $(GOLANGCI_LINT_PACKAGE) run --fix - -# workaround step for the lint-backend-windows CI task because 'go run' can not -# have distinct GOOS/GOARCH for its build and run steps -.PHONY: golangci-lint-windows -golangci-lint-windows: - @GOOS= GOARCH= $(GO) install $(GOLANGCI_LINT_PACKAGE) - golangci-lint run - -.PHONY: editorconfig-checker -editorconfig-checker: - $(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) templates - .PHONY: docker docker: docker build --disable-content-trust=false -t $(DOCKER_REF) . From 8c7b1cce4f882055011324ca36be43f3d751a8a2 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 17:00:53 +0200 Subject: [PATCH 14/20] re-order help --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 4f1108acd0280..183add132107f 100644 --- a/Makefile +++ b/Makefile @@ -198,12 +198,12 @@ help: @echo " - lint-go lint go files" @echo " - lint-go-fix lint go files and fix issues" @echo " - lint-go-vet lint go files with vet" - @echo " - lint-swagger lint swagger files" @echo " - lint-js lint js files" @echo " - lint-js-fix lint js files and fix issues" @echo " - lint-css lint css files" @echo " - lint-css-fix lint css files and fix issues" @echo " - lint-md lint markdown files" + @echo " - lint-swagger lint swagger files" @echo " - checks run various consistency checks" @echo " - checks-frontend check frontend files" @echo " - checks-backend check backend files" From 58b0abe94fdcb2d6667782ffcf3562a2b21b067e Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 17:36:25 +0200 Subject: [PATCH 15/20] add lint-fix --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 183add132107f..022c6520d6309 100644 --- a/Makefile +++ b/Makefile @@ -193,6 +193,7 @@ help: @echo " - deps-backend install backend dependencies" @echo " - deps-tools install tool dependencies" @echo " - lint lint everything" + @echo " - lint-fix lint and fix everything where fix is available" @echo " - lint-frontend lint frontend files" @echo " - lint-backend lint backend files" @echo " - lint-go lint go files" @@ -335,6 +336,9 @@ checks-backend: tidy-check swagger-check fmt-check misspell-check swagger-valida .PHONY: lint lint: lint-frontend lint-backend +.PHONY: lint-fix +lint-fix: lint-go-fix lint-js-fix lint-css-fix + .PHONY: lint-frontend lint-frontend: lint-js lint-css lint-md lint-swagger From d5a8bcd3a6ecd3a9bc0e7164bdca37e539736269 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 17:44:08 +0200 Subject: [PATCH 16/20] change lint-fix to lint everything, add intermediate targets --- Makefile | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 022c6520d6309..62318655bbf32 100644 --- a/Makefile +++ b/Makefile @@ -193,7 +193,7 @@ help: @echo " - deps-backend install backend dependencies" @echo " - deps-tools install tool dependencies" @echo " - lint lint everything" - @echo " - lint-fix lint and fix everything where fix is available" + @echo " - lint-fix lint and fix everything" @echo " - lint-frontend lint frontend files" @echo " - lint-backend lint backend files" @echo " - lint-go lint go files" @@ -337,14 +337,20 @@ checks-backend: tidy-check swagger-check fmt-check misspell-check swagger-valida lint: lint-frontend lint-backend .PHONY: lint-fix -lint-fix: lint-go-fix lint-js-fix lint-css-fix +lint-fix: lint-frontend-fix lint-backend-fix .PHONY: lint-frontend lint-frontend: lint-js lint-css lint-md lint-swagger +.PHONY: lint-frontend-fix +lint-frontend-fix: lint-js-fix lint-css-fix lint-md lint-swagger + .PHONY: lint-backend lint-backend: lint-go lint-go-vet lint-editorconfig +.PHONY: lint-backend-fix +lint-backend-fix: lint-go-fix lint-go-vet lint-editorconfig + .PHONY: lint-js lint-js: node_modules npx eslint --color --max-warnings=0 --ext js,vue web_src/js build *.config.js docs/assets/js tests/e2e From 117ee6b102091e2f26b2c3ff7a168ca653d5b208 Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 17:45:25 +0200 Subject: [PATCH 17/20] add help --- Makefile | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Makefile b/Makefile index 62318655bbf32..d16fc0f5ce2d6 100644 --- a/Makefile +++ b/Makefile @@ -195,7 +195,9 @@ help: @echo " - lint lint everything" @echo " - lint-fix lint and fix everything" @echo " - lint-frontend lint frontend files" + @echo " - lint-frontend-fix lint and fix frontend files" @echo " - lint-backend lint backend files" + @echo " - lint-backend-fix lint and fix backend files" @echo " - lint-go lint go files" @echo " - lint-go-fix lint go files and fix issues" @echo " - lint-go-vet lint go files with vet" From a9400f7d3cac3822679eab78253ca3672ef79a9d Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 17:47:12 +0200 Subject: [PATCH 18/20] reword help for consistency --- Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index d16fc0f5ce2d6..c94f36d6a92fa 100644 --- a/Makefile +++ b/Makefile @@ -193,11 +193,11 @@ help: @echo " - deps-backend install backend dependencies" @echo " - deps-tools install tool dependencies" @echo " - lint lint everything" - @echo " - lint-fix lint and fix everything" + @echo " - lint-fix lint everything and fix issues" @echo " - lint-frontend lint frontend files" - @echo " - lint-frontend-fix lint and fix frontend files" + @echo " - lint-frontend-fix lint frontend files and fix issues" @echo " - lint-backend lint backend files" - @echo " - lint-backend-fix lint and fix backend files" + @echo " - lint-backend-fix lint backend files and fix issues" @echo " - lint-go lint go files" @echo " - lint-go-fix lint go files and fix issues" @echo " - lint-go-vet lint go files with vet" From 87fbbe9d12d8743cb9f9aa6e2c280e407015752f Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 19:01:35 +0200 Subject: [PATCH 19/20] restart ci From 967ad6ed40825200ad3c825fbe4aff1e94a2e8de Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 22 Apr 2023 19:48:31 +0200 Subject: [PATCH 20/20] fix new lint error --- modules/templates/util_dict.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/templates/util_dict.go b/modules/templates/util_dict.go index c83f22449cdcc..79c307b68d9a0 100644 --- a/modules/templates/util_dict.go +++ b/modules/templates/util_dict.go @@ -108,7 +108,7 @@ func dumpVar(v any) template.HTML { return "
dumpVar: only available in dev mode
" } m, ok := dumpVarMarshalable(v, map[uintptr]bool{}) - dumpStr := "" + var dumpStr string jsonBytes, err := json.MarshalIndent(m, "", " ") if err != nil { dumpStr = fmt.Sprintf("dumpVar: unable to marshal %T: %v", v, err)