~/bend-docscommunity

linter/lint.bend checks

raw source on the hub · import bend-lint-api@0.1.1.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.

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

Types

type Quantity source · line 22 · raw

Data

Program =======

type Span source · line 29 · raw

Data

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

type Syntax source · line 37 · 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 78 · 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 83 · 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 93 · 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 99 · 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 110 · 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 113 · raw

Data

type Declaration source · line 117 · raw

Data

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

type Above source · line 293 · 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 462 · raw

Data

Rules =====

type Operation source · line 488 · 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 495 · 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 498 · raw

Data

type Found source · line 501 · raw

Data

type Value source · line 519 · raw

Data

Options =======

type Spec source · line 526 · 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 534 · 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 564 · 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 570 · 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 Here source · line 844 · 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 854 · 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 934 · raw

Data

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

type Answer source · line 939 · raw

Data

type Step source · line 945 · raw

@-R:Type -> Type

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

type Needs source · line 1047 · 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 1054 · 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 1060 · 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 121 · 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 149 · raw

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

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

def Syntax.binder source · line 167 · raw

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

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

def Syntax.declares source · line 188 · 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 213 · raw

@node:Node -> Syntax

def Node.target source · line 219 · raw

@node:Node -> String

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

def Node.kids source · line 224 · raw

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

def Node.name source · line 230 · raw

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

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

def Node.span source · line 237 · raw

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

def Span.text source · line 244 · raw

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

def Name.namespace source · line 252 · 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 257 · 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 264 · raw

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

def Node.scrutinees source · line 274 · raw

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

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

def Node.bound source · line 278 · 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 296 · raw

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

def top source · line 366 · 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 375 · raw

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

def is_recursive source · line 384 · 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 392 · 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 399 · raw

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

def is_live source · line 423 · 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 428 · 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 440 · raw

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

def parameter source · line 457 · 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 468 · raw

@s:Severity -> String

def Severity.names source · line 479 · raw

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

def finding source · line 505 · 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 538 · 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 545 · raw

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

def Value.text source · line 552 · raw

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

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

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

def Uses.global source · line 589 · raw

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

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

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

def Uses.binder source · line 604 · raw

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

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

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

def Imported.own source · line 623 · 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 630 · raw

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

def Imported.alias source · line 637 · raw

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

def Imported.add source · line 648 · raw

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

def Imported.of source · line 656 · raw

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

def Declarations.namespace source · line 668 · 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 682 · 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 689 · raw

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

def Declarations.declared source · line 703 · raw

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

def Declarations.node source · line 722 · 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 746 · 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 784 · 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 801 · raw

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

def Declarations.of source · line 815 · 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 822 · raw

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

def Source.is_own source · line 833 · raw

@source:Source -> Bool

def Program.own source · line 839 · raw

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

The program's own files: not hub packages.

def Here.of source · line 863 · 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 870 · 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 876 · raw

@here:Here -> String

def Here.namespace source · line 882 · raw

@here:Here -> String

"" for the checked file.

def Here.text source · line 887 · raw

@here:Here -> String

def Here.nodes source · line 893 · raw

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

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

def Here.sources source · line 899 · raw

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

Every file of the check, hub packages too.

def Here.declarations source · line 904 · raw

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

def Here.option source · line 910 · raw

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

The config's value, or the default.

def Whole.declarations source · line 915 · raw

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

def Whole.sources source · line 920 · raw

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

def Whole.option source · line 925 · raw

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

def Ask source · line 951 · 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 954 · raw

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

def Ask.bind source · line 957 · raw

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

def ask.step source · line 960 · raw

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

def ask source · line 968 · 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 971 · raw

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

def Answer.text source · line 974 · raw

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

def Answer.same source · line 981 · raw

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

def Answer.type source · line 989 · 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 996 · raw

@t:TypeRef -> Ask(String)

def same source · line 1004 · raw

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

def normal source · line 1012 · raw

@+t:TypeRef -> Ask(TypeRef)

def Question.shows source · line 1020 · raw

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

def Answer.texts source · line 1027 · raw

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

def show_all source · line 1037 · 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 303 · 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 334 · 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 344 · 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.