@@ -138,6 +138,10 @@ class CheckResult(Enum):
138138 CHECK_NOT_WITHOUT_MATCH = 5
139139
140140
141+ # Allow check prefixes only at the beginnings of lines or after non-word characters.
142+ before_prefix = "^(.*?[^\w-])?"
143+
144+
141145def check_line (line , current_check , match_full_lines ):
142146 if current_check .check_type == CheckType .CHECK_EMPTY :
143147 if line != '' :
@@ -281,17 +285,17 @@ def exit_handler(code):
281285 # CHECK and CHECK-NEXT
282286 strict_whitespace_match = "" if args .strict_whitespace and args .match_full_lines else " *"
283287
284- check_regex = ".*? ({}):{}(.*)" .format (check_prefix , strict_whitespace_match )
288+ check_regex = "{} ({}):{}(.*)" .format (before_prefix , check_prefix , strict_whitespace_match )
285289 check_match = re .search (check_regex , line )
286290 check_type = CheckType .CHECK
287291 if not check_match :
288- check_regex = ".*? ({}-NEXT):{}(.*)" .format (check_prefix , strict_whitespace_match )
292+ check_regex = "{} ({}-NEXT):{}(.*)" .format (before_prefix , check_prefix , strict_whitespace_match )
289293 check_match = re .search (check_regex , line )
290294 check_type = CheckType .CHECK_NEXT
291295
292296 if check_match :
293- check_keyword = check_match .group (1 )
294- check_expression = check_match .group (2 )
297+ check_keyword = check_match .group (2 )
298+ check_expression = check_match .group (3 )
295299 if not (args .strict_whitespace and args .match_full_lines ):
296300 check_expression = check_expression .strip (' ' )
297301
@@ -309,18 +313,18 @@ def exit_handler(code):
309313 expression = check_expression ,
310314 source_line = line ,
311315 check_line_idx = line_idx ,
312- start_index = check_match .start (2 ))
316+ start_index = check_match .start (3 ))
313317
314318 checks .append (check )
315319 continue
316320
317- check_not_regex = ".* ({}-NOT):{}(.*)" .format (check_prefix , strict_whitespace_match )
321+ check_not_regex = "{} ({}-NOT):{}(.*)" .format (before_prefix , check_prefix , strict_whitespace_match )
318322 check_match = re .search (check_not_regex , line )
319323 if check_match :
320324 match_type = MatchType .SUBSTRING
321325
322- check_keyword = check_match .group (1 )
323- check_expression = check_match .group (2 )
326+ check_keyword = check_match .group (2 )
327+ check_expression = check_match .group (3 )
324328 if not (args .strict_whitespace and args .match_full_lines ):
325329 check_expression = check_expression .strip (' ' )
326330
@@ -336,15 +340,15 @@ def exit_handler(code):
336340 expression = check_expression ,
337341 source_line = line ,
338342 check_line_idx = line_idx ,
339- start_index = check_match .start (2 ))
343+ start_index = check_match .start (3 ))
340344
341345 checks .append (check )
342346 continue
343347
344- check_empty_regex = ".* ({}-EMPTY):" .format (check_prefix )
348+ check_empty_regex = "{} ({}-EMPTY):" .format (before_prefix , check_prefix )
345349 check_match = re .search (check_empty_regex , line )
346350 if check_match :
347- check_keyword = check_match .group (1 )
351+ check_keyword = check_match .group (2 )
348352
349353 check = Check (check_type = CheckType .CHECK_EMPTY ,
350354 match_type = MatchType .SUBSTRING ,
0 commit comments