# mojolint.structure

> A module of lint's API.

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`

```mojo
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`

```mojo
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`

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

#### `is_param`

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

### `Field`

```mojo
struct Field
```

Implements: `Copyable`, `Movable`

Fields:

- `name: String`
- `type: String`

### `Struct`

```mojo
struct Struct
```

Implements: `Copyable`, `Movable`

Fields:

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

#### `field`

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

### `Module`

```mojo
struct Module
```

The functions and structs of one file.

Implements: `Movable`

Fields:

- `funcs: List[Func]`
- `structs: List[Struct]`

#### `func_at`

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

The innermost function whose body contains `line_index`.

#### `struct_named`

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

## Functions

### `parse_params`

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

Parameters of a `def` header line, in order.

### `parse_module`

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

Recover functions and structs from `lines`.

### `locals_of`

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

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

### `has_local`

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

### `used_after`

```mojo
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`?
