Add .golangci.yml linting config and comprehensive Makefile
This commit is contained in:
32
.golangci.yml
Normal file
32
.golangci.yml
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
version: "2"
|
||||||
|
|
||||||
|
run:
|
||||||
|
timeout: 5m
|
||||||
|
modules-download-mode: readonly
|
||||||
|
|
||||||
|
linters:
|
||||||
|
default: all
|
||||||
|
disable:
|
||||||
|
# Genuinely incompatible with project patterns
|
||||||
|
- exhaustruct # Requires all struct fields
|
||||||
|
- depguard # Dependency allow/block lists
|
||||||
|
- godot # Requires comments to end with periods
|
||||||
|
- wsl # Deprecated, replaced by wsl_v5
|
||||||
|
- wrapcheck # Too verbose for internal packages
|
||||||
|
- varnamelen # Short names like db, id are idiomatic Go
|
||||||
|
|
||||||
|
linters-settings:
|
||||||
|
lll:
|
||||||
|
line-length: 88
|
||||||
|
funlen:
|
||||||
|
lines: 80
|
||||||
|
statements: 50
|
||||||
|
cyclop:
|
||||||
|
max-complexity: 15
|
||||||
|
dupl:
|
||||||
|
threshold: 100
|
||||||
|
|
||||||
|
issues:
|
||||||
|
exclude-use-default: false
|
||||||
|
max-issues-per-linter: 0
|
||||||
|
max-same-issues: 0
|
||||||
67
Makefile
67
Makefile
@@ -1,48 +1,43 @@
|
|||||||
FN := chat
|
.PHONY: all build lint fmt test check clean run debug
|
||||||
|
|
||||||
VERSION := $(shell git describe --always --dirty=-dirty)
|
BINARY := chatd
|
||||||
ARCH := $(shell uname -m)
|
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||||
UNAME_S := $(shell uname -s)
|
BUILDARCH := $(shell go env GOARCH)
|
||||||
GOLDFLAGS += -X main.Version=$(VERSION)
|
LDFLAGS := -X main.Version=$(VERSION) -X main.Buildarch=$(BUILDARCH)
|
||||||
GOFLAGS := -ldflags "$(GOLDFLAGS)"
|
|
||||||
|
|
||||||
default: clean debug
|
all: check build
|
||||||
|
|
||||||
commit: fmt lint
|
build:
|
||||||
git commit -a
|
go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY) ./cmd/chatd
|
||||||
|
|
||||||
fmt:
|
|
||||||
gofumpt -l -w .
|
|
||||||
golangci-lint run --fix
|
|
||||||
|
|
||||||
lint:
|
lint:
|
||||||
golangci-lint run
|
golangci-lint run --config .golangci.yml ./...
|
||||||
sh -c 'test -z "$$(gofmt -l .)"'
|
|
||||||
|
fmt:
|
||||||
|
gofmt -s -w .
|
||||||
|
goimports -w .
|
||||||
|
|
||||||
test:
|
test:
|
||||||
go test ./...
|
go test -v -race -cover ./...
|
||||||
|
|
||||||
check: lint test
|
# Check runs all validation without making changes
|
||||||
|
# Used by CI and Docker build — fails if anything is wrong
|
||||||
|
check:
|
||||||
|
@echo "==> Checking formatting..."
|
||||||
|
@test -z "$$(gofmt -l .)" || (echo "Files not formatted:" && gofmt -l . && exit 1)
|
||||||
|
@echo "==> Running linter..."
|
||||||
|
golangci-lint run --config .golangci.yml ./...
|
||||||
|
@echo "==> Running tests..."
|
||||||
|
go test -v -race ./...
|
||||||
|
@echo "==> Building..."
|
||||||
|
go build -ldflags "$(LDFLAGS)" -o /dev/null ./cmd/chatd
|
||||||
|
@echo "==> All checks passed!"
|
||||||
|
|
||||||
debug: ./$(FN)d
|
run: build
|
||||||
DEBUG=1 GOTRACEBACK=all ./$(FN)d
|
./bin/$(BINARY)
|
||||||
|
|
||||||
debugger:
|
debug: build
|
||||||
cd cmd/$(FN)d && dlv debug main.go
|
DEBUG=1 GOTRACEBACK=all ./bin/$(BINARY)
|
||||||
|
|
||||||
run: ./$(FN)d
|
|
||||||
./$(FN)d
|
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
-rm -f ./$(FN)d debug.log
|
rm -rf bin/ chatd data.db
|
||||||
|
|
||||||
docker:
|
|
||||||
docker build --progress plain .
|
|
||||||
|
|
||||||
./$(FN)d: cmd/$(FN)d/main.go internal/*/*.go
|
|
||||||
cd ./cmd/$(FN)d && \
|
|
||||||
go build -o ../../$(FN)d $(GOFLAGS) .
|
|
||||||
|
|
||||||
tools:
|
|
||||||
go get -v github.com/golangci/golangci-lint/cmd/golangci-lint@v1.31.0
|
|
||||||
go get -v mvdan.cc/gofumpt/gofumports
|
|
||||||
|
|||||||
Reference in New Issue
Block a user