Files
leleka/scripts/limits/files.py
T
Pavlo Ratushnyi 334af80d3d STRA-367: limits gate for lawbook 301 (function 30 lines, complexity 10, nesting 4, width 120)
New and changed code is checked against the base (merge-base with the integration branch):
every added or touched function and every added or changed line must be within the limits,
unless limits-allowlist.json lists the function with a reason and an owner; an allowlisted
function may only shrink. The legacy that exists today is a per-crate census in
limits-baseline.json whose totals may only fall (same --update-baseline semantics as the
architecture gate). Rust is measured from the rustsplit lexer, the gate's own Python from ast.
56 self-tests, including a temporary git repository.
2026-11-06 11:26:53 +01:00

26 lines
813 B
Python

"""Reading and scanning one source file."""
import dataclasses
from . import model, policy, pyscan, rscan
def read(root, rel):
return (root / rel).read_text(encoding="utf-8", errors="replace")
def scan_text(pol, rel, text):
"""([Fn], {wide line numbers}) of a source text; a function in a test file is a test function."""
wide = model.wide_lines(text, pol.limits["width"], pol.tab_width)
in_test_file = policy.is_test_path(rel)
if policy.language(pol, rel) == "python":
try:
fns = pyscan.scan(text, wide)
except SyntaxError:
fns = []
else:
fns = rscan.scan(text, wide)
return [dataclasses.replace(fn, test=fn.test or in_test_file) for fn in fns], wide
def scan_file(root, pol, rel):
return scan_text(pol, rel, read(root, rel))