.golangci.yml:
- 启用 linter: errcheck, gosec, govet, staticcheck, ineffassign, unused,
revive, contextcheck, errorlint, errname, misspell
- 启用 formatter: gofumpt + goimports
Makefile:
- fmt/fmt-check: gofumpt + goimports 格式检查
- lint/lint-strict: golangci-lint 报告/阻断模式
- test: go test -race
- ci: 完整 CI 流程 (fmt-check + lint)
docs/code-style.md:
- 新增 AI 执行协议 + 代码格式化/自动化检查/MUST规则
- 集成 golangci-lint 检查项与规范对照
36 lines
993 B
Makefile
36 lines
993 B
Makefile
.PHONY: lint fmt check test
|
||
|
||
# === 代码格式化 ===
|
||
fmt:
|
||
@echo "==> gofumpt..."
|
||
@gofumpt -l -w internal/ cmd/
|
||
@echo "==> goimports..."
|
||
@goimports -w internal/ cmd/
|
||
|
||
# === 格式检查(CI 用,只读不改) ===
|
||
fmt-check:
|
||
@echo "==> gofumpt check..."
|
||
@test -z "$$(gofumpt -l internal/ cmd/)" || (echo "gofumpt: 以下文件格式不正确:" && gofumpt -l internal/ cmd/ && exit 1)
|
||
@echo "==> goimports check..."
|
||
@test -z "$$(goimports -l internal/ cmd/)" || (echo "goimports: 以下文件 import 不规范:" && goimports -l internal/ cmd/ && exit 1)
|
||
|
||
# === 静态分析(报告模式,不阻断) ===
|
||
lint:
|
||
@echo "==> golangci-lint (report only)..."
|
||
@golangci-lint run ./... || true
|
||
|
||
# === 静态分析(阻断模式,CI 用) ===
|
||
lint-strict:
|
||
@echo "==> golangci-lint (strict)..."
|
||
@golangci-lint run ./...
|
||
|
||
# === 测试 ===
|
||
test:
|
||
@echo "==> go test..."
|
||
@go test -v -race ./...
|
||
|
||
# === CI 完整流程(报告模式) ===
|
||
ci:
|
||
@$(MAKE) fmt-check
|
||
@$(MAKE) lint
|