From fda5ca34c2c3e645bf040e754f46f665fc9c9eee Mon Sep 17 00:00:00 2001 From: Pieter De Gendt Date: Fri, 23 Aug 2024 09:08:26 +0200 Subject: [PATCH] scripts: ci: Fix clang-format notice at file beginning/end The clang-format check outputs a git diff with surrounding context. It naively removed the first and last 3 lines, but this does not work if there are less lines. Signed-off-by: Pieter De Gendt --- scripts/ci/check_compliance.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/scripts/ci/check_compliance.py b/scripts/ci/check_compliance.py index ab124e68f2d..867a515c29c 100755 --- a/scripts/ci/check_compliance.py +++ b/scripts/ci/check_compliance.py @@ -303,11 +303,14 @@ class ClangFormatCheck(ComplianceTest): for patch in patchset: for hunk in patch: # Strip the before and after context - msg = "".join([str(l) for l in hunk[3:-3]]) + before = next(i for i,v in enumerate(hunk) if str(v).startswith('-')) + after = next(i for i,v in enumerate(reversed(hunk)) if str(v).startswith('+')) + msg = "".join([str(l) for l in hunk[before:-after or None]]) + # show the hunk at the last line self.fmtd_failure("notice", "You may want to run clang-format on this change", - file, line=hunk.source_start + hunk.source_length - 3, + file, line=hunk.source_start + hunk.source_length - after, desc=f'\r\n{msg}')