~/bend-docscommunity

src/rules/pedantic/foreign.bend checks

raw source on the hub · import bolt@1.67.0.0/src/rules/pedantic/foreign.bend as Foreign

rule foreign: a foreign def (its body only import "./x.c" / import "./x.js" lines, wherever its header's -> and return type fall: a header wrapped onto the next line is not part of the body, Calls.under) with a body for one lane and not the other. Each lane finds out only when it first runs: a native build (bend -o bin) fails with "no .c import", an interpreted or JS run with "a foreign def without a .js import". Give every foreign def both bodies, x.c and x.js. A file headed # lanes: native never runs on the JS lane, so it needs no .js. Headed means the exact line # lanes: native is one of the file's leading comment lines, those before its first line that does not start with #; the line anywhere later does not count.

8 imports
import Base
import ../../src.bend as Src
import ../../finding.bend as F
import ../../syntax/lex.bend as Lex
import ../../syntax/tree.bend as Tree
import ../../syntax/bind.bend as Bind
import ../../lazy/lazy.bend as Lazy
import ../calls.bend as Calls

Types

type Lanes source · line 22 · raw

Data

which lanes a foreign def's bodies cover

Definitions

def target source · line 26 · raw

@kids:0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/tree.Node -> String

the imported path of an import statement's tokens ("./x.c", quoted)

def lanes.go source · line 36 · raw

@body:0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/tree.Node -> @c:Bool -> @js:Bool -> Maybe<&2, Lanes>

the lanes of a body that is only imports; None when it is anything else

def lanes source · line 47 · raw

@body:0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/tree.Node -> Maybe<&2, Lanes>

the lanes of a def's body: None unless it is a foreign def

def lack source · line 56 · raw

@m:Maybe<&2, Lanes> -> @+native:Bool -> @+name:String -> String

what the lanes lack, as a message ("" for nothing)

def at source · line 67 · raw

@+msg:String -> @+line:U32 -> @+col:U32 -> @+path:String -> @+more:List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/finding.Finding> -> List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/finding.Finding>

a message as a finding, when there is one

def name.of source · line 71 · raw

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

a def's name, ? when it has none

def check.go source · line 78 · raw

@root:0xd1af11cb3fe9c11256ed247a0003f75f/src/syntax/tree.Node -> @+native:Bool -> @+path:String -> List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/finding.Finding>

def native_only.go source · line 88 · raw

@ls:List<&2, String> -> Bool

def native_only source · line 98 · raw

@text:String -> Bool

is the file headed # lanes: native: that exact line among the comment lines before its first line that is not a comment?

def check source · line 102 · raw

@s:0xd1af11cb3fe9c11256ed247a0003f75f/src/src.Src -> List<&2, 0xd1af11cb3fe9c11256ed247a0003f75f/src/finding.Finding>

the rule