Skip to content

Commit 27e36c3

Browse files
pdgendtnashif
authored andcommitted
scripts: ci: check_compliance: Keepsorted optional stripped characters
Allow passing characters to strip for zephyr-keep-sorted. This can be useful for optional double quotes in yaml maps. Signed-off-by: Pieter De Gendt <pieter.degendt@basalte.be>
1 parent 05316bd commit 27e36c3

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

scripts/ci/check_compliance.py

Lines changed: 10 additions & 2 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):
1819+
def block_check_sorted(self, block_data, *, regex, strip):
18201820
def _test_indent(txt: str):
18211821
return txt.startswith((" ", "\t"))
18221822

@@ -1839,6 +1839,9 @@ def _test_indent(txt: str):
18391839
if _test_indent(line):
18401840
continue
18411841

1842+
if strip is not None:
1843+
line = line.strip(strip)
1844+
18421845
# Fold back indented lines after the current one
18431846
for cont in takewhile(_test_indent, lines[idx + 1:]):
18441847
line += cont.strip()
@@ -1862,8 +1865,10 @@ def check_file(self, file, fp):
18621865
start_marker = f"{self.MARKER}-start"
18631866
stop_marker = f"{self.MARKER}-stop"
18641867
regex_marker = r"re\((.+)\)"
1868+
strip_marker = r"strip\((.+)\)"
18651869
start_line = 0
18661870
regex = None
1871+
strip = None
18671872

18681873
for line_num, line in enumerate(fp.readlines(), start=1):
18691874
if start_marker in line:
@@ -1878,14 +1883,17 @@ def check_file(self, file, fp):
18781883
# Test for a regex block
18791884
match = re.search(regex_marker, line)
18801885
regex = match.group(1) if match else None
1886+
1887+
match = re.search(strip_marker, line)
1888+
strip = match.group(1) if match else None
18811889
elif stop_marker in line:
18821890
if not in_block:
18831891
desc = f"{stop_marker} without {start_marker}"
18841892
self.fmtd_failure("error", "KeepSorted", file, line_num,
18851893
desc=desc)
18861894
in_block = False
18871895

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

0 commit comments

Comments
 (0)