|
| 1 | +# Repository Guidelines |
| 2 | + |
| 3 | +All rules in this document are requirements — not suggestions. ALWAYS follow them. |
| 4 | + |
| 5 | +Wormatter is a DST-based Go source code formatter. Highly opinionated, but very comprehensive. Gofumpt and gci built-in. |
| 6 | + |
| 7 | +## Highest-priority rule (MANDATORY) |
| 8 | + |
| 9 | +- NEVER add comments unless they document a non-obvious public API or explain genuinely non-obvious logic. NEVER add comments that restate what the code does, repeat the field/function name, describe obvious error handling, or act as section separators. When in doubt, don't comment. |
| 10 | +- ALWAYS use `task` commands for build/test/lint/format — NEVER raw `go build`, `go test`, `go vet`, `go fmt`, or `golangci-lint` directly. |
| 11 | +- ALWAYS verify, don't assume — check the actual state before making changes. |
| 12 | +- ALWAYS start with the simplest possible solution. If it works, stop. Add complexity only when justified by a concrete, current requirement — NEVER for hypothetical future needs. |
| 13 | +- NEVER leave TODOs, stubs, or partial implementations. |
| 14 | +- ALWAYS stay within the scope of what was asked. When asked to update a plan — only update the plan, don't change code. When asked to brainstorm/discuss — only discuss, don't write code. When asked to do X — do X and nothing else. NEVER make unsolicited changes. |
| 15 | + |
| 16 | +## Code style |
| 17 | + |
| 18 | +### Design (MANDATORY) |
| 19 | + |
| 20 | +> NEVER edit rules below directly. Instead ALWAYS update [CODESTYLE.md](CODESTYLE.md) and ask AI to sync the section below with it. |
| 21 | +
|
| 22 | +- ALWAYS prefer stupid and simple over abstract and extendable. |
| 23 | +- ALWAYS prefer a bit of duplication over complex abstractions. |
| 24 | +- ALWAYS prefer clarity over brevity in names. |
| 25 | +- ALWAYS minimize interfaces, generics, embedding. |
| 26 | +- ALWAYS prefer fewer types. Prefer no types over few. Prefer data types over types with behavior. |
| 27 | +- ALWAYS prefer functions over methods. ALWAYS prefer public fields over getters/setters. |
| 28 | +- ALWAYS keep everything private/internal as much as possible. |
| 29 | +- ALWAYS validate early, validate a lot. ALWAYS keep APIs stupid and minimal. |
| 30 | +- NEVER prefer global state. ALWAYS prefer simplicity over micro-optimizations. |
| 31 | +- ALWAYS use libraries for complex things instead of reinventing the wheel. |
| 32 | +- NEVER add comments unless they document a non-obvious public API or explain genuinely non-obvious logic. NEVER add obvious/redundant comments, NEVER add comments restating what code does. When in doubt, don't comment. |
| 33 | + |
| 34 | +### Conventions (MANDATORY) |
| 35 | + |
| 36 | +> NEVER edit rules below directly. Instead ALWAYS update [CODESTYLE.md](CODESTYLE.md) and ask AI to sync the section below with it. |
| 37 | +
|
| 38 | +- All arguments of a public function are required — passing nil not allowed. |
| 39 | +- Optional arguments via `<FunctionName>Options` as the last argument. NEVER use functional options. |
| 40 | +- Use guard clauses and early returns to keep the happy path unindented. |
| 41 | +- Use `samber/lo` helpers: `lo.Filter`, `lo.Find`, `lo.Map`, `lo.Contains`, `lo.Ternary`, `lo.ToPtr`, `lo.Must`, etc. |
| 42 | +- Constructors: `New<TypeName>[...]()`. No network/filesystem calls in constructors. |
| 43 | +- Interfaces: ALWAYS add `var _ Animal = (*Dog)(nil)` compile-time check. |
| 44 | +- Constants: avoid `iota`. Prefix enum constants with type name: `LogLevelDebug LogLevel = "debug"`. |
| 45 | +- Errors: ALWAYS wrap with context: `fmt.Errorf("read config: %w", err)`. Describe what is being done, not what failed. Panic on programmer errors. Prefer one-line `if err := ...; err != nil`. |
| 46 | + |
| 47 | +### Go standard guidelines (MANDATORY) |
| 48 | + |
| 49 | +Follow [Effective Go](https://go.dev/doc/effective_go) and [Go Code Review Comments](https://go.dev/wiki/CodeReviewComments). Commonly violated rules: |
| 50 | + |
| 51 | +- NEVER use `this`/`self` as receiver names. Use 1-2 letter names, consistent across methods. |
| 52 | +- NEVER discard errors with `_`. Indent error flow, not happy path. |
| 53 | +- NEVER use dot imports. |
| 54 | +- NEVER use named returns or naked returns. |
| 55 | + |
| 56 | +## Commands (MANDATORY) |
| 57 | + |
| 58 | +ALWAYS use these `task` commands. NEVER use raw `go build`, `go test`, `go fmt`, `go vet`, or `golangci-lint` directly. Pass extra args after `--` to forward them to the underlying command (e.g., `task test -- -run TestMyFunc`). |
| 59 | + |
| 60 | +- NEVER `go build` → ALWAYS `task build`. Builds binary to `./bin/`. |
| 61 | +- NEVER `go test` → ALWAYS `task test`. Runs all tests. |
| 62 | +- `task clean` — clean build artifacts. |
| 63 | +- `task install` — install binary to `$GOPATH/bin`. |
| 64 | + |
| 65 | +## Testing (MANDATORY) |
| 66 | + |
| 67 | +- ALWAYS use `testify` (`assert`, `require`) when writing new tests. |
| 68 | +- When writing tests as an AI agent → ALWAYS name the file `*_ai_test.go`, add `//go:build ai_tests` build tag, prefix test functions with `TestAI_`. |
| 69 | +- ALWAYS place tests alongside source files, not in a separate directory. |
| 70 | +- Test helpers go in `helpers_test.go` (or `helpers_ai_test.go` for AI-written helpers). |
| 71 | +- Test fixtures go in `testdata/` subdirectory next to the tests. |
| 72 | + |
| 73 | +## PR review guidelines (MANDATORY) |
| 74 | + |
| 75 | +- NEVER add new external dependencies without flagging to the user first. |
| 76 | +- NEVER introduce breaking user-facing changes (not API changes) unless they are hidden behind a feature flag. Flag to the user first. |
| 77 | +- NEVER introduce changes that may compromise security. Flag to the user first. |
0 commit comments