Answer stability round 1: 0 🔴, 3 🟡 (0 misread); skip vendored settings files, test the worktree read, use assert_not_root, read a file name that is not UTF-8
This commit is contained in:
@@ -34,12 +34,14 @@ class SpaceIndented:
|
||||
|
||||
def space_indented(base: pathlib.Path, timeout: float | None = None) -> SpaceIndented | Failure | None:
|
||||
"""The line counts of the tracked code under base where it has more space-indented lines than tab-indented ones and no tracked file sets the indent; None where it doesn't, or has no code; a Failure where a file cannot be read."""
|
||||
tracked = git("ls-files", "-z", cwd=str(base), timeout=timeout)
|
||||
tracked = git("ls-files", "-z", cwd=str(base), timeout=timeout, errors="replace")
|
||||
if isinstance(tracked, Failure):
|
||||
return tracked
|
||||
spaced = tabbed = 0
|
||||
for name in filter(None, tracked.split("\0")):
|
||||
code = CODE.fullmatch(name) and not VENDORED.search(name)
|
||||
if VENDORED.search(name):
|
||||
continue
|
||||
code = CODE.fullmatch(name)
|
||||
key = next((key for pattern, key in SETTINGS if pattern.fullmatch(name.rsplit("/", 1)[-1])), None)
|
||||
path = base / name
|
||||
if not (code or key) or not os.path.isfile(path):
|
||||
@@ -47,7 +49,7 @@ def space_indented(base: pathlib.Path, timeout: float | None = None) -> SpaceInd
|
||||
try:
|
||||
text = path.read_text(encoding="utf-8", errors="replace")
|
||||
except OSError as failure:
|
||||
return Failure(f"cannot read {name}: {failure}")
|
||||
return Failure(f"{name}: {failure}")
|
||||
if key and key in text:
|
||||
return None
|
||||
if code:
|
||||
|
||||
Reference in New Issue
Block a user