oct.linter.lint_cache module#

Purpose#

FS-510 — incremental lint cache. Content-hash keyed so unchanged files are not re-linted on subsequent runs.

Responsibilities#

  • Compute deterministic content hashes for source files.

  • Store and retrieve per-file lint results from a JSON cache file.

  • Invalidate entries when file content, active rules, or OCT version change.

  • Thread-safe read/write via threading.Lock.

Diagnostics#

Domain: OCT-LINTER Levels:

L3 — cache hits/misses L4 — cache I/O details

Contracts#

  • Cache file lives at .option_c/cache/lint-cache.json.

  • Corrupt or missing cache file is silently replaced (no crash).

  • Cache is never authoritative — a --no-cache flag bypasses reads.

class oct.linter.lint_cache.LintCache(cache_path: Path, oct_version: str)[source]#

Bases: object

Thread-safe, content-addressed lint result cache.

Loads from cache_path on init; call save() to persist.

property entry_count: int#

Number of cached entries (for diagnostics).

get(file_hash: str, active_rules_hash: str) LintCacheEntry | None[source]#

Return cached entry if content + rules match, else None.

put(file_hash: str, active_rules_hash: str, entry: LintCacheEntry) None[source]#

Store a lint result in the cache.

save() None[source]#

Write the cache to disk. Creates parent directories if needed.

class oct.linter.lint_cache.LintCacheEntry(content_hash: str, rule_results: dict[str, bool], json_detail: dict[str, Any], oct_version: str, timestamp: str)[source]#

Bases: object

One cached lint result for a single file.

content_hash: str#
json_detail: dict[str, Any]#
oct_version: str#
rule_results: dict[str, bool]#
timestamp: str#
oct.linter.lint_cache.content_hash(text: str) str[source]#

Return a SHA-256 hex digest of text.

oct.linter.lint_cache.rules_hash(active_rules: dict[str, bool]) str[source]#

Return a SHA-256 hex digest of the sorted active-rules dict.