#!/usr/bin/env python3
"""Print every line in a stripped tree that still starts like a comment.
Usage: residual.py <TREE>"""
import pathlib, re, sys
SUFFIXES = {".java", ".xml", ".yml", ".yaml", ".properties", ".go", ".js", ".py"}
KEEP = {"maven-wrapper.properties"}
hits = files = 0
for p in sorted(pathlib.Path(sys.argv[1]).rglob("*")):
    if not p.is_file() or p.suffix not in SUFFIXES or p.name in KEEP or "target" in p.parts:
        continue
    files += 1
    for n, line in enumerate(p.read_text(encoding="utf-8").split("\n"), 1):
        if re.match(r"\s*(#|//|/\*|\*|<!--)", line) and not (n == 1 and line.startswith("#!")):
            hits += 1
            print(f"{p}:{n}: {line.strip()[:80]}")
print(f"{files} files scanned, {hits} comment-shaped lines")
