Skip to content
lesiwPublic

About

An analysis.Analyzer for source lines that wrap where they should not.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

lesiw.io/linewrap

Go Reference CI Release Go Version Discord License

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.

Checks

Statement headers

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 the if keyword of the link that wrapped, and a long else body is never a header wrap.
  • switch and type switch. A wrapped tag expression, a wrapped init statement, or a wrapped x := v.(type) assignment all push the brace down and are reported at the switch keyword.
  • case clauses. Not part of the header. A case expression 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.

Usage

go get -tool lesiw.io/linewrap/cmd/linewrap
go tool linewrap ./...

About

An analysis.Analyzer for source lines that wrap where they should not.

Topics

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages