Documentation
¶
Overview ¶
Command/library hookcheck is a static "rules of hooks" analyzer for GoWebComponents. It flags hooks (any Use* function, including ui.UseEvent behind an On* handler) that are not called at a stable render position:
- inside a loop (the framework's #1 gotcha, G1) — a per-row hook must live in its own component, not in a range/for over a variable-length list; and
- inside a conditional branch (an if/else body or a switch/select case body) — hooks must run unconditionally, in the same order every render.
Each finding names the offending hook and its enclosing component and proposes the specific fix. It is a compile-time check (go/ast only, no runtime cost and no x/tools dependency), so it can never destabilize the render path.
Index ¶
Constants ¶
const IgnoreDirective = "hookcheck:ignore"
IgnoreDirective suppresses a finding when present as a line comment on the hook's line or the line immediately above it — for deliberate, controlled cases (e.g. a fixed-count benchmark loop).
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Finding ¶
type Finding struct {
Pos token.Position
Hook string
Kind FindingKind
Func string
}
Finding is one rules-of-hooks violation. Pos is the source location, Hook the offending hook's name, Kind the violation category, and Func the enclosing component/function symbol (empty when the hook is in an anonymous function), so a message can name exactly where the problem is.
func CheckDir ¶
CheckDir walks root, parses every non-vendored .go file, and returns all findings sorted by position. testdata, vendor, and dot-directories are skipped.
func CheckSource ¶
CheckSource analyzes one source file given as bytes (filename is used only for positions). Returns a parse error if the source does not compile syntactically.
func (Finding) Remediation ¶
Remediation returns the specific corrective action for this finding, naming the offending hook so the fix is unambiguous (not a category-level hint).
type FindingKind ¶
type FindingKind string
FindingKind names which rules-of-hooks violation a Finding reports.
const ( // KindLoop is a hook called inside a for/range loop. KindLoop FindingKind = "loop" // KindConditional is a hook called inside a conditional branch (an if/else // body or a switch/select case body) rather than at the component's top level. KindConditional FindingKind = "conditional" )
Directories
¶
| Path | Synopsis |
|---|---|
|
cmd
|
|
|
hookcheck
command
Command hookcheck reports GoWebComponents "rules of hooks" violations: any Use* hook (including ui.UseEvent behind an On* handler) called inside a loop.
|
Command hookcheck reports GoWebComponents "rules of hooks" violations: any Use* hook (including ui.UseEvent behind an On* handler) called inside a loop. |