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:
40
game/io.go
40
game/io.go
@@ -31,16 +31,18 @@ func (g *RogueGame) msg(format string, a ...any) int {
|
||||
g.move(0, 0)
|
||||
g.clrtoeol()
|
||||
g.Msgs.Mpos = 0
|
||||
|
||||
return ^Escape
|
||||
}
|
||||
// otherwise add to the message and flush it out
|
||||
g.doadd(format, a...)
|
||||
g.doaddf(format, a...)
|
||||
|
||||
return g.endmsg()
|
||||
}
|
||||
|
||||
// addmsg adds things to the current message (io.c addmsg).
|
||||
func (g *RogueGame) addmsg(format string, a ...any) {
|
||||
g.doadd(format, a...)
|
||||
// addmsgf adds things to the current message (io.c addmsg).
|
||||
func (g *RogueGame) addmsgf(format string, a ...any) {
|
||||
g.doaddf(format, a...)
|
||||
}
|
||||
|
||||
// endmsg displays a new msg, giving the player a chance to see the previous
|
||||
@@ -50,10 +52,12 @@ func (g *RogueGame) endmsg() int {
|
||||
if m.SaveMsg {
|
||||
m.Huh = m.buf.String()
|
||||
}
|
||||
|
||||
if m.Mpos != 0 {
|
||||
g.look(false)
|
||||
g.mvaddstr(0, m.Mpos, "--More--")
|
||||
g.refresh()
|
||||
|
||||
if !m.MsgEsc {
|
||||
g.waitFor(' ')
|
||||
} else {
|
||||
@@ -62,10 +66,12 @@ func (g *RogueGame) endmsg() int {
|
||||
if ch == ' ' {
|
||||
break
|
||||
}
|
||||
|
||||
if ch == Escape {
|
||||
m.buf.Reset()
|
||||
m.Mpos = 0
|
||||
m.newpos = 0
|
||||
|
||||
return Escape
|
||||
}
|
||||
}
|
||||
@@ -75,25 +81,30 @@ func (g *RogueGame) endmsg() int {
|
||||
// with a pack addressing character
|
||||
out := m.buf.String()
|
||||
if len(out) > 0 && isLower(out[0]) && !m.LowerMsg &&
|
||||
!(len(out) > 1 && out[1] == ')') {
|
||||
(len(out) <= 1 || out[1] != ')') {
|
||||
out = string(toUpper(out[0])) + out[1:]
|
||||
}
|
||||
|
||||
g.mvaddstr(0, 0, out)
|
||||
g.clrtoeol()
|
||||
|
||||
m.Mpos = m.newpos
|
||||
m.newpos = 0
|
||||
m.buf.Reset()
|
||||
g.refresh()
|
||||
|
||||
return ^Escape
|
||||
}
|
||||
|
||||
// doadd performs an add onto the message buffer (io.c doadd).
|
||||
func (g *RogueGame) doadd(format string, a ...any) {
|
||||
// doaddf performs an add onto the message buffer (io.c doadd).
|
||||
func (g *RogueGame) doaddf(format string, a ...any) {
|
||||
m := &g.Msgs
|
||||
|
||||
s := fmt.Sprintf(format, a...)
|
||||
if len(s)+m.newpos >= maxMsg {
|
||||
g.endmsg()
|
||||
}
|
||||
|
||||
m.buf.WriteString(s)
|
||||
m.newpos = m.buf.Len()
|
||||
}
|
||||
@@ -114,8 +125,10 @@ func (g *RogueGame) readchar() byte {
|
||||
ch := g.scr.term.ReadChar()
|
||||
if ch == 3 { // ^C
|
||||
g.quit(0)
|
||||
|
||||
return 27
|
||||
}
|
||||
|
||||
return ch
|
||||
}
|
||||
|
||||
@@ -146,17 +159,21 @@ func (g *RogueGame) status() {
|
||||
if p.CurArmor != nil {
|
||||
temp = p.CurArmor.ArmorClass
|
||||
}
|
||||
|
||||
if s.init && s.hp == p.Stats.HP && s.exp == p.Stats.Exp &&
|
||||
s.pur == p.Purse && s.arm == temp && s.str == p.Stats.Str &&
|
||||
s.lvl == g.Depth && s.hungry == p.HungryState && !g.StatMsg {
|
||||
return
|
||||
}
|
||||
|
||||
s.init = true
|
||||
s.arm = temp
|
||||
|
||||
oy, ox := g.scr.Std.GetYX()
|
||||
|
||||
if s.hp != p.Stats.MaxHP {
|
||||
s.hp = p.Stats.MaxHP
|
||||
|
||||
s.hpwidth = 0
|
||||
for t := p.Stats.MaxHP; t != 0; t /= 10 {
|
||||
s.hpwidth++
|
||||
@@ -183,6 +200,7 @@ func (g *RogueGame) status() {
|
||||
g.move(StatLine, 0)
|
||||
g.addstr(line)
|
||||
}
|
||||
|
||||
g.clrtoeol()
|
||||
g.move(oy, ox)
|
||||
}
|
||||
@@ -197,7 +215,11 @@ func (g *RogueGame) waitFor(ch byte) {
|
||||
}
|
||||
}
|
||||
}
|
||||
for g.readchar() != ch {
|
||||
|
||||
for {
|
||||
if g.readchar() == ch {
|
||||
return
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -221,11 +243,13 @@ func toUpper(c byte) byte {
|
||||
if isLower(c) {
|
||||
return c - 'a' + 'A'
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
func toLower(c byte) byte {
|
||||
if isUpper(c) {
|
||||
return c - 'A' + 'a'
|
||||
}
|
||||
|
||||
return c
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user