# diagnostic

URL: /patitas/api/linting/diagnostic/
Section: linting
Description: Diagnostic and Severity types for the lint framework.

This is a leaf data module: it depends only on the standard library and
`SourceLocation`, so it can be imported without pulling
in the runner, the registry, or any rules.

Thread Safety:
    Both `Severity` and `Diagnostic` are immutable. ``Severity``
    is a plain enum; ``Diagnostic`` is a frozen, slotted dataclass. Both are
    safe to share across threads.

---

> For a complete page index, fetch /patitas/llms.txt.

Open LLM text
(/patitas/api/linting/diagnostic/index.txt)

Share with AI

Ask Claude
(https://claude.ai/new?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Flinting%2Fdiagnostic%2Findex.txt)

Ask ChatGPT
(https://chatgpt.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Flinting%2Fdiagnostic%2Findex.txt)

Ask Gemini
(https://gemini.google.com/app?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Flinting%2Fdiagnostic%2Findex.txt)

Ask Copilot
(https://copilot.microsoft.com/?q=Please%20help%20me%20understand%20this%20documentation%3A%20%2Fpatitas%2Fapi%2Flinting%2Fdiagnostic%2Findex.txt)

Module

#
`linting.diagnostic`

Diagnostic and Severity types for the lint framework.

This is a leaf data module: it depends only on the standard library and
`SourceLocation`, so it can be imported without pulling
in the runner, the registry, or any rules.

Thread Safety:

```
Both `Severity` and `Diagnostic` are immutable. ``Severity``
is a plain enum; ``Diagnostic`` is a frozen, slotted dataclass. Both are
safe to share across threads.
```

2Classes

## Classes

`Severity`

1

▼

Severity level of a lint `Diagnostic`.

A plain `Enum` (matching the codebase's plain-Enum preceden…

Bases:

`Enum`

Severity level of a lint `Diagnostic` (/patitas/api/linting/diagnostic/#Diagnostic).

A plain`Enum`(matching the codebase's plain-Enum precedent,
e.g. `TokenType` (/patitas/api/tokens/#TokenType)/`LexerMode` (/patitas/api/lexer/modes/#LexerMode)). It is deliberately NOT an `IntEnum`:
that avoids accidental integer coercion (`Severity.ERROR != 1`). The
LSP`DiagnosticSeverity`integer is available explicitly via
`to_lsp` (/patitas/api/linting/diagnostic/#Severity)().

#### Methods

`to_lsp`

0

`int`

▼

Return the LSP ``DiagnosticSeverity`` integer for this severity.

The Language …

`def to_lsp(self) -> int`

Return the LSP`DiagnosticSeverity`integer for this severity.

The Language Server Protocol numbers severities 1 (Error), 2 (Warning),
3 (Information), 4 (Hint). This maps the three lint severities onto the
first three.

##### Returns

`int`

The LSP severity integer: ERROR -> 1, WARNING -> 2, INFO -> 3.

`Diagnostic`

6

▼

A single lint finding.

Reuses the existing `SourceLocation` verbatim for
positions — it never intr…

A single lint finding.

Reuses the existing `SourceLocation` (/patitas/api/location/#SourceLocation) verbatim for
positions — it never introduces a new position type and never extends
`Node` (/patitas/api/nodes/#Node). For AST-oriented rules the location is the offending node's
`node.location`; for line-oriented rules (e.g. trailing whitespace) the
rule synthesizes its own `SourceLocation` (/patitas/api/location/#SourceLocation).

The runner stamps`rule_id` and `severity` (/patitas/api/linting/diagnostic/#Diagnostic) from the emitting
rule's class metadata, so they can never drift from the producing rule.

Thread Safety:
Frozen and slotted; safe to share across threads.

#### Attributes

Name
Type
Description

`rule_id`

`str`

Kebab-case id of the rule that produced this diagnostic.

`message`

`str`

Human-readable, single-line description of the violation.

`location`

`SourceLocation (/patitas/api/location/#SourceLocation)`

Position of the violation (reuses`SourceLocation`).

`severity`

`Severity (/patitas/api/linting/diagnostic/#Severity)`

Effective severity of this occurrence.

#### Methods

`to_dict`

0

`dict[str, object]`

▼

Convert to a JSON/LSP-friendly dict.

Named ``to_dict`` to match the establishe…

`def to_dict(self) -> dict[str, object]`

Convert to a JSON/LSP-friendly dict.

Named`to_dict` to match the established `serialization.py`
convention. `severity` (/patitas/api/linting/diagnostic/#Diagnostic) is serialized to its enum `.value` (/patitas/api/tokens/#Token) string.

##### Returns

`dict[str, object]`

A dict with the rule id, message, severity value, and position
fields (line/col plus the full location offsets).

Internal Methods
1

▼

`__str__`

0

`str`

▼

Format as ``file:line:col: [rule-id] message``.

Delegates position formatting …

`def __str__(self) -> str`

Format as`file:line:col: [rule-id] message`.

Delegates position formatting to`__str__`(), so the
`file:` prefix is omitted when `source_file`is unset. Mirrors the
`ParseError` (/patitas/api/errors/#ParseError) "file:line:col: message" shape.

##### Returns

`str`

A single-line, ready-to-print diagnostic string.
