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:
22
game/init.go
22
game/init.go
@@ -51,7 +51,8 @@ func (g *RogueGame) initPlayer() {
|
||||
// (init.c init_colors).
|
||||
func (g *RogueGame) initColors() {
|
||||
used := make([]bool, len(rainbow))
|
||||
for i := PotionKind(0); i < NumPotionTypes; i++ {
|
||||
|
||||
for i := range NumPotionTypes {
|
||||
var j int
|
||||
for {
|
||||
j = g.rnd(len(rainbow))
|
||||
@@ -59,6 +60,7 @@ func (g *RogueGame) initColors() {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
used[j] = true
|
||||
g.Items.PotColors[i] = rainbow[j]
|
||||
}
|
||||
@@ -66,8 +68,9 @@ func (g *RogueGame) initColors() {
|
||||
|
||||
// initNames generates the names of the various scrolls (init.c init_names).
|
||||
func (g *RogueGame) initNames() {
|
||||
for i := ScrollKind(0); i < NumScrollTypes; i++ {
|
||||
for i := range NumScrollTypes {
|
||||
var cp strings.Builder
|
||||
|
||||
nwords := g.rnd(3) + 2
|
||||
for ; nwords > 0; nwords-- {
|
||||
nsyl := g.rnd(3) + 1
|
||||
@@ -76,10 +79,13 @@ func (g *RogueGame) initNames() {
|
||||
if cp.Len()+len(sp) > MaxNameLen {
|
||||
break
|
||||
}
|
||||
|
||||
cp.WriteString(sp)
|
||||
}
|
||||
|
||||
cp.WriteByte(' ')
|
||||
}
|
||||
|
||||
g.Items.ScrNames[i] = strings.TrimSuffix(cp.String(), " ")
|
||||
}
|
||||
}
|
||||
@@ -88,7 +94,8 @@ func (g *RogueGame) initNames() {
|
||||
// (init.c init_stones).
|
||||
func (g *RogueGame) initStones() {
|
||||
used := make([]bool, len(stoneTable))
|
||||
for i := RingKind(0); i < NumRingTypes; i++ {
|
||||
|
||||
for i := range NumRingTypes {
|
||||
var j int
|
||||
for {
|
||||
j = g.rnd(len(stoneTable))
|
||||
@@ -96,6 +103,7 @@ func (g *RogueGame) initStones() {
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
used[j] = true
|
||||
g.Items.RingStones[i] = stoneTable[j].Name
|
||||
g.Items.Rings[i].Worth += stoneTable[j].Value
|
||||
@@ -107,8 +115,10 @@ func (g *RogueGame) initStones() {
|
||||
func (g *RogueGame) initMaterials() {
|
||||
used := make([]bool, len(woods))
|
||||
metused := make([]bool, len(metals))
|
||||
for i := WandKind(0); i < NumWandTypes; i++ {
|
||||
|
||||
for i := range NumWandTypes {
|
||||
var str string
|
||||
|
||||
for {
|
||||
if g.rnd(2) == 0 {
|
||||
j := g.rnd(len(metals))
|
||||
@@ -116,6 +126,7 @@ func (g *RogueGame) initMaterials() {
|
||||
g.Items.WandType[i] = "wand"
|
||||
str = metals[j]
|
||||
metused[j] = true
|
||||
|
||||
break
|
||||
}
|
||||
} else {
|
||||
@@ -124,10 +135,12 @@ func (g *RogueGame) initMaterials() {
|
||||
g.Items.WandType[i] = "staff"
|
||||
str = woods[j]
|
||||
used[j] = true
|
||||
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g.Items.WandMade[i] = str
|
||||
}
|
||||
}
|
||||
@@ -166,5 +179,6 @@ func (g *RogueGame) pickColor(col string) string {
|
||||
if g.Player.On(Hallucinating) {
|
||||
return rainbow[g.rnd(len(rainbow))]
|
||||
}
|
||||
|
||||
return col
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user