Only check tracked files and don't print on empty lint

This commit is contained in:
Allen Hill
2026-07-09 18:16:51 -07:00
parent 681450f4ad
commit 568c2af9e6
+22 -12
View File
@@ -49,6 +49,7 @@ still bypasses it.
import argparse import argparse
import os import os
import re import re
import subprocess
import sys import sys
# ---- locations ------------------------------------------------------------- # ---- locations -------------------------------------------------------------
@@ -227,10 +228,16 @@ def find_address_spec(root):
def iter_src_files(root): def iter_src_files(root):
for dirpath, _dirs, files in os.walk(os.path.join(root, SRC_REL)): """List source files under src/, via `git ls-files` so paths excluded by
for fn in sorted(files): .gitignore (e.g. the ESP32 port's CMake build directory, which vendors
if fn.endswith(SRC_EXTS): FetchContent'd third-party code) are never walked into."""
yield os.path.join(dirpath, fn) out = subprocess.run(
["git", "-C", root, "ls-files", "-z", "--cached", "--others",
"--exclude-standard", "--", SRC_REL],
capture_output=True, check=True, text=True,
).stdout
paths = sorted(p for p in out.split("\0") if p.endswith(SRC_EXTS))
return [os.path.join(root, p) for p in paths]
# ---- lint ------------------------------------------------------------------ # ---- lint ------------------------------------------------------------------
@@ -471,8 +478,6 @@ def main():
lua_path = os.path.join(root, LUA_REL) lua_path = os.path.join(root, LUA_REL)
lua_lines = read_lines(lua_path) lua_lines = read_lines(lua_path)
specs, have_address = build_specs(root) specs, have_address = build_specs(root)
if not have_address:
print("note: no Address enum found in src/ -- addresses not synced")
# ---- lint (all modes) ---- # ---- lint (all modes) ----
lint_failed = False lint_failed = False
@@ -487,6 +492,8 @@ def main():
print_lint(spec, LUA_REL, problems) print_lint(spec, LUA_REL, problems)
if args.lint: if args.lint:
if not have_address:
print("note: no Address enum found in src/ -- addresses not synced")
if lint_failed: if lint_failed:
print("lint: FAILED") print("lint: FAILED")
return 1 return 1
@@ -503,6 +510,8 @@ def main():
has_drift = any(not d.clean() for _s, _e, d in drifts) has_drift = any(not d.clean() for _s, _e, d in drifts)
if args.fix: if args.fix:
if not have_address:
print("note: no Address enum found in src/ -- addresses not synced")
if lint_failed: if lint_failed:
print("fix aborted: resolve the dissector name problems above first") print("fix aborted: resolve the dissector name problems above first")
return 1 return 1
@@ -525,16 +534,17 @@ def main():
print("fix: applied" if has_drift else "fix: already in sync") print("fix: applied" if has_drift else "fix: already in sync")
return 0 return 0
# ---- default: report ---- # ---- default: report (silent on success -- this is the pre-commit hook) ----
if not (lint_failed or has_drift):
return 0
if not have_address:
print("note: no Address enum found in src/ -- addresses not synced")
for spec, _entries, drift in drifts: for spec, _entries, drift in drifts:
if not drift.clean(): if not drift.clean():
print("%s drift:" % spec["name"]) print("%s drift:" % spec["name"])
print_drift(drift) print_drift(drift)
if lint_failed or has_drift: print("out of sync -- run: scripts/sync_avclan_enums.py --fix")
print("out of sync -- run: scripts/sync_avclan_enums.py --fix") return 1
return 1
print("enums in sync with the dissector")
return 0
if __name__ == "__main__": if __name__ == "__main__":