~/bend-docscommunity

linter/lint.bend checks

raw source on the hub · import bend-lint-api@0.2.0.0/linter/lint.bend as Lint

What a rule sees. A rule file imports this file, and defines rule().

Design - The rules run in an ordinary Bend program that seam.ts writes from bend-lint.json, builds once and keeps. The C lane is the target; the JS lane must work too. - Bend's checker is TS for now: seam.ts makes each check's program of what Bend's parser and checker give, and answers the questions rules ask about its types, over local TCP (see Seam in cli.bend). When the checker is Bend, glue in Bend makes the same program, and the questions become calls. - A file is a tree of syntax nodes. A rule walks it, and reads what a node is from the node and the nodes above it. - Rules are pure, so they run in parallel. The runner answers every rule's questions of a round in one batch. - A check is read once and shared by every rule. Facts and declarations are collected only if a rule needs them. - A rule requests a fix as typed operations, and the linter plans them. Until Bend's checker is Bend, no fix is proven to keep the program: --fix-dangerously makes them all, and --fix makes none.

6 imports
import Base
import ../shared/lists.bend as Lists
import ../shared/names.bend as Names
import ../shared/sets.bend as Sets
import ../shared/strings.bend as Strings
import ../shared/tables.bend as Tables

Types

type Quantity source · line 23 · raw

Data

Program =======

type Span source · line 30 · raw

Data

Where something is: its file, and offsets in code points.

type Syntax source · line 38 · raw

Data

