|
2 | 2 |
|
3 | 3 | ## Naming |
4 | 4 |
|
| 5 | +- **Constants use semantic prefixes**: Group related constants with prefixes |
| 6 | + - `Dir*` for directories (`DirContext`, `DirArchive`) |
| 7 | + - `File*` for file paths (`FileSettings`, `FileClaudeMd`) |
| 8 | + - `Filename*` for file names only (`FilenameTask`, `FilenameDecision`) |
| 9 | + - `*Type*` for enum-like values (`UpdateTypeTask`, `UpdateTypeDecision`) |
| 10 | +- **Package name = folder name**: Go canonical pattern |
| 11 | + - `package initialize` in `initialize/` folder |
| 12 | + - Never `package initcmd` in `init/` folder |
| 13 | +- **Maps reference constants**: Use constants as keys, not literals |
| 14 | + - `map[string]X{ConstKey: value}` not `map[string]X{"literal": value}` |
| 15 | + |
5 | 16 | ## Patterns |
6 | 17 |
|
| 18 | +- **Centralize magic strings**: All repeated literals belong in a `config` or `constants` package |
| 19 | + - If a string appears in 3+ files, it needs a constant |
| 20 | + - If a string is used for comparison, it needs a constant |
| 21 | +- **Path construction**: Always use stdlib path joining |
| 22 | + - Go: `filepath.Join(dir, file)` |
| 23 | + - Python: `os.path.join(dir, file)` |
| 24 | + - Node: `path.join(dir, file)` |
| 25 | + - Never: `dir + "/" + file` |
| 26 | +- **Constants reference constants**: Self-referential definitions |
| 27 | + - `FileType[UpdateTypeTask] = FilenameTask` not `FileType["task"] = "TASKS.md"` |
| 28 | +- **Colocate related code**: Group by feature, not by type |
| 29 | + - `session/run.go`, `session/types.go`, `session/parse.go` |
| 30 | + - Not: `runners/session.go`, `types/session.go`, `parsers/session.go` |
| 31 | + |
7 | 32 | ## Testing |
| 33 | + |
| 34 | +- **Colocate tests**: Test files live next to source files |
| 35 | + - `foo.go` → `foo_test.go` in same package |
| 36 | + - Not a separate `tests/` folder |
| 37 | +- **Test the unit, not the file**: One test file can test multiple related functions |
| 38 | +- **Integration tests are separate**: `cli_test.go` for end-to-end binary tests |
| 39 | + |
| 40 | +## Documentation |
| 41 | + |
| 42 | +- **Godoc format**: Use canonical sections |
| 43 | + ```go |
| 44 | + // FunctionName does X. |
| 45 | + // |
| 46 | + // Longer description if needed. |
| 47 | + // |
| 48 | + // Parameters: |
| 49 | + // - param1: Description |
| 50 | + // - param2: Description |
| 51 | + // |
| 52 | + // Returns: |
| 53 | + // - Type: Description of return value |
| 54 | + func FunctionName(param1, param2 string) error |
| 55 | + ``` |
| 56 | +- **Package doc in doc.go**: Each package gets a `doc.go` with package-level documentation |
| 57 | +- **Copyright headers**: All source files get the project copyright header |
0 commit comments