An analysis.Analyzer for source lines that wrap where they should not.
It pairs with lesiw.io/linelen: linelen owns how long a line may be,
linewrap owns where a line may be broken.
An if, for, or switch statement keeps its header on a single
line: the opening brace of the body sits on the same physical line as
the keyword that owns it.
if err := longCall( // if header spans 3 lines, exceeds the 1-line limit
ctx, arg,
); err != nil {Hoist the value to a named variable instead.
Boundaries:
else if. Each link in a chain owns its own header. A wrap is reported at theifkeyword of the link that wrapped, and a longelsebody is never a header wrap.switchand type switch. A wrapped tag expression, a wrapped init statement, or a wrappedx := v.(type)assignment all push the brace down and are reported at theswitchkeyword.caseclauses. Not part of the header. Acaseexpression may wrap freely.- Function signatures. A wrapped signature or function literal is
not a header wrap; line length is
linelen's business. - Labels. A label does not move the report; it lands on the keyword.
- Comments. A trailing line comment sits after the brace and never affects the verdict. A block comment that pushes the brace onto a later line is reported, because the header does occupy more than one line.
- Headers that cannot fit. There is no length carve-out; hoist the value to a named variable.
go get -tool lesiw.io/linewrap/cmd/linewrap
go tool linewrap ./...