src/rules/style/wrap.bend checks
raw source on the hub · import 0x013e0f9a479bbebad5ed196725eede95/src/rules/style/wrap.bend as Wrap
rule wrap: how a def header breaks. A one-line header wider than 120 must
break; the width is the header through its :, counted the way space
counts a line (a string literal is two characters), a comment counting
none. A header breaks when a newline token of its own sits in it: a line
break inside a string literal is the string's. A one-line header that
fits stays one line however many parameters it has. A header that breaks
puts ( at the end of the first line and one parameter on each following
line, then ) and the return type on a line of their own after the last
parameter. Several parameters on a line, a parameter left on the (
line, a parameter split across lines, a ) on the last parameter's line
(bb: U32) -> U32:), a ) with no -> right after it on its line (the
return type on a line of its own, ) then -> U32:; a def that fills a
law has no return type, and ): is its end), or a parameter list
with no parameter in it (def none( then ) -> U32:, which fits on one
line), is a finding. A comment after the header's : is not part of the
header: def u(aa: U32) -> U32: # note is a one-line header.
7 imports
import Base import ../../src.bend as Src import ../../finding.bend as F import ../../syntax/lex.bend as Lex import ../../syntax/outline.bend as Outline import ../../lazy/lazy.bend as Lazy import ./space.bend as Space
Types
type Span source · line 26 · raw
Data
where one parameter sits in the header: its first line, its last, its column
Span@line:U32 -> @end:U32 -> @col:U32 -> Span
type Phase source · line 31 · raw
Data
seeking the parameter list, inside it, just past its ), past a ->
right after it on its line, or past anything else after it
SeekPhase
ArgsPhase
PastPhase
ShutPhase
LoosePhase
type Act source · line 39 · raw
Data
what a token does to the bracket depths
AOpenAct
AParenAct
AEndAct
AUnparenAct
ABrackAct
AUnbrackAct
ABraceAct
AUnbraceAct
AAngleAct
AUnangleAct
ACommaAct
AArrowAct
AStrayAct
ANoneAct
type Walk source · line 57 · raw
Data
the walk: depths, where the list's ) sat, the ( line, and the parameter
open so far (spans reversed)
Walk@mode:Phase -> @paren:U32 -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @shut:Span -> @open:U32 -> @on:Bool -> @pline:U32 -> @pend:U32 -> @pcol:U32 -> @spans:List<&2, Span> -> Walk
Definitions
def check.broken source · line 62 · raw
@toks:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok> -> Bool
the header already breaks across lines: some token of it is a newline
def check.cost source · line 70 · raw
@kd:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> U32
one token's share of the header's width: a comment has none
def check.add source · line 78 · raw
@+acc:U32 -> @kd:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> U32
the width so far, with one token's share added
def check.is_colon source · line 82 · raw
@kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> Bool
a : token?
def check.width.go source · line 92 · raw
@toks:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok> -> @+acc:U32 -> @+upto:U32 -> @+seen:Bool -> U32
the header's width through its last : (upto, once seen says there was
one), else its whole width, a string literal counting as two and a
comment none
def check.width source · line 102 · raw
@toks:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok> -> U32
the header's width, through its :: a comment after it does not count
def check.start source · line 106 · raw
Walk
a fresh walk, before the parameter list
def check.is_oparen source · line 110 · raw
@kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> Bool
(
def check.is_cparen source · line 118 · raw
@kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> Bool
)
def check.open_text source · line 126 · raw
@+tx:String -> Act
an opening bracket, as the depth it raises; ANone when it is not one
def check.on_open source · line 132 · raw
@kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> Act
an opening bracket, as the depth it raises
def check.close_text source · line 140 · raw
@+tx:String -> Act
a closing bracket, as the depth it lowers; ANone when it is not one
def check.on_close source · line 146 · raw
@kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> Act
a closing bracket, as the depth it lowers
def check.is_op source · line 154 · raw
@kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> Bool
an operator token
def check.gt_chars source · line 162 · raw
@cs:List<&2, Char> -> Bool
every char a >
def check.all_gt source · line 170 · raw
@+tx:String -> Bool
the text is a non-empty run of >
def check.gt_count source · line 174 · raw
@cs:List<&2, Char> -> Nat
how many > a run holds
def check.ticks_of source · line 183 · raw
@+tx:String -> Nat
the angle-closes in the text, else none
def check.opens_angle source · line 187 · raw
@glued:Bool -> @+tx:String -> Bool
< or <& glued to a name opens type arguments
def check.drop_close source · line 191 · raw
@_closed:Act -> Act
an angle close, discarded when an angle open already won
def check.prefer_open source · line 195 · raw
@opens:Bool -> @closed:Act -> Act
an angle open wins over a close; otherwise the close stands
def check.op_angle source · line 203 · raw
@+tx:String -> @glued:Bool -> Act
> runs close angles; < glued to a name opens one
def check.no_angle source · line 208 · raw
@_tx:String -> @_glued:Bool -> Act
not an operator: no angle motion
def check.angle_op source · line 212 · raw
@is_op:Bool -> @+tx:String -> @glued:Bool -> Act
an operator's angle motion
def check.angle_act source · line 220 · raw
@kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> @glued:Bool -> Act
angle motion, when the token is an operator
def check.keep source · line 224 · raw
@act:Act -> @_kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @_tx:String -> @_glued:Bool -> Act
a value used only so a branch can name it
def check.or_angle source · line 228 · raw
@closed:Act -> @kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> @glued:Bool -> Act
angle motion when the token was not a bracket, else that bracket
def check.or_close source · line 236 · raw
@opened:Act -> @+kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> @glued:Bool -> Act
a close bracket, else angle motion
def check.brackets source · line 244 · raw
@+kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> @glued:Bool -> Act
the bracket or angle motion of a token, not the parameter list's own breaks
def check.zero source · line 248 · raw
@+paren:U32 -> @+angle:U32 -> @+brace:U32 -> @+bracket:U32 -> Bool
no depth is open
def check.top source · line 254 · raw
@+paren:U32 -> @+angle:U32 -> @+brace:U32 -> @+bracket:U32 -> Bool
the top of the parameter list: one (, nothing nested
def check.pick_open source · line 260 · raw
@zero:Bool -> @rest:Act -> Act
( at depth zero opens the parameter list; a nested one is just a paren
def check.seek_open source · line 268 · raw
@is_open:Bool -> @zero:Bool -> @rest:Act -> Act
the parameter list's (, else the token's ordinary motion
def check.act_seek source · line 276 · raw
@+kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> @glued:Bool -> @+paren:U32 -> @+angle:U32 -> @+brace:U32 -> @+bracket:U32 -> Act
motion while still seeking the parameter list
def check.end_or source · line 289 · raw
@flat:Bool -> @rest:Act -> Act
) at the top of the list ends it; a nested one is just a paren
def check.args_end source · line 297 · raw
@is_close:Bool -> @flat:Bool -> @rest:Act -> Act
the parameter list's ), else the token's ordinary motion
def check.comma_or source · line 305 · raw
@flat:Bool -> @rest:Act -> Act
a comma at the top of the list separates parameters
def check.args_comma source · line 313 · raw
@is_comma:Bool -> @flat:Bool -> @rest:Act -> Act
a separating comma, else the token's ordinary motion
def check.act_args source · line 321 · raw
@+kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> @glued:Bool -> @+paren:U32 -> @+angle:U32 -> @+brace:U32 -> @+bracket:U32 -> Act
motion inside the parameter list
def check.act_done source · line 335 · raw
@_kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @_tx:String -> @_glued:Bool -> @_paren:U32 -> @_angle:U32 -> @_brace:U32 -> @_bracket:U32 -> Act
past the parameter list nothing moves
def check.is_arrow source · line 347 · raw
@kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> Bool
->
def check.act_shut source · line 356 · raw
@+kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @_tx:String -> @_glued:Bool -> @_paren:U32 -> @_angle:U32 -> @_brace:U32 -> @_bracket:U32 -> Act
right after the list's ), a ->, or the : of a header with no return
type (a def that fills a law), or anything else
def check.act source · line 368 · raw
@ph:Phase -> @kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.TokKind -> @+tx:String -> @glued:Bool -> @+paren:U32 -> @+angle:U32 -> @+brace:U32 -> @+bracket:U32 -> Act
the motion of one token
def check.is_sep source · line 391 · raw
@act:Act -> Bool
the parameter list's own (, ) and commas are not part of a parameter
def check.dec_u source · line 403 · raw
@+nn:U32 -> U32
one less, and not below zero
def check.sub source · line 407 · raw
@left:Nat -> @+angle:U32 -> U32
left angle-closes applied to the depth, and not below zero
def check.no_span source · line 415 · raw
@_pline:U32 -> @_pend:U32 -> @_pcol:U32 -> @spans:List<&2, Span> -> List<&2, Span>
a parameter that did start, onto the list
def check.cons source · line 419 · raw
@on:Bool -> @+pline:U32 -> @+pend:U32 -> @+pcol:U32 -> @spans:List<&2, Span> -> List<&2, Span>
the open parameter, closed onto the list
def check.rebuild source · line 427 · raw
@_ticks:Nat -> @mode:Phase -> @paren:U32 -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @shut:Span -> @open:U32 -> @on:Bool -> @pline:U32 -> @pend:U32 -> @pcol:U32 -> @spans:List<&2, Span> -> Walk
the walk rebuilt; angle-closes are applied by the caller
def check.opened source · line 445 · raw
@ticks:Nat -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @spans:List<&2, Span> -> @+ln:U32 -> @_mode:Phase -> @_paren:U32 -> @_shut:Span -> @_open:U32 -> @_on:Bool -> @_pline:U32 -> @_pend:U32 -> @_pcol:U32 -> Walk
( opens the parameter list
def check.ended source · line 464 · raw
@ticks:Nat -> @_mode:Phase -> @paren:U32 -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @_shut:Span -> @open:U32 -> @on:Bool -> @pline:U32 -> @pend:U32 -> @pcol:U32 -> @spans:List<&2, Span> -> @+ln:U32 -> @cl:U32 -> Walk
) ends the parameter list, and notes where it sits
def check.commaed source · line 485 · raw
@ticks:Nat -> @mode:Phase -> @paren:U32 -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @shut:Span -> @open:U32 -> @on:Bool -> @pline:U32 -> @pend:U32 -> @pcol:U32 -> @spans:List<&2, Span> -> Walk
a comma closes the parameter that was open
def check.unangled source · line 504 · raw
@ticks:Nat -> @mode:Phase -> @paren:U32 -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @shut:Span -> @open:U32 -> @on:Bool -> @pline:U32 -> @pend:U32 -> @pcol:U32 -> @spans:List<&2, Span> -> Walk
a run of > lowers the angle depth
def check.turn source · line 522 · raw
@+ln:U32 -> @shut:Span -> Phase
a -> on the ) line puts the return type there; on a later line it does not
def check.apply_on source · line 527 · raw
@motion:Act -> @mode:Phase -> @paren:U32 -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @+shut:Span -> @open:U32 -> @on:Bool -> @pline:U32 -> @pend:U32 -> @pcol:U32 -> @spans:List<&2, Span> -> @+ln:U32 -> @cl:U32 -> @ticks:Nat -> Walk
the token's motion applied to fields already taken off the walk
def check.apply source · line 576 · raw
@motion:Act -> @wk:Walk -> @+ln:U32 -> @cl:U32 -> @ticks:Nat -> Walk
the token's motion applied to the walk
def check.note_extend source · line 581 · raw
@+pline:U32 -> @_pend:U32 -> @+pcol:U32 -> @+ln:U32 -> @_cl:U32 -> @mode:Phase -> @paren:U32 -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @shut:Span -> @open:U32 -> @spans:List<&2, Span> -> Walk
the same parameter, extended to this line
def check.note_begin source · line 599 · raw
@_pline:U32 -> @_pend:U32 -> @_pcol:U32 -> @+ln:U32 -> @+cl:U32 -> @mode:Phase -> @paren:U32 -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @shut:Span -> @open:U32 -> @spans:List<&2, Span> -> Walk
a parameter starting here
def check.note_on source · line 617 · raw
@on:Bool -> @mode:Phase -> @paren:U32 -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @shut:Span -> @open:U32 -> @pline:U32 -> @pend:U32 -> @pcol:U32 -> @spans:List<&2, Span> -> @+ln:U32 -> @+cl:U32 -> Walk
the token continues the open parameter, or starts one
def check.note_skip source · line 640 · raw
@on:Bool -> @mode:Phase -> @paren:U32 -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @shut:Span -> @open:U32 -> @pline:U32 -> @pend:U32 -> @pcol:U32 -> @spans:List<&2, Span> -> @_tok:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok -> Walk
outside the parameter list the token starts nothing
def check.note_here source · line 658 · raw
@on:Bool -> @mode:Phase -> @paren:U32 -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @shut:Span -> @open:U32 -> @pline:U32 -> @pend:U32 -> @pcol:U32 -> @spans:List<&2, Span> -> @tok:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok -> Walk
inside the parameter list, the token's position joins the open parameter
def check.note_phase source · line 677 · raw
@mode:Phase -> @on:Bool -> @paren:U32 -> @bracket:U32 -> @brace:U32 -> @angle:U32 -> @shut:Span -> @open:U32 -> @pline:U32 -> @pend:U32 -> @pcol:U32 -> @spans:List<&2, Span> -> @tok:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok -> Walk
inside the list the token is part of a parameter; outside it is not
def check.note_args source · line 699 · raw
@wk:Walk -> @tok:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok -> Walk
a token that belongs to a parameter notes where that parameter sits
def check.drop_tok source · line 704 · raw
@_tok:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok -> @wk:Walk -> Walk
a token the parameter list itself consumed
def check.maybe_note source · line 708 · raw
@sep:Bool -> @wk:Walk -> @tok:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok -> Walk
note the token when it is part of a parameter
def check.step_hit source · line 716 · raw
@+wk:Walk -> @+tok:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok -> @glued:Bool -> Walk
one significant token
def check.step_skip source · line 723 · raw
@_tok:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok -> @wk:Walk -> @_glued:Bool -> Walk
a space, a newline or a comment changes nothing
def check.step_on source · line 727 · raw
@sig:Bool -> @+tok:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok -> @wk:Walk -> @glued:Bool -> Walk
a significant token is read; a space, a newline or a comment is not
def check.step source · line 735 · raw
@+tok:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok -> @wk:Walk -> @glued:Bool -> Walk
one token of the header
def check.seal source · line 740 · raw
@wk:Walk -> Walk
the parameter still open at the end of the header
def check.glue_of source · line 745 · raw
@tok:0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok -> Bool
a name glues a following <
def check.walk source · line 750 · raw
@toks:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok> -> @wk:Walk -> @glued:Bool -> Walk
every token of the header
def check.bad source · line 766 · raw
@sp:Span -> @+open:U32 -> @spans:List<&2, Span> -> Bool
split across lines, sitting on the ( line, or sharing its line
def check.judge source · line 772 · raw
@spans:List<&2, Span> -> @+open:U32 -> Maybe<&2, Span>
the first parameter that is not alone on its own line
def check.jam_span source · line 780 · raw
@wk:Walk -> Maybe<&2, Span>
the first parameter that breaks the shape, in source order
def check.tight source · line 785 · raw
@spans:List<&2, Span> -> @+close:U32 -> Bool
the last parameter (the head: spans are reversed) runs onto the ) line
def check.shut_at source · line 793 · raw
@shut:Span -> @spans:List<&2, Span> -> Maybe<&2, Span>
the ), when it shares the last parameter's line
def check.shut_span source · line 799 · raw
@wk:Walk -> Maybe<&2, Span>
the ) of a list that did close, when it is not on a line after the last
parameter
def check.loose_span source · line 810 · raw
@wk:Walk -> Maybe<&2, Span>
the ) with no -> right after it on its line
def check.none_at source · line 821 · raw
@spans:List<&2, Span> -> @+open:U32 -> Maybe<&2, Span>
the ( line, when the list holds no parameter
def check.empty_span source · line 829 · raw
@wk:Walk -> Maybe<&2, Span>
a parameter list that opened and holds no parameter
def check.place_loose source · line 838 · raw
@mm:Maybe<&2, Span> -> @+base:U32 -> @+path:String -> @+more:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding> -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>
the return type off the ) line, as a finding
def check.place_shut source · line 854 · raw
@mm:Maybe<&2, Span> -> @loose:Maybe<&2, Span> -> @+base:U32 -> @+path:String -> @+more:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding> -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>
the ) on the last parameter's line, as a finding, else the return type
off the ) line
def check.place_empty source · line 870 · raw
@mm:Maybe<&2, Span> -> @shut:Maybe<&2, Span> -> @loose:Maybe<&2, Span> -> @+base:U32 -> @+path:String -> @+more:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding> -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>
an empty parameter list across lines, as a finding, else a misplaced )
def check.place source · line 888 · raw
@mm:Maybe<&2, Span> -> @empty:Maybe<&2, Span> -> @shut:Maybe<&2, Span> -> @loose:Maybe<&2, Span> -> @+base:U32 -> @+path:String -> @+more:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding> -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>
the parameter that breaks the shape, else an empty list, a misplaced ) or
a return type off its line, as a finding on the header's lines
def check.jam source · line 907 · raw
@+line:U32 -> @toks:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok> -> @+path:String -> @+more:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding> -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>
a multi-line header that is not one parameter per line, holds no parameter,
or whose ) shares the last parameter's line or has no -> after it
def check.wide source · line 912 · raw
@+line:U32 -> @toks:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok> -> @+path:String -> @+more:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding> -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>
a one-line header past 120
def check.header source · line 918 · raw
@multi:Bool -> @+line:U32 -> @toks:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok> -> @+path:String -> @+more:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding> -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>
a broken header is judged by its shape; a one-line header by its width
def check.lexed source · line 932 · raw
@+line:U32 -> @+toks:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/lex.Tok> -> @+path:String -> @+more:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding> -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>
a def header's tokens, judged
def check.one source · line 936 · raw
@kk:0x013e0f9a479bbebad5ed196725eede95/src/syntax/outline.ItemKind -> @+line:U32 -> @+sig:String -> @+path:String -> @+more:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding> -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>
a def header; anything else is not this rule's
def check.go source · line 947 · raw
@items:List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/syntax/outline.Item> -> @+path:String -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>
every def header of the file
def check source · line 956 · raw
@ss:0x013e0f9a479bbebad5ed196725eede95/src/src.Src -> List<&2, 0x013e0f9a479bbebad5ed196725eede95/src/finding.Finding>
the rule