Skip to content

Commit 15fbf21

Browse files
pdgendtnashif
authored andcommitted
scripts: ci: check_compliance: Keepsorted optional folding
Introduce a marker for zephyr-keep-sorted to not fold continued indented lines. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
1 parent 27e36c3 commit 15fbf21

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

scripts/ci/check_compliance.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,7 +1816,7 @@ class KeepSorted(ComplianceTest):
18161816

18171817
MARKER = "zephyr-keep-sorted"
18181818

1819-
def block_check_sorted(self, block_data, *, regex, strip):
1819+
def block_check_sorted(self, block_data, *, regex, strip, fold):
18201820
def _test_indent(txt: str):
18211821
return txt.startswith((" ", "\t"))
18221822

@@ -1842,9 +1842,10 @@ def _test_indent(txt: str):
18421842
if strip is not None:
18431843
line = line.strip(strip)
18441844

1845-
# Fold back indented lines after the current one
1846-
for cont in takewhile(_test_indent, lines[idx + 1:]):
1847-
line += cont.strip()
1845+
if fold:
1846+
# Fold back indented lines after the current one
1847+
for cont in takewhile(_test_indent, lines[idx + 1:]):
1848+
line += cont.strip()
18481849

18491850
if line < last:
18501851
return idx
@@ -1866,9 +1867,11 @@ def check_file(self, file, fp):
18661867
stop_marker = f"{self.MARKER}-stop"
18671868
regex_marker = r"re\((.+)\)"
18681869
strip_marker = r"strip\((.+)\)"
1870+
nofold_marker = "nofold"
18691871
start_line = 0
18701872
regex = None
18711873
strip = None
1874+
fold = True
18721875

18731876
for line_num, line in enumerate(fp.readlines(), start=1):
18741877
if start_marker in line:
@@ -1886,14 +1889,16 @@ def check_file(self, file, fp):
18861889

18871890
match = re.search(strip_marker, line)
18881891
strip = match.group(1) if match else None
1892+
1893+
fold = nofold_marker not in line
18891894
elif stop_marker in line:
18901895
if not in_block:
18911896
desc = f"{stop_marker} without {start_marker}"
18921897
self.fmtd_failure("error", "KeepSorted", file, line_num,
18931898
desc=desc)
18941899
in_block = False
18951900

1896-
idx = self.block_check_sorted(block_data, regex=regex, strip=strip)
1901+
idx = self.block_check_sorted(block_data, regex=regex, strip=strip, fold=fold)
18971902
if idx >= 0:
18981903
desc = f"sorted block has out-of-order line at {start_line + idx}"
18991904
self.fmtd_failure("error", "KeepSorted", file, line_num,

0 commit comments

Comments
 (0)