From 6bd8c976b6689945bd584f40d067347021a3cbb5 Mon Sep 17 00:00:00 2001 From: Nils Goroll Date: Fri, 20 Mar 2026 07:06:09 +0100 Subject: [PATCH] chore: polish linter error vs. dead code reporting (#11217) This PR improves and clarifies linter error reporting vs. dead code reporting. Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/11217 Reviewed-by: Gusted Co-authored-by: Nils Goroll Co-committed-by: Nils Goroll --- .gitignore | 1 + Makefile | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/.gitignore b/.gitignore index ffc493a51d..c524583ce8 100644 --- a/.gitignore +++ b/.gitignore @@ -107,6 +107,7 @@ cpu.out /.air /.go-licenses /.cur-deadcode-out +/.deadcode.diff # Files and folders that were previously generated /public/assets/img/webpack diff --git a/Makefile b/Makefile index dda216c0e9..4064ea8d85 100644 --- a/Makefile +++ b/Makefile @@ -486,11 +486,23 @@ RUN_DEADCODE = $(GO) run $(DEADCODE_PACKAGE) -generated=false -f='{{println .Pat .PHONY: lint-go lint-go: - $(GO) run $(GOLANGCI_LINT_PACKAGE) run $(GOLANGCI_LINT_ARGS) - $(GO) run $(ERRORTYPE_PACKAGE) ./... - $(RUN_DEADCODE) > .cur-deadcode-out - @$(DIFF) .deadcode-out .cur-deadcode-out \ + $(GO) run $(GOLANGCI_LINT_PACKAGE) run $(GOLANGCI_LINT_ARGS) \ || (code=$$?; echo "Please run 'make lint-go-fix' and commit the result"; exit $${code}) + $(RUN_DEADCODE) > .cur-deadcode-out + @$(DIFF) .deadcode-out .cur-deadcode-out >.deadcode.diff || true + @if grep -qE '^[+][^+]' .deadcode.diff ; then \ + cat .deadcode.diff ; \ + echo "Looks like you added dead code, please evaluate and remove or use it."; \ + echo "If you are sure the dead code should stay around, please run 'make lint-go-fix',"; \ + echo "commit the result and explain the reason in the commit message / PR description."; \ + exit 1; \ + fi + @if grep -qE '^[-][^-]' .deadcode.diff ; then \ + cat .deadcode.diff ; \ + echo "Looks like you removed dead code. Thank you!"; \ + echo "Run 'make lint-go-fix' and commit the result to accept."; \ + fi + $(GO) run $(ERRORTYPE_PACKAGE) ./... .PHONY: lint-go-fix lint-go-fix: