@@ -1816,7 +1816,7 @@ class KeepSorted(ComplianceTest):
1816
1816
1817
1817
MARKER = "zephyr-keep-sorted"
1818
1818
1819
- def block_check_sorted (self , block_data , regex ):
1819
+ def block_check_sorted (self , block_data , * , regex , strip ):
1820
1820
def _test_indent (txt : str ):
1821
1821
return txt .startswith ((" " , "\t " ))
1822
1822
@@ -1839,6 +1839,9 @@ def _test_indent(txt: str):
1839
1839
if _test_indent (line ):
1840
1840
continue
1841
1841
1842
+ if strip is not None :
1843
+ line = line .strip (strip )
1844
+
1842
1845
# Fold back indented lines after the current one
1843
1846
for cont in takewhile (_test_indent , lines [idx + 1 :]):
1844
1847
line += cont .strip ()
@@ -1862,8 +1865,10 @@ def check_file(self, file, fp):
1862
1865
start_marker = f"{ self .MARKER } -start"
1863
1866
stop_marker = f"{ self .MARKER } -stop"
1864
1867
regex_marker = r"re\((.+)\)"
1868
+ strip_marker = r"strip\((.+)\)"
1865
1869
start_line = 0
1866
1870
regex = None
1871
+ strip = None
1867
1872
1868
1873
for line_num , line in enumerate (fp .readlines (), start = 1 ):
1869
1874
if start_marker in line :
@@ -1878,14 +1883,17 @@ def check_file(self, file, fp):
1878
1883
# Test for a regex block
1879
1884
match = re .search (regex_marker , line )
1880
1885
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
1881
1889
elif stop_marker in line :
1882
1890
if not in_block :
1883
1891
desc = f"{ stop_marker } without { start_marker } "
1884
1892
self .fmtd_failure ("error" , "KeepSorted" , file , line_num ,
1885
1893
desc = desc )
1886
1894
in_block = False
1887
1895
1888
- idx = self .block_check_sorted (block_data , regex )
1896
+ idx = self .block_check_sorted (block_data , regex = regex , strip = strip )
1889
1897
if idx >= 0 :
1890
1898
desc = f"sorted block has out-of-order line at { start_line + idx } "
1891
1899
self .fmtd_failure ("error" , "KeepSorted" , file , line_num ,
0 commit comments