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)
|
||||
ARCH := $(shell uname -m)
|
||||
UNAME_S := $(shell uname -s)
|
||||
GOLDFLAGS += -X main.Version=$(VERSION)
|
||||
GOFLAGS := -ldflags "$(GOLDFLAGS)"
|
||||
BINARY := chatd
|
||||
VERSION := $(shell git describe --tags --always --dirty 2>/dev/null || echo "dev")
|
||||
BUILDARCH := $(shell go env GOARCH)
|
||||
LDFLAGS := -X main.Version=$(VERSION) -X main.Buildarch=$(BUILDARCH)
|
||||
|
||||
default: clean debug
|
||||
all: check build
|
||||
|
||||
commit: fmt lint
|
||||
git commit -a
|
||||
|
||||
fmt:
|
||||
gofumpt -l -w .
|
||||
golangci-lint run --fix
|
||||
build:
|
||||
go build -ldflags "$(LDFLAGS)" -o bin/$(BINARY) ./cmd/chatd
|
||||
|
||||
lint:
|
||||
golangci-lint run
|
||||
sh -c 'test -z "$$(gofmt -l .)"'
|
||||
golangci-lint run --config .golangci.yml ./...
|
||||
|
||||
fmt:
|
||||
gofmt -s -w .
|
||||
goimports -w .
|
||||
|
||||
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
|
||||
DEBUG=1 GOTRACEBACK=all ./$(FN)d
|
||||
run: build
|
||||
./bin/$(BINARY)
|
||||
|
||||
debugger:
|
||||
cd cmd/$(FN)d && dlv debug main.go
|
||||
|
||||
run: ./$(FN)d
|
||||
./$(FN)d
|
||||
debug: build
|
||||
DEBUG=1 GOTRACEBACK=all ./bin/$(BINARY)
|
||||
|
||||
clean:
|
||||
-rm -f ./$(FN)d debug.log
|
||||
|
||||
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
|
||||
rm -rf bin/ chatd data.db
|
||||
|
||||
Reference in New Issue
Block a user