diff --git a/TODO.md b/TODO.md index 83c8480..d68a307 100644 --- a/TODO.md +++ b/TODO.md @@ -21,6 +21,11 @@ fmt-check, and commit. # Completed Steps +- 2026-11-07: Go code is now formatted with `gofmt` and then `golines -m 77` + (https://git.eeqj.de/sneak/prompts/issues/160). `prompts/REPO_POLICIES.md` + says how `script/fmt`, `script/fmt-check` and `script/bootstrap` do it and + pins `golines`. The Go style guide and both checklists say the same. `lll` + stays at 88, since `golines` leaves long strings and comments as they are. - 2026-11-06: The pinning rule in `prompts/REPO_POLICIES.md` now opens with its scope: what we download and install ourselves in scripts and Dockerfiles (https://git.eeqj.de/sneak/prompts/issues/154). Distribution packages are diff --git a/prompts/CODE_STYLEGUIDE_GO.md b/prompts/CODE_STYLEGUIDE_GO.md index 1da9c13..82e5c82 100644 --- a/prompts/CODE_STYLEGUIDE_GO.md +++ b/prompts/CODE_STYLEGUIDE_GO.md @@ -1,13 +1,16 @@ --- title: Code Styleguide — Go -last_modified: 2026-10-18 +last_modified: 2026-11-07 --- -1. Try to hard wrap long lines at 77 characters or less. +1. Format Go code with `gofmt` and then `golines -m 77`, through `make fmt`. + Don't commit anything `make fmt` would change. The only exception is when + committing things that aren't yet syntactically valid, which should only + happen pre-v0.0.1 or on a non-`main` branch. -1. Don't commit anything that hasn't been `go fmt`'d. The only exception is - when committing things that aren't yet syntactically valid, which should - only happen pre-v0.0.1 or on a non-`main` branch. +1. Hard wrap long lines at 77 characters or less. `golines` does this for code. + Wrap comments and long string literals by hand, since `golines` leaves them + as they are. 1. Even if you are planning to deal with only positive integers, use `int`/`int64` types instead of `uint`/`uint64` types. This is for diff --git a/prompts/EXISTING_REPO_CHECKLIST.md b/prompts/EXISTING_REPO_CHECKLIST.md index 8fe3f42..eb3f74f 100644 --- a/prompts/EXISTING_REPO_CHECKLIST.md +++ b/prompts/EXISTING_REPO_CHECKLIST.md @@ -1,6 +1,6 @@ --- title: Existing Repo Checklist -last_modified: 2026-11-06 +last_modified: 2026-11-07 --- Use this checklist when beginning work in a repo that may not yet conform to our @@ -259,8 +259,13 @@ with your task. # Formatting -- [ ] Platform-standard formatter is configured (`black`, `prettier`, `go fmt`) -- [ ] Default formatter config, only exception: four-space indents (except Go) +- [ ] Platform-standard formatter is configured (`black`, `prettier`, and for Go + `gofmt` then `golines -m 77`) +- [ ] Default formatter config, except four-space indents (not Go) and the Go + 77-column limit +- [ ] Go: `script/bootstrap` installs `golines` with `go install` pinned to a + commit hash; `script/fmt-check` fails when `gofmt` or `golines -m 77` + would change a file - [ ] All files pass `make fmt-check` # Git Hygiene diff --git a/prompts/NEW_REPO_CHECKLIST.md b/prompts/NEW_REPO_CHECKLIST.md index 0380f38..0332076 100644 --- a/prompts/NEW_REPO_CHECKLIST.md +++ b/prompts/NEW_REPO_CHECKLIST.md @@ -1,6 +1,6 @@ --- title: New Repo Checklist -last_modified: 2026-11-06 +last_modified: 2026-11-07 --- Use this checklist when creating a new repository from scratch. Follow the steps @@ -233,9 +233,11 @@ are thin shims calling them. Model scripts: which writes no image. No lint verdict may come from a host invocation of the linter. - [ ] `script/fmt` / `make fmt` — formats code (writes; native, never in a - container) + container). Go code gets `gofmt`, then `golines -m 77`. - [ ] `script/fmt-check` / `make fmt-check` — checks formatting (read-only; - native) + native). Fails when `gofmt` or `golines -m 77` would change a Go file. +- [ ] Go: `script/bootstrap` installs `golines` with `go install` pinned to a + commit hash - [ ] `script/check` / `make check` — runs `test`, `lint`, `fmt-check`; must not modify files - [ ] `script/projectname` — outputs the project name (used by `script/docker` diff --git a/prompts/REPO_POLICIES.md b/prompts/REPO_POLICIES.md index e44995d..fc0c0e1 100644 --- a/prompts/REPO_POLICIES.md +++ b/prompts/REPO_POLICIES.md @@ -1,6 +1,6 @@ --- title: Repository Policies -last_modified: 2026-11-06 +last_modified: 2026-11-07 --- This document covers repository structure, tooling, and workflow standards. Code @@ -675,11 +675,26 @@ style conventions are in separate documents: - Use platform-standard formatters: - `black` for Python - `prettier` for JS/CSS/Markdown/HTML - - `go fmt` for Go + - `gofmt`, then `golines -m 77`, for Go - Always use default configuration, with two exceptions: + Always use default configuration, with three exceptions: - four-space indents (except Go) - `proseWrap: always` for Markdown (hard-wrap at 80 columns) + - a 77-column limit for Go, set by `golines -m 77` + + `script/fmt` runs `gofmt` and then `golines -m 77` on Go code. + `script/fmt-check` fails when either of them would change a file. `golines` + comes from `github.com/segmentio/golines`. `script/bootstrap` installs it + with `go install`, pinned to a commit hash as below: + + ```sh + # golines v0.13.0, 2025-08-21 + go install github.com/segmentio/golines@8f32f0f7e89c30f572c7f2cd3b2a48016b9d8bbf + ``` + + `golines` cannot shorten every line: long string literals and comments stay + as they are. golangci-lint's `lll` limit therefore stays at 88 columns, so + it fails only lines far past the formatter's limit. Documentation and writing repos (Markdown, HTML, CSS) should also have `.prettierrc` and `.prettierignore`.