1
1
Fork 1
mirror of https://github.com/go-gitea/gitea.git synced 2024-06-06 07:56:19 +02:00

add lint script

This commit is contained in:
silverwind 2024-04-27 21:06:52 +02:00
parent cab07abf55
commit 922fa2c954
No known key found for this signature in database
GPG Key ID: 2E62B41C93869443
2 changed files with 19 additions and 2 deletions

View File

@ -428,8 +428,8 @@ lint-go-vet:
.PHONY: lint-go-gopls
lint-go-gopls:
@echo "Running gopls..."
@$(GO) run $(GOPLS_PACKAGE) check $(GO_SOURCES_NO_BINDATA)
@echo "Running gopls check..."
@GO=$(GO) GOPLS_PACKAGE=$(GOPLS_PACKAGE) tools/lint-go-gopls.sh $(GO_SOURCES_NO_BINDATA)
lint-editorconfig:
@$(GO) run $(EDITORCONFIG_CHECKER_PACKAGE) $(EDITORCONFIG_FILES)

17
tools/lint-go-gopls.sh Executable file
View File

@ -0,0 +1,17 @@
#!/bin/bash
set -euo pipefail
# lint all go files with 'gopls check' and look for lines starting with the
# current absolute path, indicating a error was found. This is neccessary
# because the tool does not set non-zero exit code when errors are found.
# ref: https://github.com/golang/go/issues/67078
ERROR_LINES=$("$GO" run "$GOPLS_PACKAGE" check $@ | grep -P "^$PWD");
NUM_ERRORS=$(echo "$ERROR_LINES" | wc -l)
if [ "$NUM_ERRORS" -eq "0" ]; then
exit 0;
else
echo "$ERROR_LINES"
echo "Found $NUM_ERRORS 'gopls check' errors"
exit 1;
fi