~/bend-docscommunity

layout/canon_import_path.bend checks

raw source on the hub · import bend-lint-rules@0.1.1.0/layout/canon_import_path.bend as Canon_import_path

layout/canon_import_path: an import path that is not the shortest path from the importer to the file it names, or that does not start with ./ or ../. Fix: writes the shortest path. Heuristics: it compares real paths, links resolved, so a link to a file is that file. Base and hub imports are not paths: it skips them.

3 imports
import Base
import bend-lint-api@0.1.1.0/linter/lint.bend as Lint
import bend-lint-api@0.1.1.0/shared/lists.bend as Lists

Definitions

def segments.step source · line 12 · raw

@p:String -> @acc:List<&2, String> -> List<&2, String>

Paths =====

def segments.go source · line 24 · raw

@parts:List<&2, String> -> @acc:List<&2, String> -> List<&2, String>

A path's segments, last first: "" and "." dropped, ".." applied.

def segments source · line 31 · raw

@path:String -> List<&2, String>

def ups source · line 35 · raw

@from:List<&2, String> -> @to:List<&2, String> -> List<&2, String>

Each segment of from as "..", then to.

def is_same_head source · line 43 · raw

@from:List<&2, String> -> @to:List<&2, String> -> Bool

Whether both lists start with the same segment.

def relative.go source · line 50 · raw

@from:List<&2, String> -> @to:List<&2, String> -> @same:Bool -> List<&2, String>

def relative source · line 58 · raw

@+from:List<&2, String> -> @+to:List<&2, String> -> List<&2, String>

The segments that lead from the folder from to to.

def canon source · line 62 · raw

@+parts:List<&2, String> -> String

The segments as a path that starts with ./ or ../.

def is_hub source · line 73 · raw

@+path:String -> Bool

Hub imports name a package, not a path.

def verdict source · line 76 · raw

@fine:Bool -> @+want:String -> @+span:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Span -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>

def judge source · line 91 · raw

@file:String -> @+written:String -> @loads:String -> @span:0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Span -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>

A written path, against the one from file to loads, the file its import loads.

def paths source · line 97 · raw

@nodes:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Node> -> @+file:String -> @out:List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding> -> List<&2, 0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Finding>

The findings on the paths of nodes' imports, onto out. A file's imports come first, so the first node of another kind ends them; import Base writes no path.

def run source · line 119 · raw

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

def rule source · line 122 · raw

0xbf17cd8a773b73dcdd93291552ca53f8/linter/lint.Rule