~/bend-docscommunity

layout/imports.bend checks

raw source on the hub · import bend-lint-rules@0.3.5.0/layout/imports.bend as Imports

layout/imports: an import block out of order, with a file imported twice, or with blank lines. The order: import Base, then the other imports by written path, then by alias, by code point; a comment line stays with the import below it. Fix: writes the block in order, drops a second import of a file, and points its uses at the first one's alias. Heuristics: two imports name one file if the check loads one file for both.

4 imports
import Base
import bend-lint-api@0.3.5.0/linter/api/impl.bend as LintImpl
import bend-lint-api@0.3.5.0/linter/api/spec.bend as Lint
import bend-lint-api@0.3.5.0/shared.bend as Shared

Types

type Entry source · line 17 · raw

Data

One import: where its alias is, whether it is Base, its written path, its alias, the file it loads, and its text (the comment lines above it, then its line).

type Deduped source · line 22 · raw

Data

The imports read so far, each file's first only: the files they load, each with its alias; the imports kept (last first); and the operations that point a dropped import's uses at the kept one's alias.

type Block source · line 30 · raw

Data

The block, as written: where it starts and ends, and its imports, last first.

Definitions

def is_blank source · line 35 · raw

@s:String -> Bool

Text ====

def kept source · line 48 · raw

@+line:String -> String

def comments source · line 53 · raw

@s:String -> @line:String -> @acc:List<&2, String> -> String

The comment lines of s, a run of whole lines, each with its newline; blank lines dropped. line is the current line, last character first; acc the lines so far, last first.

def ended source · line 62 · raw

@+s:String -> String

def add.line source · line 69 · raw

@+text:String -> @+beg:U32 -> @+end:U32 -> @at:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span -> @base:Bool -> @path:String -> @alias:String -> @loads:String -> @b:Block -> Block

The import on the line from beg to end, after the block so far.

def add source · line 108 · raw

@+text:String -> @at:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span -> @base:Bool -> @path:String -> @alias:String -> @loads:String -> @b:Block -> Block

The import whose alias is at at, after the block so far.

def block source · line 133 · raw

@nodes:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Node> -> @+text:String -> @b:Block -> Block

The block of the imports among nodes. A file's imports come first, so the first node of another kind ends them.

def loads_of source · line 153 · raw

@e:Entry -> String

Duplicates and order ====================

def dedupe.kept source · line 160 · raw

@first:Maybe<&2, String> -> @e:Entry -> @d:Deduped -> Deduped

An import read, after those before it: kept, if its file has no import yet; else dropped, with its uses pointed at first, the alias of the file's first import. A second import Base has none to point: its uses are bare names.

def dedupe.add source · line 173 · raw

@+e:Entry -> @d:Deduped -> Deduped

def dedupe source · line 179 · raw

@es:List<&2, Entry> -> @d:Deduped -> Deduped

The imports of es, in order, after those of d, each file's first only.

def is_before source · line 187 · raw

@a:Entry -> @b:Entry -> Bool

Whether a may come before b: Base first, then by path, then by alias.

def texts source · line 197 · raw

@es:List<&2, Entry> -> @acc:List<&2, String> -> String

The texts of es, after acc, the texts so far, last first.

def verdict source · line 206 · raw

@same:Bool -> @+span:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span -> @ordered:String -> @renames:List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Operation> -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

Rule ====

def judged source · line 226 · raw

@span:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Span -> @written:String -> @d:Deduped -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

The block as written (written, at span), against its imports in order, each file once.

def judge source · line 232 · raw

@path:String -> @text:String -> @b:Block -> List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>

def run source · line 243 · raw

@+here:0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Here -> 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Ask(List<&2, 0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Finding>)

def rule source · line 252 · raw

0x94bdd21968f0b8ad8c1be0e7e2b606a0/linter/api/spec.Rule