lint · API

mojolint.structure

Functions, parameters, structs and fields, recovered from logical lines by indentation alone.

A def header at indent k owns every following line with indent > k; the same for struct. That is enough to know, for any line, which function it is in and what that function's parameters and var locals are called — the whole vocabulary the rules use.

Structs

Param

struct Param

Implements Copyable, Movable

Fields
name: String
conv: String: read, mut, ref, var, out or deinit — read when unwritten.
type: String: The declared type text, default value removed; empty if untyped.

Func

struct Func

Implements Copyable, Movable

Fields
name: String
owner: String: The enclosing struct's name, or empty for a free function.
params: List[Param]
header: Int: Index of the header line in the List[Line].
body_start: Int
body_end: Int: Exclusive end of the body in the List[Line].

param

def param(self, name: String) -> Optional[Param]

is_param

def is_param(self, name: String) -> Bool

Field

struct Field

Implements Copyable, Movable

Fields
name: String
type: String

Struct

struct Struct

Implements Copyable, Movable

Fields
name: String
fields: List[Field]
has_deinit: Bool: Defines __deinit__ or __del__.
header: Int
body_end: Int

field

def field(self, name: String) -> Optional[Field]

Module

struct Module

The functions and structs of one file.

Implements Movable

Fields
funcs: List[Func]
structs: List[Struct]

func_at

def func_at(self, line_index: Int) -> Optional[Func]

The innermost function whose body contains line_index.

struct_named

def struct_named(self, name: String) -> Optional[Struct]

Functions

parse_params

def parse_params(header: String) -> List[Param]

Parameters of a def header line, in order.

parse_module

def parse_module(lines: List[Line]) -> Module

Recover functions and structs from lines.

locals_of

def locals_of(lines: List[Line], f: Func) -> List[String]

Names declared with var in f's body, in order of declaration.

has_local

def has_local(lines: List[Line], f: Func, name: String) -> Bool

used_after

def used_after(lines: List[Line], f: Func, line_index: Int, name: String) -> Bool

Is name mentioned on any line of f after line_index?