Adopt house golangci-lint config; fix all approved-linter findings

.golangci.yml is the prompts-repo standard verbatim plus one approved
exception (paralleltest, sneak 2026-07-06). Roughly 1,500 findings
fixed:

- autofix sweep (wsl_v5/nlreturn/intrange/modernize formatting), with
  the misspell autofix REVERTED where it rewrote authentic C game text
  ("missle vanishes" stays, with nolint and a comment)
- error handling: errcheck sites get real handling — saveFile now
  closes explicitly and removes corrupt saves, scoreboard writes are
  documented best-effort, err113 sentinel errors (ErrSaveOutOfDate,
  ErrScreenTooSmall); panics allowed for unrecoverable states per
  MEMORY.md policy
- gosec: real fixes (ParseInt for SEED, 0600 scorefile) and justified
  per-line nolints for provably-bounded conversions (randomMonsterLetter
  helper collapses eight rnd(26)+'A' sites)
- API tidying from linters: pointer receivers on flag types
  (recvcheck), msg helpers renamed addmsgf/doaddf/Printwf/MvPrintwf
  (goprintffuncname), myExit()/findFloor(monst)/mkGameInput(t) drop
  always-constant params (unparam), gameEnd carries no status
- gocritic/staticcheck: if-else chains to switches, the pack.c
  inventory filter untangled into matchesFilter, main.go split so
  defers run before exit (exitAfterDefer, funlen)
- revive doc comments on all exported flag types/consts/methods

Remaining findings are confined to linters pending sneak's exception
decision (mnd, gochecknoglobals, cyclop, nestif, gocognit, exhaustive,
goconst, testpackage); TODO.md records the state. MEMORY.md added at
repo root as the project's agent working notes.
This commit is contained in:
2026-07-07 00:03:45 +02:00
parent 3ed7931676
commit 5ba9fe8f66
49 changed files with 1965 additions and 410 deletions

View File

@@ -37,26 +37,28 @@ type Window struct {
func NewWindow(rows, cols int) *Window {
w := &Window{rows: rows, cols: cols, cells: make([]cell, rows*cols)}
w.Clear()
return w
}
func (w *Window) at(y, x int) *cell { return &w.cells[y*w.cols+x] }
// Move positions the cursor (curses move/wmove).
func (w *Window) Move(y, x int) { w.cy, w.cx = y, x }
// GetYX reports the cursor position (curses getyx).
func (w *Window) GetYX() (y, x int) { return w.cy, w.cx }
func (w *Window) GetYX() (int, int) { return w.cy, w.cx }
// AddCh writes a character at the cursor and advances it (curses addch).
func (w *Window) AddCh(ch byte) {
if ch == '\n' {
w.cy, w.cx = w.cy+1, 0
return
}
if w.cy < 0 || w.cy >= w.rows || w.cx < 0 || w.cx >= w.cols {
return
}
*w.at(w.cy, w.cx) = cell{ch: ch, standout: w.standout}
if w.cx++; w.cx >= w.cols {
w.cx = 0
@@ -68,7 +70,7 @@ func (w *Window) AddCh(ch byte) {
// AddStr writes a string at the cursor (curses addstr).
func (w *Window) AddStr(s string) {
for i := 0; i < len(s); i++ {
for i := range len(s) {
w.AddCh(s[i])
}
}
@@ -85,15 +87,15 @@ func (w *Window) MvAddStr(y, x int, s string) {
w.AddStr(s)
}
// Printw writes formatted text at the cursor (curses printw).
func (w *Window) Printw(format string, a ...any) {
// Printwf writes formatted text at the cursor (curses printw).
func (w *Window) Printwf(format string, a ...any) {
w.AddStr(fmt.Sprintf(format, a...))
}
// MvPrintw moves then writes formatted text (curses mvprintw).
func (w *Window) MvPrintw(y, x int, format string, a ...any) {
// MvPrintwf moves then writes formatted text (curses mvprintw).
func (w *Window) MvPrintwf(y, x int, format string, a ...any) {
w.Move(y, x)
w.Printw(format, a...)
w.Printwf(format, a...)
}
// Inch returns the character under the cursor (curses inch, sans
@@ -102,12 +104,14 @@ func (w *Window) Inch() byte {
if w.cy < 0 || w.cy >= w.rows || w.cx < 0 || w.cx >= w.cols {
return ' '
}
return w.at(w.cy, w.cx).ch
}
// MvInch moves then reads (curses mvinch).
func (w *Window) MvInch(y, x int) byte {
w.Move(y, x)
return w.Inch()
}
@@ -120,6 +124,7 @@ func (w *Window) Clear() {
for i := range w.cells {
w.cells[i] = cell{ch: ' '}
}
w.cy, w.cx = 0, 0
}
@@ -128,6 +133,7 @@ func (w *Window) Clrtoeol() {
if w.cy < 0 || w.cy >= w.rows {
return
}
for x := w.cx; x < w.cols; x++ {
*w.at(w.cy, x) = cell{ch: ' '}
}
@@ -138,13 +144,14 @@ func (w *Window) CopyFrom(src *Window) {
copy(w.cells, src.cells)
}
// Size reports the window dimensions.
func (w *Window) Size() (rows, cols int) { return w.rows, w.cols }
// Size reports the window dimensions as rows, columns.
func (w *Window) Size() (int, int) { return w.rows, w.cols }
// CellAt reports the character and standout attribute at a position; used
// by Terminal implementations to render the window.
func (w *Window) CellAt(y, x int) (ch byte, standout bool) {
func (w *Window) CellAt(y, x int) (byte, bool) {
c := w.at(y, x)
return c.ch, c.standout
}
@@ -155,6 +162,7 @@ func (w *Window) Contents() []byte {
for i, c := range w.cells {
out[i] = c.ch
}
return out
}
@@ -171,12 +179,16 @@ func (w *Window) SetContents(data []byte) {
// victory screens.
func (w *Window) Line(y int) string {
buf := make([]byte, w.cols)
for x := 0; x < w.cols; x++ {
for x := range w.cols {
buf[x] = w.at(y, x).ch
}
return string(buf)
}
// at addresses the cell at (y, x) in the backing array.
func (w *Window) at(y, x int) *cell { return &w.cells[y*w.cols+x] }
// Screen bundles the two windows the game draws on with the device that
// shows them.
type Screen struct {
@@ -217,7 +229,7 @@ func (g *RogueGame) mvaddch(y, x int, c byte) { g.scr.Std.MvAddCh(y, x, c) }
func (g *RogueGame) mvaddstr(y, x int, s string) {
g.scr.Std.MvAddStr(y, x, s)
}
func (g *RogueGame) printw(f string, a ...any) { g.scr.Std.Printw(f, a...) }
func (g *RogueGame) printw(f string, a ...any) { g.scr.Std.Printwf(f, a...) }
func (g *RogueGame) inch() byte { return g.scr.Std.Inch() }
func (g *RogueGame) mvinch(y, x int) byte { return g.scr.Std.MvInch(y, x) }
func (g *RogueGame) standout() { g.scr.Std.Standout(true) }