From 5c8a6d93f63b0fca98c9dbd4b832367bdcd5b6fc Mon Sep 17 00:00:00 2001 From: Michael Mayer Date: Fri, 21 Nov 2025 10:28:43 +0100 Subject: [PATCH] CI: Add revive.toml & "make lint-go" target, improve .golangci.yml #5330 Signed-off-by: Michael Mayer --- .golangci.yml | 53 +++++++++++++++++++++++++++++++++++++++++++++++ Makefile | 7 ++++++- frontend/Makefile | 2 +- revive.toml | 34 ++++++++++++++++++++++++++++++ 4 files changed, 94 insertions(+), 2 deletions(-) create mode 100644 revive.toml diff --git a/.golangci.yml b/.golangci.yml index 8dccee779..cc89275e1 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -19,3 +19,56 @@ linters: - mnd # don't go after every "magic number" - depguard # only useful once you define strict dependency rules - gomodguard + - ineffassign + - errcheck + + settings: + revive: + # Only enable the revive rules you actually care about. + rules: + - name: blank-imports + - name: error-strings + - name: error-return + - name: error-naming + - name: exported + - name: if-return + - name: var-naming + severity: warning + disabled: false + exclude: [""] + arguments: + - ["ID", "Id", "id", "UID", "Uid", "uid", "URI", "Uri", "uri", "URL", "Url", "url"] # AllowList + - [] # DenyList + - - skip-initialism-name-checks: true + upper-case-const: true + skip-package-name-checks: true + - name: var-declaration + - name: increment-decrement + - name: range + - name: receiver-naming + - name: time-naming + - name: unexported-return + + misspell: + # Correct spellings using locale preferences for US or UK. + # Setting locale to US will correct the British spelling of 'colour' to 'color'. + # Default is to use a neutral variety of English. + locale: US + # Typos to ignore. + # Should be in lower case. + # Default: [] + ignore-rules: + - nolint + - gosec + # Extra word corrections. + # `typo` and `correction` should only contain letters. + # The words are case-insensitive. + # Default: [] + extra-words: + - typo: "Photoprism" + correction: "PhotoPrism" + # Mode of the analysis: + # - default: checks all the file content. + # - restricted: checks only comments. + # Default: "" + mode: restricted diff --git a/Makefile b/Makefile index dde5d328a..932d33bd3 100644 --- a/Makefile +++ b/Makefile @@ -936,8 +936,13 @@ docker-dummy-oidc: packer-digitalocean: $(info Buildinng DigitalOcean marketplace image...) (cd ./setup/docker/cloud && packer build digitalocean.json) +lint: lint-js lint-go lint-js: - (cd frontend && npm run lint) + $(info Linting JS code...) + $(MAKE) -C frontend lint +lint-go: + $(info Linting Go code...) + golangci-lint run --issues-exit-code 0 ./pkg/... ./internal/... ./.../internal/... fmt-js: (cd frontend && npm run fmt) fmt-go: diff --git a/frontend/Makefile b/frontend/Makefile index 6980b331a..1fcb15602 100644 --- a/frontend/Makefile +++ b/frontend/Makefile @@ -60,7 +60,7 @@ watch: build: npm run build lint: - npm run lint + npm run lint || true fmt: npm run fmt test: diff --git a/revive.toml b/revive.toml new file mode 100644 index 000000000..22a617862 --- /dev/null +++ b/revive.toml @@ -0,0 +1,34 @@ +ignoreGeneratedHeader = false +severity = "warning" +confidence = 0.8 +errorCode = 0 +warningCode = 0 + +[rule.blank-imports] +[rule.context-as-argument] +[rule.context-keys-type] +[rule.dot-imports] +[rule.error-return] +[rule.error-strings] +[rule.error-naming] +[rule.exported] +[rule.increment-decrement] +[rule.var-naming] +arguments = [ + ["ID", "Id", "id", "UID", "Uid", "uid", "URI", "Uri", "uri", "URL", "Url", "url"], + [], + [{ skip-initialism-name-checks = true, upper-case-const = true, skip-package-name-checks = true }] +] +[rule.var-declaration] +[rule.package-comments] +[rule.range] +[rule.receiver-naming] +[rule.time-naming] +[rule.unexported-return] +[rule.indent-error-flow] +[rule.errorf] +[rule.empty-block] +[rule.superfluous-else] +[rule.unused-parameter] +[rule.unreachable-code] +[rule.redefines-builtin-id]