validate

Validation normative de fichiers Markdown OKF (exit 0 si conforme, exit 1 sinon).

Normative validation of OKF Markdown files — exit 0 if conformant, 1 otherwise.

class okflint.validate.Diagnostic(code, tier, severity, file, message)[source]

Bases: object

OKF validation error or warning.

code: str
file: str
message: str
severity: str
tier: str
exception okflint.validate.ManifestError[source]

Bases: Exception

Invalid or unreadable OKF manifest.

okflint.validate.dispatch_reserved_file(path, file_path, content, *, reserved_files, is_root)[source]

Route a file to its reserved-file check, or signal it is a concept file.

Single source of truth for “is this file reserved, and if so which rule applies”: both the manifest-driven path (validate_file) and the manifest-less path (run_audit) must go through this instead of each deciding independently which names are reserved — that duplication is what let F001 fire on reserved files in the manifest-less audit path.

Parameters:
  • path (str) – Relative file path (for diagnostic messages).

  • file_path (Path) – Absolute path of the file; its basename is matched against reserved_files.

  • content (str) – Raw file content.

  • reserved_files (dict[str, str]) – Mapping with “index”/”log” keys to their configured filename. Pass manifest.base.reserved_files when a manifest is loaded, DEFAULT_RESERVED_FILES otherwise.

  • is_root (bool) – True if the file sits directly under the applicable root (manifest root, or bundle root when there is no manifest). Only affects R001’s root exemption for okf_version.

Return type:

list[Diagnostic] | None

Returns:

Diagnostics from R001/R002 if the file is reserved (possibly empty if conformant), or None if the file is not reserved and the caller should fall through to the normal concept-file check.

okflint.validate.run_validate(manifest_path, targets, *, vault_index=None)[source]

Orchestrate OKF validation over a list of targets.

When vault_index is provided it is used as the wikilink resolution index instead of rebuilding one from the manifest roots, allowing the caller to pass a vault-wide union index built once for all bundles.

Parameters:
  • manifest_path (Path) – Path to the OKF YAML manifest.

  • targets (list[Path]) – Files or directories to validate. May be relative (e.g. to the process CWD); resolved to absolute internally to match the manifest’s own resolved roots.

  • vault_index (dict[str, list[str]] | None) – Pre-built file index (stem → list of relative paths). When provided, the per-manifest index build is skipped.

Return type:

tuple[list[Diagnostic], int]

Returns:

Tuple (list of diagnostics, exit code 0 or 1).

Raises:

ManifestError – If the manifest is invalid or unreadable.