Linting¶
The ubCode language server has a linting feature built in and detects a broad range of RST issues. The linting feature is enabled by default. Specific rules can be deactivated in the ubproject.toml file.
Lint errors appear in the editor as well as in the problems tab. The same rules also run on the command line through ubc check, the canonical project linter for CI and pre-commit use.
Supported lint rules:
Identifier |
Description |
|---|---|
|
Warns on tabs in a line, which can degrade performance of source mapping. |
|
Warns on missing blank lines between syntax blocks. |
|
Warns on issues with title under/over lines. |
|
Warns on unexpected titles in a context where they are not allowed. |
|
Warns on unexpected indentation of a paragraph line. |
|
Warns on literal blocks with no content. |
|
Warns on malformed hyperlink targets. |
|
Warns on malformed substitution definition. |
|
Warns on malformed tables. |
|
Warns on inconsistent title levels, e.g. a level 1 title style followed by a level 3 style. |
|
Warns on unknown directives. |
|
Warns if the second line of a directive starts with an indented |
|
Warns on malformed directives. |
|
Warns on directives with missing required content. |
|
Warns on directives with a missing required argument. |
|
Warns on inline markup with no closing marker. |
|
Warns on malformed inline roles. |
Markup-semantics diagnostics¶
Added in version 0.31.0.
In addition to the parse-level rules above,
ubCode analyses the meaning of the parsed markup
(directive options, diagram directives, document structure)
and reports issues as warnings with the source label ubcode-markup.
These apply to reStructuredText and Markdown documents alike,
and are reported in the editor, by ubc check,
and in the ubc build diagnostics log.
Identifier |
Description |
|---|---|
|
Warns when a directive option value cannot be interpreted as its declared type. |
|
Warns when a directive option value is outside its declared set of choices
(e.g. |
|
Warns when a diagram directive (e.g. |
|
Warns when a |
|
Warns when a |
|
Warns when a |
|
Warns when a |
|
Warns when a |
|
Warns when a |
|
Warns on non-consecutive Markdown heading levels,
e.g. a |
|
Warns when a |
|
Warns when an |
|
Warns when a |
These codes are governed by the same lint configuration
as every other rule:
ignore, per-file-ignores, message-ignores,
and the --extend-ignore flag of ubc check all apply.
Toctree diagnostics¶
Added in version 0.31.0.
ubCode expands the project’s toctree directives into a single navigation tree,
rooted at the configured root document,
and reports the structural problems it finds along the way.
These are project-level diagnostics — they depend on which documents exist
and how the toctrees reference one another —
and surface in the editor, by ubc check,
and in the ubc build diagnostics log.
Identifier |
Description |
|---|---|
|
Warns when a toctree entry references a document that does not exist (including an entry that names its own containing document). |
|
Warns when a document is listed more than once within a single toctree; the duplicate entry is kept. |
|
Warns when a circular toctree reference is detected and pruned. |
|
Warns when a toctree |
|
Warns when a document is not reachable from any toctree;
the root document and documents pulled in via |
|
Notes that a document is referenced from more than one toctree — an informational message, not a warning. |
|
Warns when the configured root document ( |
Like every other rule, these codes are governed by the
lint configuration
(ignore, per-file-ignores, message-ignores,
and the --extend-ignore flag of ubc check).
Codelinks diagnostics¶
Added in version 0.29.0.
In addition to RST linting,
ubCode validates codelinks one-line markers in source files
(C/C++, Python, Rust, C#, YAML).
When a file belongs to a codelinks project,
marker syntax issues are reported as warnings with the source label ubcode-codelinks.
See Tracing source code with Codelinks for the full list of warning codes and details.
Linting on the command line¶
Added in version 0.31.0.
The ubc check command is the canonical project linter,
in the mould of ruff check and cargo check.
It reports the same project-wide diagnostics the editor shows,
so a passing ubc check and a clean Problems view mean the same thing.
There are three scopes:
ubc check(no paths) checks the whole project, discovered by walking up from the current directory to the nearestubproject.toml. Every diagnostic family runs — the parse, markup-semantics, toctree, reference, need, and schema families above — and both reStructuredText and Markdown documents are included.ubc check <paths>still resolves the whole project, so cross-file diagnostics such as duplicate need IDs and broken references stay correct, but reports only the diagnostics located under the named paths. Project-level configuration problems are always reported, whatever the paths.ubc check --per-file <paths>is the fast, project-free path: each named file is parsed in isolation, so only the per-file (parse and markup) families run — no cross-file, reference, toctree, or schema checks — and non-RST files such as Markdown are skipped.
Cache.
The whole-project and scoped modes read and warm the on-disk .ub_cache,
exactly like ubc build index, so repeated runs are fast;
pass --no-cache for a run that neither reads nor writes it.
--per-file never touches the cache.
Scoped details.
A named path that does not exist on disk is an error,
so a typo in a CI recipe fails rather than passing green;
a path that exists but matches no source file is a warning on stderr.
Configuration-less files that span unrelated directory trees are refused
(use --per-file instead of walking the whole disk).
Exit policy.
By default any warning-or-worse finding fails the command (exit 1);
info-level findings alone do not.
--deny <info|warning|error> moves the failure threshold,
and --max-warnings <N> caps the number of warnings —
when both are given the stricter one wins.
An invalid flag value is a usage error (exit 2).
License.
Like ubc build index, ubc check runs without a license on small
projects (up to five files) and fails with an error above that;
--per-file requires an active license for any non-open-source project.
Machine-readable output.
--output-format json writes a single JSON document to stdout —
the diagnostics and a summary severity tally —
with every other line on stderr, so stdout is safe to pipe into a JSON consumer:
$ ubc check --output-format json
{
"diagnostics": [
{
"code": "image.not_found",
"severity": "warning",
"message": "Image file not found: 'missing.png'",
"sources": [
{"stype": "local", "path": "index.rst", "line": 4, "column": 12, "label": null}
]
}
],
"summary": {"errors": 0, "warnings": 1, "infos": 0}
}
The item shape matches the editor’s project-wide diagnostics
(code, message, and a sources list tagged by stype),
with a severity field added.
The exit code and the --deny / --max-warnings policy are unchanged by the format.