What a syntax node is, as Bend's parser reads it: a declaration, a part of one, a term, or a pattern; with what only nodes of its kind have: the global name it declares or uses (target, as the check names it; an import's is the path of the file it loads), the binder it declares or a variable uses (numbered per top-level declaration), and its quantity as written (a ~ parameter's is Template). An import's written path is an ImportPath under it; import Base writes none. A Definition is unsafe if Bend's checker trusts its body (@unsafe def f, or def f?).

type TypeRef source · line 79 · raw

Data

A type the checker holds: a handle, good in the check it came from. Rules ask about it (show, same, normal). Two types are the same only over the binders their scopes share: A of one def is not A of another.

type Role source · line 84 · raw

Data

What a fact says of its node: the type its term has, or the type its binder declares (a parameter, field, pattern variable, lambda, forall or let binding).

type Fact source · line 94 · raw

Data

What the checker found for a node of the source: what the fact says of it, the quantity (how often the term is demanded, or the binder's), for a binder of a parameter, lambda, let or case, how often its body uses it (the most of its checked copies; none for a parameter a match takes apart), and the type. A fact is never wrong, but a node can have none: a term the checker rewrote into another (a scrutinee used again, a call a template took) is not typed as itself. A node has one fact per distinct type: pattern compilation can check one term in several branches, under different refinements.

type Node source · line 100 · raw

Data

A syntax node: what it is, its name as written, where the file writes it (none for what the parser adds), the nodes under it, in order, and the checker's facts on it, if a rule needs them. An application's nodes are its function, then its arguments; a block's, its binders, then their values, then the rest of the block.

type Source source · line 111 · raw

Data

A file the check parsed: its path, its namespace in the check ("" for the checked file), its text, and its nodes: its imports, then its declarations, each constructor under its type.

type Program source · line 114 · raw

Data

type Declaration source · line 118 · raw

Data

A name a node declares, and the nodes that use it, in order.

type Above source · line 294 · raw

Data

A node above another: the node, and the place among its nodes (from 0) of the one on the way down.

type Severity source · line 463 · raw

Data

Rules =====

type Operation source · line 489 · raw

Data

An edit a fix asks for: replace a span's text; rename what the declaration written at at declares, with each of its uses; or rename only its uses, to point them at a name the program declares already (to drop a duplicate import, say). A rename changes an import's alias, the first part of each use (U of U.two), and any other name's last part. The linter finds the uses, and drops the fix if the text does not write the name where one of them is. It drops a Rename of a global name (a def, type, constructor or law), as files the check did not read can use it, and one whose new name is taken where the declaration is.

type Fix source · line 496 · raw

Data

A way to fix a finding: what it does, and its operations, in any of the program's own files (not Base, nor a hub package).

type Finding source · line 499 · raw

Data

type Found source · line 502 · raw

Data

type Value source · line 520 · raw

Data

Options =======

type Spec source · line 527 · raw

Data

What an option accepts: a whole number in a range, a flag, text (one of choices, unless there are none), or what one of specs accepts.

type Declared source · line 535 · raw

Data

An option a rule declares: its name, its value when the config gives none, and what it accepts. The config gives values as "rule/id": {"name": value}; a name the rule does not declare, or a value it does not accept, is an error.

type Imported source · line 565 · raw

Data

What uses a file's imports: the nodes written with an alias's prefix (U.two, a fill def U.law(x):), by alias; and those that use Base: a global name with no namespace that the file does not declare (last first).

type Uses source · line 571 · raw

Data

What the declarations of a top-level declaration are read with: the program's files (one of them is what an import loads), the uses of global names in the files the declarations are read in, by name, the uses of the declaration's binders, by binder (each last first), and what uses its file's imports.

type Param source · line 847 · raw

Data

A runtime parameter of a definition: its name, and its type as one name ("" if it is not one name).

type Def source · line 852 · raw

Data

A definition of the program: its name as the check names it, its runtime parameters, whether it forks, the definitions it calls by name, and the type it returns, as one name ("" if it is not one name).

type Here source · line 1052 · raw

Data

What a file rule sees: the program, from one of its files; that file's declarations, with their uses in it, if a rule needs them; and the rule's options, each declared one with its value.

type Whole source · line 1062 · raw

Data

What a program rule sees: the program (its files, hub packages aside); every declaration of its files, with their uses in all of them, if a rule needs them; and the rule's options.

type Question source · line 1142 · raw

Data

Show spells a type as its file does; Same compares as the checker does.

type Answer source · line 1147 · raw

Data

type Step source · line 1153 · raw

@-R:Type -> Type

A run so far: finished, or waiting for the answers to its questions, in order.

type Needs source · line 1255 · raw

Data

What a rule needs collected for it, as each costs time and memory: the checker's facts, and the declarations with their uses. A rule that does not ask for them gets none.

type Run source · line 1262 · raw

Type

How a rule runs: once per linted file, reporting only in it; or once per check, on the whole program, reporting in any file (what it finds in a file that is not linted is dropped). When several entries check the named file, a program rule's finding stays if some check finds it, or, if every, if every check finds it; then, if an entry that reads the named file fails its check, the rule does not run.

type Rule source · line 1268 · raw

Type

A rule: what it needs, the options it declares, and how it runs. Its id is its path in bend-lint-rules/, without .bend, as bend-lint.json names it.

Definitions

def Syntax.target source · line 122 · raw

@syntax:Syntax -> Maybe<&2, String>

The global name a node of this kind declares or uses, if any (an import's is the file it loads).

def Syntax.used source · line 150 · raw

@syntax:Syntax -> Maybe<&2, String>

The global name a node of this kind uses, if it uses one.

def Syntax.binder source · line 168 · raw

@syntax:Syntax -> Maybe<&2, U32>

The binder a node of this kind declares, or, for a variable, uses.

def Syntax.declares source · line 189 · raw

@syntax:Syntax -> Maybe<&2, Bool>

Whether a node of this kind declares a global name (Some{True{}}), a binder of its top-level declaration (Some{False{}}), or nothing (an import declares an alias, which Declarations below handles).

def Node.syntax source · line 214 · raw

@node:Node -> Syntax

def Node.target source · line 220 · raw

@node:Node -> String

"" for a node of a kind that names nothing.

def Node.kids source · line 225 · raw

@node:Node -> List<&2, Node>

def Node.name source · line 231 · raw

@node:Maybe<&2, Node> -> String

"" for no node, as are the next two.

def Node.span source · line 238 · raw

@node:Maybe<&2, Node> -> Maybe<&2, Span>

def Span.text source · line 245 · raw

@source:String -> @span:Maybe<&2, Span> -> String

def Name.namespace source · line 253 · raw

@name:String -> String

The namespace of a global name: what comes before its first ":", or "" for Base and the checked file's own names.

def Node.is_bare source · line 258 · raw

@node:Node -> Bool

Whether a parameter is written bare (def f(x), filling a law): its quantity is the law's, which its node does not give.

def Node.scrutinees.go source · line 265 · raw

@nodes:List<&2, Node> -> @out:List<&2, Node> -> List<&2, Node>

def Node.scrutinees source · line 275 · raw

@node:Node -> List<&2, Node>

The scrutinees of a match, in order: its nodes before its first case.

def Node.bound source · line 279 · raw

@nodes:List<&2, Node> -> @out:List<&2, U32> -> List<&2, U32>

The binders of the pattern variables in nodes, patterns, and under them, onto out.

def Above.of source · line 297 · raw

@parent:Maybe<&2, Node> -> @at:U32 -> @up:List<&2, Above> -> List<&2, Above>

def top source · line 367 · raw

@path:List<&2, Above> -> @node:Node -> Node

The top-level declaration a node is in: the outermost node above it, or the node itself.

def calls source · line 376 · raw

@called:String -> @owner:Node -> Bool

def is_recursive source · line 385 · raw

@path:List<&2, Above> -> @+node:Node -> Bool

Whether a node is an application of the definition it is in, below path: a step of a loop, as Bend repeats work by recursion.

def is_pair source · line 393 · raw

@kids:List<&2, Node> -> Bool

Whether an application's function is Pair: it builds a pair type (A & B), whose parts are types.

def is_live.go source · line 400 · raw

@path:List<&2, Above> -> @ok:Bool -> Bool

def is_live source · line 424 · raw

@path:List<&2, Above> -> Bool

Whether a node below path is in live code: a definition's body, outside types: an annotation's type, an equality, a function or pair type, a type's arguments. Types and equations are dead: the checker sees them, the program does not run them.

def definitions source · line 429 · raw

@nodes:List<&2, Node> -> @out:Map<&2, Maybe<&2, Node>> -> Map<&2, Maybe<&2, Node>>

The definitions of nodes, by the name the check gives them: read one with Names.find. Of two with one name, the later is kept.

def parameter.go source · line 441 · raw

@nodes:List<&2, Node> -> @found:Maybe<&2, Nat> -> @+binder:U32 -> @+at:Nat -> Maybe<&2, Nat>

def parameter source · line 458 · raw

@nodes:List<&2, Node> -> @binder:U32 -> Maybe<&2, Nat>

Where the parameter that declares binder is among nodes, a definition's, counting from 0.

def Severity.show source · line 469 · raw

@s:Severity -> String

def Severity.names source · line 480 · raw

List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/shared/names.Named<Severity>>

def finding source · line 506 · raw

@severity:Severity -> @hit:Bool -> @span:Maybe<&2, Span> -> @text:String -> List<&2, Finding>

A finding at span, if hit and span is known.

def Value.number source · line 539 · raw

@value:Maybe<&2, Value> -> U32

An option's value as a number, a flag or text; a value of another kind, or none, gives 0, False, "".

def Value.flag source · line 546 · raw

@value:Maybe<&2, Value> -> Bool

def Value.text source · line 553 · raw

@value:Maybe<&2, Value> -> String

def Uses.global.add source · line 579 · raw

@used:Maybe<&2, String> -> @node:Node -> @m:Map<&2, List<&2, Node>> -> Map<&2, List<&2, Node>>

def Uses.global source · line 590 · raw

@+u:Unit -> @+node:Node -> @m:Map<&2, List<&2, Node>> -> Map<&2, List<&2, Node>>

def Uses.binder.add source · line 593 · raw

@+t:0xd69a1e32f167d67a827d0d362dfcf729/shared/tables.Table<List<&2, Node>> -> @+b:U32 -> @node:Node -> 0xd69a1e32f167d67a827d0d362dfcf729/shared/tables.Table<List<&2, Node>>

def Uses.binder source · line 605 · raw

@+u:Unit -> @+node:Node -> @t:0xd69a1e32f167d67a827d0d362dfcf729/shared/tables.Table<List<&2, Node>> -> 0xd69a1e32f167d67a827d0d362dfcf729/shared/tables.Table<List<&2, Node>>

def Imported.own.add source · line 616 · raw

@target:Maybe<&2, String> -> @out:Set -> Set

def Imported.own source · line 624 · raw

@nodes:List<&2, Node> -> @out:Set -> Set

The global names a file's own top-level declarations declare, as a set.

def Imported.is_base source · line 631 · raw

@own:Set -> @used:Maybe<&2, String> -> Bool

def Imported.alias source · line 638 · raw

@prefix:String -> @node:Node -> @aliases:Map<&2, List<&2, Node>> -> Map<&2, List<&2, Node>>

def Imported.add source · line 649 · raw

@+own:Set -> @+node:Node -> @uses:Imported -> Imported

def Imported.of source · line 657 · raw

@+nodes:List<&2, Node> -> Imported

def Declarations.namespace source · line 669 · raw

@sources:List<&2, Source> -> @+path:String -> @found:Maybe<&2, String> -> String

The namespace of the file at path, as the check names it (found, once found): "" for Base, or a file the check did not parse.

def Declarations.imported source · line 683 · raw

@base:Bool -> @alias:String -> @imported:Imported -> List<&2, Node>

The uses of an import, in order: of Base (base), or of its alias.

def Declarations.bound source · line 690 · raw

@binder:Maybe<&2, U32> -> @binders:0xd69a1e32f167d67a827d0d362dfcf729/shared/tables.Table<List<&2, Node>> -> List<&2, Node>

def Declarations.declared source · line 704 · raw

@declares:Maybe<&2, Bool> -> @+node:Node -> @uses:Uses -> List<&2, Declaration>

def Declarations.node source · line 723 · raw

@+uses:Uses -> @+node:Node -> @out:List<&2, Declaration> -> List<&2, Declaration>

A node's declaration, if it declares a name, with its uses, onto out.

def Declarations.tops source · line 747 · raw

@nodes:List<&2, Node> -> @+sources:List<&2, Source> -> @+globals:Map<&2, List<&2, Node>> -> @+imported:Imported -> @out:List<&2, Declaration> -> List<&2, Declaration>

def Declarations.files source · line 785 · raw

@files:List<&2, Source> -> @+sources:List<&2, Source> -> @+globals:Map<&2, List<&2, Node>> -> @out:List<&2, Declaration> -> List<&2, Declaration>

def Declarations.globals source · line 802 · raw

@files:List<&2, Source> -> @m:Map<&2, List<&2, Node>> -> Map<&2, List<&2, Node>>

def Declarations.of source · line 816 · raw

@+files:List<&2, Source> -> @sources:List<&2, Source> -> List<&2, Declaration>

The declarations of files, in order, with their uses in files; sources are the program's files.

def Declarations.when source · line 823 · raw

@declare:Bool -> @files:List<&2, Source> -> @sources:List<&2, Source> -> List<&2, Declaration>

def Source.is_own source · line 834 · raw

@source:Source -> Bool

def Program.own source · line 840 · raw

@sources:List<&2, Source> -> List<&2, Source>

The program's own files: not hub packages.

def type_name source · line 862 · raw

@nodes:List<&2, Node> -> String

The type the first of nodes writes, as one name, or "" for another form (an application, a list).

def Quantity.is_runtime source · line 870 · raw

@quantity:Quantity -> Bool

Whether a parameter of this quantity is there at run time.

def Def.params source · line 880 · raw

@nodes:List<&2, Node> -> @out:List<&2, Param> -> List<&2, Param>

The runtime parameters among a definition's nodes, in order, onto out.

def forks source · line 893 · raw

@nodes:List<&2, Node> -> @found:Bool -> Bool

Whether a parallel let (two binders, at least) is among nodes or under them, or found.

def Def.called.visit source · line 917 · raw

@+u:Unit -> @+path:List<&2, Above> -> @+node:Node -> List<&2, String>

The definition an application below path calls by name.

def Def.returned source · line 925 · raw

@nodes:List<&2, Node> -> String

The type a definition's nodes say it returns, as one name, or "".

def Def.forks source · line 934 · raw

@info:Maybe<&2, Def> -> Bool

def Program.defs.file source · line 942 · raw

@nodes:List<&2, Node> -> @out:Map<&2, Maybe<&2, Def>> -> Map<&2, Maybe<&2, Def>>

The definitions among a file's nodes, by the name the check gives them, onto out.

def Program.defs source · line 972 · raw

@sources:List<&2, Source> -> @out:Map<&2, Maybe<&2, Def>> -> Map<&2, Maybe<&2, Def>>

The definitions of the program's files, by the name the check gives them, onto out: read one with Names.find.

def Program.callers.if source · line 982 · raw

@found:Bool -> @t:String -> @callers:Set -> Set

def Program.callers.step source · line 990 · raw

@info:Maybe<&2, Def> -> @+callers:Set -> Set

callers with the definition info, if it calls one of them.

def Program.callers.file source · line 998 · raw

@nodes:List<&2, Node> -> @+defs:Map<&2, Maybe<&2, Def>> -> @callers:Set -> Set

callers after a step for each definition among a file's nodes, in order.

def Program.callers.pass source · line 1011 · raw

@sources:List<&2, Source> -> @+defs:Map<&2, Maybe<&2, Def>> -> @callers:Set -> Set

def Program.callers.go source · line 1023 · raw

@fuel:Nat -> @same:Bool -> @+sources:List<&2, Source> -> @+defs:Map<&2, Maybe<&2, Def>> -> @+callers:Set -> Set

Passes over the program until one adds nothing (same), or fuel runs out.

def Program.callers source · line 1043 · raw

@sources:List<&2, Source> -> @+defs:Map<&2, Maybe<&2, Def>> -> @seeds:Set -> Set

seeds, and the definitions of the program (defs, of sources) that call one of them, directly or through others. A definition calls only those above it, unless it is @unsafe, and the check gives a file's imports before it, so the first pass, in order, finds nearly all. Each pass but the last adds one at least, so as many passes as there are definitions find them all.

def Here.of source · line 1071 · raw

@program:Program -> @+source:Source -> @declare:Bool -> Here

The program from one of its files, built once for every file rule that runs on that file: its declarations, if a rule needs them (declare). The runner gives each rule its options.

def Whole.of source · line 1078 · raw

@program:Program -> @declare:Bool -> Whole

The whole program, built once for every program rule: the declarations of its own files, if a rule needs them (declare).

def Here.path source · line 1084 · raw

@here:Here -> String

def Here.namespace source · line 1090 · raw

@here:Here -> String

"" for the checked file.

def Here.text source · line 1095 · raw

@here:Here -> String

def Here.nodes source · line 1101 · raw

@here:Here -> List<&2, Node>

The file's nodes: its imports, then its declarations.

def Here.sources source · line 1107 · raw

@here:Here -> List<&2, Source>

Every file of the check, hub packages too.

def Here.declarations source · line 1112 · raw

@here:Here -> List<&2, Declaration>

def Here.option source · line 1118 · raw

@here:Here -> @name:String -> Maybe<&2, Value>

The config's value, or the default.

def Whole.declarations source · line 1123 · raw

@whole:Whole -> List<&2, Declaration>

def Whole.sources source · line 1128 · raw

@whole:Whole -> List<&2, Source>

def Whole.option source · line 1133 · raw

@whole:Whole -> @name:String -> Maybe<&2, Value>

def Ask source · line 1159 · raw

@-A:Type -> Type

A computation that may ask the checker, in do Lint.Ask<A>: blocks. Continuation-passing, so binding needs no recursion. A run may ask only cli.bend's budget() rounds, so ask for everything at once (show_all).

def Ask.pure source · line 1162 · raw

@-A:Type -> @x:A -> Ask(A)

def Ask.bind source · line 1165 · raw

@-A:Type -> @-B:Type -> @m:Ask(A) -> @f:(@_:A -> Ask(B)) -> Ask(B)

def ask.step source · line 1168 · raw

@-R:Type -> @questions:List<&2, Question> -> @k:(@_:List<&2, Answer> -> Step<R>) -> Step<R>

def ask source · line 1176 · raw

@questions:List<&2, Question> -> Ask(List<&2, Answer>)

The answers to questions, in order, asked in one round; none asked, no round.

def done source · line 1179 · raw

@findings:List<&2, Finding> -> Ask(List<&2, Finding>)

def Answer.text source · line 1182 · raw

@answers:List<&2, Answer> -> String

def Answer.same source · line 1189 · raw

@answers:List<&2, Answer> -> Bool

def Answer.type source · line 1197 · raw

@t:TypeRef -> @answers:List<&2, Answer> -> TypeRef

t with the handle of its normal form, if the answers give one.

def show source · line 1204 · raw

@t:TypeRef -> Ask(String)

def same source · line 1212 · raw

@a:TypeRef -> @b:TypeRef -> Ask(Bool)

def normal source · line 1220 · raw

@+t:TypeRef -> Ask(TypeRef)

def Question.shows source · line 1228 · raw

@types:List<&2, TypeRef> -> @out:List<&2, Question> -> List<&2, Question>

def Answer.texts source · line 1235 · raw

@answers:List<&2, Answer> -> @out:List<&2, String> -> List<&2, String>

def show_all source · line 1245 · raw

@types:List<&2, TypeRef> -> Ask(List<&2, String>)

How each type of types is shown, in order, asked in one round.

Templates

template visit.go source · line 304 · raw

@-C:Data -> @-A:Data -> @-f:(@+c:C -> @+path:List<&2, Above> -> @+node:Node -> List<&2, A>) -> @nodes:List<&2, Node> -> @+c:C -> @+up:List<&2, Above> -> @+parent:Maybe<&2, Node> -> @+at:U32 -> @out:List<&2, A> -> List<&2, A>

template visit source · line 335 · raw

@-C:Data -> @-A:Data -> @-f:(@+c:C -> @+path:List<&2, Above> -> @+node:Node -> List<&2, A>) -> @c:C -> @nodes:List<&2, Node> -> List<&2, A>

f(c, path, node) for each node of nodes and under them, parents first, in order: path holds the nodes above the node, innermost first.

template fold source · line 345 · raw

@-C:Data -> @-S:Data -> @-f:(@+c:C -> @+node:Node -> @_:S -> S) -> @+c:C -> @nodes:List<&2, Node> -> @s:S -> S

f(c, node, s) for each node of nodes and under them, parents first, in order, from s.