~/bend-docscommunity

vendor/lint.bend relies on unsafe/foreign

raw source on the hub · import bend-lint-pack@0.1.1.0/vendor/lint.bend as Lint

The contract between bend-lint and a rule written in Bend. A rule file imports this file and defines:

def id() -> String: # namespace/name, the code of its findings def facts() -> Lint.Want: # Lint.NoFacts{}, or the facts it needs def run(input: Lint.Input) -> IO(List<&2, Lint.Diag>): def main() -> IO(Unit): Lint.serve(run)

A rule with facts reads them one at a time, with fold_facts or next_fact. Offsets count characters (code points) from the start of a file. The rule's options come from bend-lint.json; read them with option_number, option_flag and option_text, each with a default.

1 import
import Base

Types

type Fact source · line 18 · raw

Data

A checked term, a type, and a node of a checked body: indexes into bend-lint's tables for one run. Only the effects below read them.

type Term source · line 21 · raw

Data

type Node source · line 24 · raw

Data

type Source source · line 27 · raw

Data

type Value source · line 31 · raw

Data

An option's value: a whole number (a U32), a boolean, or text.

type Option source · line 36 · raw

Data

type Input source · line 39 · raw

Data

type Scope source · line 43 · raw

Data

File: facts of the linted file. Program: of its imports too, never Base.

type Want source · line 51 · raw

Data

The facts a rule needs. A fact must match each list; an empty list matches all. kinds: the term's kind, annotations stripped (Var, Ref, App, ...). defs: the def whose body holds the term (a template's instances count as the template). names: the name a Var or Ref points to.

type Span source · line 55 · raw

Data

type Severity source · line 58 · raw

Data

type Applicability source · line 65 · raw

Data

Safe keeps behavior; Suggested may change it; Dangerous may break code.

type Edit source · line 70 · raw

Data

type Fix source · line 73 · raw

Data

type Diag source · line 76 · raw

Data

type Quantity source · line 80 · raw

Data

How many times a term may be used.

type Use source · line 85 · raw

Data

type View source · line 93 · raw

Data

A fact as bend-lint sees it: the def it is in, whether that def is a template instance, the kind of its term once an annotation is stripped (Var, App, ...), the name a Var or Ref points to (else ""), how many times the term is demanded, and the spans of the checked term and of the stripped one.

type Shape source · line 98 · raw

Data

A node: its kind, annotations kept (Ann, Var, App, ...), the name a Var or Ref points to (else ""), its span, and its children, in bend's order.

Definitions

def pick source · line 174 · raw

@hit:Bool -> @v:Value -> @later:Maybe<&2, Value> -> Maybe<&2, Value>

def find source · line 182 · raw

@opts:List<&2, Option> -> @+key:String -> Maybe<&2, Value>

The value of an option, if it is given.

def option_number_or source · line 189 · raw

@m:Maybe<&2, Value> -> @default:U32 -> U32

def option_number source · line 201 · raw

@opts:List<&2, Option> -> @key:String -> @default:U32 -> U32

An option's value, or default when it is not given or of another type.

def option_flag_or source · line 204 · raw

@m:Maybe<&2, Value> -> @default:Bool -> Bool

def option_flag source · line 215 · raw

@opts:List<&2, Option> -> @key:String -> @default:Bool -> Bool

def option_text_or source · line 218 · raw

@m:Maybe<&2, Value> -> @default:String -> String

def option_text source · line 229 · raw

@opts:List<&2, Option> -> @key:String -> @default:String -> String

def serve source · line 232 · raw

@run:(@_:Input -> IO(List<&2, Diag>)) -> IO(Unit)

Templates

template fold_next source · line 112 · raw

@-A:Type -> @-step:(@_:A -> @+f:Fact -> IO(A)) -> @m:Maybe<&2, Fact> -> @acc:A -> @again:(@_:A -> IO(A)) -> IO(A)

One step of fold_facts: stop at None{}, else run step and go on.

Effects (foreign code)

effect input source · line 101 · raw

IO(Input)

foreign: vendor/effects.js

effect report source · line 104 · raw

@diags:List<&2, Diag> -> IO(Unit)

foreign: vendor/effects.js

effect next_fact source · line 108 · raw

IO(Maybe<&2, Fact>)

The next fact the rule asked for, or None{} when none are left.

foreign: vendor/effects.js

effect view source · line 128 · raw

@fact:Fact -> IO(View)

foreign: vendor/effects.js

effect type_of source · line 132 · raw

@fact:Fact -> IO(Term)

The type the fact's term was checked against, or inferred.

foreign: vendor/effects.js

effect binder source · line 136 · raw

@fact:Fact -> IO(Maybe<&2, Term>)

The type of the binder a Var fact refers to.

foreign: vendor/effects.js

effect same source · line 141 · raw

@fact:Fact -> @a:Term -> @b:Term -> IO(Bool)

Whether two types are equal, as the checker compares them in the fact's scope.

foreign: vendor/effects.js

effect show source · line 144 · raw

@fact:Fact -> @t:Term -> IO(String)

foreign: vendor/effects.js

effect normal source · line 148 · raw

@fact:Fact -> @t:Term -> IO(Term)

The normal form of a type, in the fact's scope.

foreign: vendor/effects.js

effect uses source · line 152 · raw

@fact:Fact -> IO(List<&2, Use>)

The variables the fact's term uses, each with how many times.

foreign: vendor/effects.js

effect text source · line 156 · raw

@span:Span -> IO(String)

The text under a span, in the file on disk.

foreign: vendor/effects.js

effect body source · line 160 · raw

@name:String -> IO(Maybe<&2, Node>)

A def's checked body, if it has one.

foreign: vendor/effects.js

effect node source · line 164 · raw

@fact:Fact -> IO(Node)

The node a fact is about.

foreign: vendor/effects.js

effect shape source · line 167 · raw

@n:Node -> IO(Shape)

foreign: vendor/effects.js

effect fact source · line 171 · raw

@n:Node -> IO(Maybe<&2, Fact>)

The node's fact, if the rule asked for it.

foreign: vendor/effects.js

Unsafe

unsafe fold_facts source · line 123 · raw

@-A:Type -> @-step:(@_:A -> @+f:Fact -> IO(A)) -> @acc:A -> IO(A)

Runs step on each fact the rule asked for, in order, from acc; step is a def, given as ~name, that takes its fact as +f. Facts come one at a time, so a big file does not build one big list.