v0.1.0-pre.011

This commit is contained in:
2026-07-24 14:23:58 +02:00
parent 62bc0ffb44
commit 42e8a203ec
460 changed files with 12005 additions and 7020 deletions

View File

@@ -1,6 +1,6 @@
#!/usr/bin/env python3
# file: scripts/audit_rust_general_rules.py
# version: 3
# version: 4
"""Audit mechanically verifiable Rust rules shared by all Rust projects."""
@@ -54,6 +54,18 @@ def audit_file(root: pathlib.Path, path: pathlib.Path) -> list[Violation]:
violations.append(Violation("RUST003", relative, max(len(lines), 1), "file must end with exactly one newline"))
for index, line in enumerate(lines, 1):
stripped = line.strip()
if stripped.startswith("pub mod ") and (
relative == "kb-lib/src/lib.rs" and stripped == "pub mod materializer;"
or relative.startswith("kb-lib/src/materializer")
):
violations.append(
Violation(
"RUST014",
relative,
index,
"consolidated materializer modules must remain private",
)
)
if re.match(r"^(?:pub(?:\(crate\))?\s+)?use\s+", stripped) is None:
continue
is_export = stripped.startswith("pub use ") or stripped.startswith("pub(crate) use ")
@@ -70,12 +82,30 @@ def audit_file(root: pathlib.Path, path: pathlib.Path) -> list[Violation]:
for attribute in ("#![warn(missing_docs)]", "#![deny(unreachable_pub)]", "#![forbid(unsafe_code)]"):
if attribute not in lines[:20]:
violations.append(Violation("RUST020", relative, 1, f"missing `{attribute}`"))
previous_export_line: int | None = None
previous_export_visibility: str | None = None
for index, line in enumerate(lines, 1):
if not (line.startswith("pub use ") or line.startswith("pub(crate) use ")):
continue
previous = lines[index - 2].strip() if index >= 2 else ""
if not previous.startswith("///"):
violations.append(Violation("RUST021", relative, index, "crate-root re-export requires adjacent rustdoc"))
visibility = "pub(crate)" if line.startswith("pub(crate) use ") else "pub"
if (
previous_export_line is not None
and previous_export_visibility == visibility
and any(not candidate.strip() for candidate in lines[previous_export_line:index - 1])
):
violations.append(
Violation(
"RUST022",
relative,
index,
"crate-root re-export block contains an empty line",
)
)
previous_export_line = index
previous_export_visibility = visibility
return violations