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:
@@ -90,22 +90,29 @@ const (
|
||||
VsMagic = 3
|
||||
)
|
||||
|
||||
// Flags for rooms (rogue.h)
|
||||
// RoomFlags are the room state bits (rogue.h room flags).
|
||||
type RoomFlags int16
|
||||
|
||||
// Room state bits (rogue.h ISDARK/ISGONE/ISMAZE).
|
||||
const (
|
||||
Dark RoomFlags = 1 << iota // room is dark
|
||||
Gone // room is gone (a corridor)
|
||||
Maze // room is a maze
|
||||
)
|
||||
|
||||
func (f RoomFlags) Has(b RoomFlags) bool { return f&b != 0 }
|
||||
func (f *RoomFlags) Set(b RoomFlags) { *f |= b }
|
||||
func (f *RoomFlags) Clear(b RoomFlags) { *f &^= b }
|
||||
// Has reports whether any of the given bits are set.
|
||||
func (f *RoomFlags) Has(b RoomFlags) bool { return *f&b != 0 }
|
||||
|
||||
// Flags for objects (rogue.h)
|
||||
// Set turns the given bits on.
|
||||
func (f *RoomFlags) Set(b RoomFlags) { *f |= b }
|
||||
|
||||
// Clear turns the given bits off.
|
||||
func (f *RoomFlags) Clear(b RoomFlags) { *f &^= b }
|
||||
|
||||
// ObjFlags are the object state bits (rogue.h object flags).
|
||||
type ObjFlags int32
|
||||
|
||||
// Object state bits (rogue.h).
|
||||
const (
|
||||
Cursed ObjFlags = 1 << iota // ISCURSED: object is cursed
|
||||
Known // ISKNOW: player knows details about the object
|
||||
@@ -115,15 +122,22 @@ const (
|
||||
Protected // ISPROT: armor is permanently protected
|
||||
)
|
||||
|
||||
func (f ObjFlags) Has(b ObjFlags) bool { return f&b != 0 }
|
||||
func (f *ObjFlags) Set(b ObjFlags) { *f |= b }
|
||||
func (f *ObjFlags) Clear(b ObjFlags) { *f &^= b }
|
||||
// Has reports whether any of the given bits are set.
|
||||
func (f *ObjFlags) Has(b ObjFlags) bool { return *f&b != 0 }
|
||||
|
||||
// Flags for creatures (rogue.h). The C bit collisions are deliberate and
|
||||
// preserved: one name of each pair applies to monsters, the other to the
|
||||
// hero, and they never coexist on one creature.
|
||||
// Set turns the given bits on.
|
||||
func (f *ObjFlags) Set(b ObjFlags) { *f |= b }
|
||||
|
||||
// Clear turns the given bits off.
|
||||
func (f *ObjFlags) Clear(b ObjFlags) { *f &^= b }
|
||||
|
||||
// CreatureFlags are the creature state bits (rogue.h creature flags). The
|
||||
// C bit collisions are deliberate and preserved: one name of each pair
|
||||
// applies to monsters, the other to the hero, and they never coexist on
|
||||
// one creature.
|
||||
type CreatureFlags int32
|
||||
|
||||
// Creature state bits (rogue.h).
|
||||
const (
|
||||
CanConfuse CreatureFlags = 0o000001 // CANHUH: creature can confuse
|
||||
CanSeeInvisible CreatureFlags = 0o000002 // CANSEE: creature can see invisible creatures
|
||||
@@ -146,13 +160,20 @@ const (
|
||||
Slowed CreatureFlags = 0o100000 // ISSLOW: creature has been slowed
|
||||
)
|
||||
|
||||
func (f CreatureFlags) Has(b CreatureFlags) bool { return f&b != 0 }
|
||||
func (f *CreatureFlags) Set(b CreatureFlags) { *f |= b }
|
||||
func (f *CreatureFlags) Clear(b CreatureFlags) { *f &^= b }
|
||||
// Has reports whether any of the given bits are set.
|
||||
func (f *CreatureFlags) Has(b CreatureFlags) bool { return *f&b != 0 }
|
||||
|
||||
// Flags for the level map (rogue.h)
|
||||
// Set turns the given bits on.
|
||||
func (f *CreatureFlags) Set(b CreatureFlags) { *f |= b }
|
||||
|
||||
// Clear turns the given bits off.
|
||||
func (f *CreatureFlags) Clear(b CreatureFlags) { *f &^= b }
|
||||
|
||||
// PlaceFlags are the per-map-cell bits (rogue.h level map flags). The low
|
||||
// bits double as the passage number (FPassNum) or trap kind (FTrapMask).
|
||||
type PlaceFlags uint8
|
||||
|
||||
// Map cell bits (rogue.h).
|
||||
const (
|
||||
FPassage PlaceFlags = 0x80 // F_PASS: is a passageway
|
||||
FSeen PlaceFlags = 0x40 // have seen this spot before
|
||||
@@ -163,14 +184,20 @@ const (
|
||||
FTrapMask PlaceFlags = 0x07 // F_TMASK: trap number mask
|
||||
)
|
||||
|
||||
func (f PlaceFlags) Has(b PlaceFlags) bool { return f&b != 0 }
|
||||
func (f *PlaceFlags) Set(b PlaceFlags) { *f |= b }
|
||||
func (f *PlaceFlags) Clear(b PlaceFlags) { *f &^= b }
|
||||
// Has reports whether any of the given bits are set.
|
||||
func (f *PlaceFlags) Has(b PlaceFlags) bool { return *f&b != 0 }
|
||||
|
||||
// Set turns the given bits on.
|
||||
func (f *PlaceFlags) Set(b PlaceFlags) { *f |= b }
|
||||
|
||||
// Clear turns the given bits off.
|
||||
func (f *PlaceFlags) Clear(b PlaceFlags) { *f &^= b }
|
||||
|
||||
// TrapKind identifies a trap (rogue.h trap types). The kind is stored in
|
||||
// the low bits of a map cell's PlaceFlags (FTrapMask).
|
||||
type TrapKind int
|
||||
|
||||
// Trap kinds (rogue.h T_* constants).
|
||||
const (
|
||||
TrapDoor TrapKind = 0
|
||||
TrapArrow TrapKind = 1
|
||||
@@ -189,6 +216,7 @@ func (t TrapKind) String() string {
|
||||
if t < 0 || t >= NumTrapTypes {
|
||||
return "a bizarre trap"
|
||||
}
|
||||
|
||||
return trName[t]
|
||||
}
|
||||
|
||||
@@ -219,6 +247,7 @@ func (p PotionKind) String() string {
|
||||
if p < 0 || p >= NumPotionTypes {
|
||||
return "strange potion"
|
||||
}
|
||||
|
||||
return basePotInfo[p].Name
|
||||
}
|
||||
|
||||
@@ -253,6 +282,7 @@ func (s ScrollKind) String() string {
|
||||
if s < 0 || s >= NumScrollTypes {
|
||||
return "strange scroll"
|
||||
}
|
||||
|
||||
return baseScrInfo[s].Name
|
||||
}
|
||||
|
||||
@@ -270,15 +300,19 @@ const (
|
||||
WeaponDart
|
||||
WeaponShuriken
|
||||
WeaponSpear
|
||||
WeaponFlame // fake entry for dragon breath (ick)
|
||||
NumWeaponTypes = WeaponFlame
|
||||
WeaponFlame // fake entry for dragon breath (ick)
|
||||
)
|
||||
|
||||
// NumWeaponTypes counts the real weapons; the flame pseudo-weapon sits
|
||||
// just past them in the tables (C's MAXWEAPONS == FLAME).
|
||||
const NumWeaponTypes = WeaponFlame
|
||||
|
||||
// String returns the weapon's name ("mace", "two handed sword", ...).
|
||||
func (w WeaponKind) String() string {
|
||||
if w < 0 || w > WeaponFlame {
|
||||
return "strange weapon"
|
||||
}
|
||||
|
||||
return baseWeapInfo[w].Name
|
||||
}
|
||||
|
||||
@@ -303,6 +337,7 @@ func (a ArmorKind) String() string {
|
||||
if a < 0 || a >= NumArmorTypes {
|
||||
return "strange armor"
|
||||
}
|
||||
|
||||
return baseArmInfo[a].Name
|
||||
}
|
||||
|
||||
@@ -333,6 +368,7 @@ func (r RingKind) String() string {
|
||||
if r < 0 || r >= NumRingTypes {
|
||||
return "strange ring"
|
||||
}
|
||||
|
||||
return baseRingInfo[r].Name
|
||||
}
|
||||
|
||||
@@ -363,6 +399,7 @@ func (w WandKind) String() string {
|
||||
if w < 0 || w >= NumWandTypes {
|
||||
return "strange stick"
|
||||
}
|
||||
|
||||
return baseWsInfo[w].Name
|
||||
}
|
||||
|
||||
@@ -425,6 +462,7 @@ func CTRL(c byte) byte { return c & 0o37 }
|
||||
func distance(y1, x1, y2, x2 int) int {
|
||||
dx := x2 - x1
|
||||
dy := y2 - y1
|
||||
|
||||
return dx*dx + dy*dy
|
||||
}
|
||||
|
||||
@@ -439,5 +477,6 @@ func sign(nm int) int {
|
||||
case nm > 0:
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user