src/rules/style/size.bend checks
raw source on the hub · import bolt@1.57.0.0/src/rules/style/size.bend as Size
rules arity, length and depth: a def that holds more than a reader can.
Each measures one thing of a def and reports the def when the measure is
over the rule's limit, one finding on the def's name:
arity its parameters, type parameters aside (-A: Type, ~A: Data
have no lowercase name of their own): over 8
length its lines, from the def line to the line of its last token:
over 40
depth how deep its statements nest. The statements right under the def
are level 1, and a statement that opens a block (its own tokens
hold a :, as match x: and case A: do) puts the statements
under it one level down: over 6, which is a third match inside
two
A bolt.bend sets another limit with def arity_max() -> U32,
def length_max() or def depth_max().
A line an expression wraps onto is under its statement in bolt's tree but
opens no block, so it is no level. A block inside brackets (a lambda's
body) is not read.
Left alone: a law file, a proof file, and a def that is a proof (no type,
or one that returns -> {..}), as the cost rules leave them
(src/rules/calls.bend): a proof is as long as its statement needs.
The fixes are structural, and a name cannot buy them: parameters that
travel together become one value of a type; a step of a long def, or the
inner match of a deep one, becomes a helper.
The limits are where public Bend 2 code stops: 99 in 100 defs have 9
parameters or fewer, 19 lines or fewer, and nest 6 levels or fewer.
7 imports
import Base import ../../src.bend as Src import ../../finding.bend as F import ../../lazy/lazy.bend as Lazy import ../../syntax/lex.bend as Lex import ../../syntax/tree.bend as Tree import ../calls.bend as Calls
Types
type Dim source · line 35 · raw
Data
what of a def a rule measures
DArityDim
DLengthDim
DDepthDim
Definitions
def slug source · line 41 · raw
@dim:Dim -> String
the rule's slug
def limit_name source · line 51 · raw
@dim:Dim -> String
the name a bolt.bend sets the rule's limit by
def limit source · line 61 · raw
@dim:Dim -> U32
the rule's limit when no bolt.bend sets one
def most source · line 71 · raw
@+a:U32 -> @+b:U32 -> U32
the greater of two
def arity.one source · line 75 · raw
@name:String -> @+acc:U32 -> U32
one more when the parameter has a name of its own
def arity.go source · line 79 · raw
@ps:List<&2, 0xf70fc6a217b89edfba89174d2aa39455/src/syntax/tree.Node> -> @acc:U32 -> U32
how many of the parameters have a name of their own, onto acc
def arity source · line 87 · raw
@sig:0xf70fc6a217b89edfba89174d2aa39455/src/syntax/tree.Node -> U32
a def's parameters, type parameters aside
def last.close source · line 91 · raw
@close:Maybe<&2, 0xf70fc6a217b89edfba89174d2aa39455/src/syntax/lex.Tok> -> @best:U32 -> U32
a closing bracket's line, or the line so far
def last source · line 99 · raw
@n:0xf70fc6a217b89edfba89174d2aa39455/src/syntax/tree.Node -> @best:U32 -> U32
the greatest line of a token under the node, or best when it is greater
def length source · line 113 · raw
@+sig:0xf70fc6a217b89edfba89174d2aa39455/src/syntax/tree.Node -> @body:0xf70fc6a217b89edfba89174d2aa39455/src/syntax/tree.Node -> U32
a def's lines: from its first line to the line of its last token
def depth.under source · line 119 · raw
@opens:Bool -> @at:U32 -> U32
the level the statements under a statement sit at: one down when it opens a block
def depth source · line 128 · raw
@n:0xf70fc6a217b89edfba89174d2aa39455/src/syntax/tree.Node -> @+at:U32 -> @best:U32 -> U32
the deepest level of a statement among these, which sit at level at, or
best when it is deeper
def measure source · line 138 · raw
@dim:Dim -> @sig:0xf70fc6a217b89edfba89174d2aa39455/src/syntax/tree.Node -> @body:0xf70fc6a217b89edfba89174d2aa39455/src/syntax/tree.Node -> U32
what a rule measures of a def
def say source · line 148 · raw
@dim:Dim -> @+name:String -> @size:U32 -> @max:U32 -> String
what a finding says
def found source · line 161 · raw
@hit:Bool -> @+dim:Dim -> @+name:String -> @line:U32 -> @size:U32 -> @max:U32 -> @path:String -> @more:List<&2, 0xf70fc6a217b89edfba89174d2aa39455/src/finding.Finding> -> List<&2, 0xf70fc6a217b89edfba89174d2aa39455/src/finding.Finding>
a finding on the def's name when it is over, before the rest
def sized source · line 178 · raw
@+dim:Dim -> @name:String -> @line:U32 -> @+size:U32 -> @+max:U32 -> @path:String -> @more:List<&2, 0xf70fc6a217b89edfba89174d2aa39455/src/finding.Finding> -> List<&2, 0xf70fc6a217b89edfba89174d2aa39455/src/finding.Finding>
a def measured against the limit
def check.go source · line 190 · raw
@ds:List<&2, 0xf70fc6a217b89edfba89174d2aa39455/src/rules/calls.Def> -> @+dim:Dim -> @+path:String -> @+max:U32 -> List<&2, 0xf70fc6a217b89edfba89174d2aa39455/src/finding.Finding>
every def over the limit, in order; an exempt def is not measured
def check source · line 200 · raw
@dim:Dim -> @s:0xf70fc6a217b89edfba89174d2aa39455/src/src.Src -> @max:U32 -> List<&2, 0xf70fc6a217b89edfba89174d2aa39455/src/finding.Finding>
a rule of the family, at a limit