mirror of
https://github.com/devvmhq/devvm.git
synced 2026-12-01 21:36:40 -10:00
build(lint): enforce contexts, nolint reasons, reassign and function size
.golangci.yml: - forbidigo bans context.Background and context.TODO outside internal/ui and cmd/devvm. - nolintlint requires each //nolint to name its linters and say why, and reports unused ones. - reassign (patterns .*) forbids setting another package's variables, tests included. - revive keeps its default rules and adds function-length (100 statements, 160 lines) and cognitive-complexity (75). Fixes: - Backend.Lifeline takes a ctx: smolvm's machine data-dir lookup runs with the caller's. - The proxy's TLS handshake with a VM uses the request's context, limited to 30 seconds. - OAuth token refreshes run within refreshTimeout (30 seconds). - Tests use t.Context(). - Launch.create is split into plan, newVM.record and undoCreate. - lima's TestStartConfined is split into helpers. - smolvm's Terminal comes from its UI's StdinIsTerminal. - Unused //nolint directives are removed. - Fresh contexts that remain (an in-memory TLS parse, lookups shared by every request, a test cleanup) each carry a nolint saying why. Docs: contributing.md lists which lint rule enforces which convention; AGENTS.md names the linters behind its Go conventions. Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
35 files changed
+341
-232
No files matched your search
@@ -59,6 +59,20 @@ Before and after every change, `mise run fmt && mise run lint && mise run test`
|
||||
|
||||
CI runs `lint` and `test` on macOS and Linux.
|
||||
|
||||
## Go lint rules
|
||||
|
||||
golangci-lint enforces the [Go conventions](https://github.com/w3cj/devvm/blob/main/AGENTS.md#go-conventions) in `.golangci.yml`:
|
||||
|
||||
| Rule | Enforces |
|
||||
| --- | --- |
|
||||
| forbidigo | only `internal/ui` prints (`fmt.Print*`, `os.Stdout`, `os.Stderr`); only `cmd/devvm` calls `os.Exit`; only `internal/ui` and `cmd/devvm` make a context (`context.Background`, `context.TODO`), every other function takes its caller's |
|
||||
| depguard | the allowed modules; `internal/proxy` uses only the standard library; only `cmd/devvm` and `internal/cli` import `internal/ui` |
|
||||
| nolintlint | every `//nolint` names its linters and says why, and is still needed |
|
||||
| reassign | no package reassigns another package's variables, tests included |
|
||||
| revive | at most 100 statements or 160 lines a function (`function-length`), and a cognitive complexity of 75 (`cognitive-complexity`) |
|
||||
|
||||
A fresh context elsewhere, such as for a cleanup that outlives a canceled run, or a lookup that many requests share, takes `//nolint:forbidigo // <why>`.
|
||||
|
||||
## CLI tests
|
||||
|
||||
CLI tests are [testscript](https://pkg.go.dev/github.com/rogpeppe/go-internal/testscript) scripts in `testdata/script/*.txtar`, run by `internal/cli/script_test.go` against a freshly built `devvm`. Call it with `exec devvm …`:
|
||||
|
||||
Reference in new issue
Block a user