@@ -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,11 +285,11 @@ 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 = "^(.*?[^\w-])?( {}):{}(.*)" .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 = "^(.*?[^\w-])?( {}-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
@@ -314,7 +318,7 @@ def exit_handler(code):
314318 checks .append (check )
315319 continue
316320
317- check_not_regex = "^(.*?[^\w-])?( {}-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
@@ -341,7 +345,7 @@ def exit_handler(code):
341345 checks .append (check )
342346 continue
343347
344- check_empty_regex = "^(.*?[^\w-])?( {}-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 :
347351 check_keyword = check_match .group (2 )
0 commit comments