~/bend-docscommunity

layout/imports.bend checks

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

5 imports
import Base
import bend-lint-api@0.2.1.0/linter/lint.bend as Lint
import bend-lint-api@0.2.1.0/shared/lists.bend as Lists
import bend-lint-api@0.2.1.0/shared/names.bend as Names
import bend-lint-api@0.2.1.0/shared/strings.bend as Strings

Types

type Entry source · line 18 · 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 23 · 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 31 · raw

Data

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

Definitions

def is_blank source · line 36 · raw

@s:String -> Bool

Text ====

def kept source · line 49 · raw

@+line:String -> String

def comments source · line 54 · 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 63 · raw

@+s:String -> String

def add.line source · line 70 · raw

@+text:String -> @+beg:U32 -> @+end:U32 -> @at:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.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 100 · raw

@+text:String -> @at:0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.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 125 · raw

@nodes:List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.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 145 · raw

@e:Entry -> String

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

def dedupe.kept source · line 152 · 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 165 · raw

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

def dedupe source · line 171 · 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 179 · raw

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

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

def texts source · line 189 · 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 198 · raw

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

Rule ====

def judged source · line 218 · raw

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

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

def judge source · line 224 · raw

@path:String -> @text:String -> @b:Block -> List<&2, 0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Finding>

def run source · line 235 · raw

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

def rule source · line 244 · raw

0xd69a1e32f167d67a827d0d362dfcf729/linter/lint.Rule