fix(conventions): strip trailing tab from spaced diff paths

Git appends a tab after file names containing spaces in the +++ header, so the
added-lines key kept the tab and its suffix no longer matched. Comment,
extension, title and silent-stub rules then skipped such files. The tab is
now stripped, with a test covering core/a b.cpp.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01V9UU71SP1UKGR51Sowbgmq
This commit is contained in:
GalaxyGamingFR 2026-10-11 02:33:20 -07:00 committed by Adrià Franch
parent 434f290def
commit 3a1deb48a8
2 changed files with 33 additions and 1 deletions

View File

@ -66,7 +66,7 @@ class Check:
path = None
for line in git("diff", "-U0", "--no-color", "--no-renames", "--no-prefix", self.base, head).splitlines():
if line.startswith("+++ "):
path = None if line == "+++ /dev/null" else line[4:]
path = None if line == "+++ /dev/null" else line[4:].rstrip(" ")
elif line.startswith("@@"):
number = int(re.search(r"\+(\d+)", line).group(1))
elif line.startswith("+") and path:

View File

@ -226,5 +226,37 @@ class PullRequestTemplateTests(unittest.TestCase):
self.assertEqual(self.findings("- [x] all"), [])
class SpacedPathTests(unittest.TestCase):
def test_comment_in_path_with_space_is_reported(self):
checker = Path(__file__).resolve().parents[1] / "check_conventions.py"
with tempfile.TemporaryDirectory() as directory:
root = Path(directory)
def git(*args):
return subprocess.run(
["git", "-c", "user.name=Conventions Test", "-c", "user.email=test@example.com",
"-c", "commit.gpgsign=false", *args],
cwd=root, capture_output=True, text=True, check=True,
)
git("init", "-q")
(root / "readme.txt").write_text("x\n", encoding="utf-8")
git("add", ".")
git("commit", "-qm", "docs: add readme")
source = root / "core/a b.cpp"
source.parent.mkdir(parents=True)
source.write_text("int x; // note\n", encoding="utf-8")
git("add", ".")
git("commit", "-qm", "feat: add spaced file")
result = subprocess.run(
[sys.executable, "-I", str(checker), "--base", "HEAD~1"],
cwd=root, capture_output=True, text=True,
env={key: value for key, value in os.environ.items()
if key not in ("GITHUB_EVENT_PATH", "GITHUB_STEP_SUMMARY", "GITHUB_ACTIONS")},
)
self.assertEqual(result.returncode, 1, result.stdout + result.stderr)
self.assertIn("core/a b.cpp:1: error: [comment]", result.stdout)
if __name__ == "__main__":
unittest.main()