|
145 | 145 | _AR_DIRECT_INTENT_PATTERNS = ( |
146 | 146 | re.compile(r"\byou\s+(?:must|will|should|can|cannot|can'?t|are|were)\b", re.IGNORECASE), |
147 | 147 | re.compile(r"\bfrom\s+now\s+on\b", re.IGNORECASE), |
| 148 | + re.compile(r"\b(?:never|do\s+not|don'?t)\s+(?:ever\s+)?(?:refuse|decline)\b", re.IGNORECASE), |
| 149 | + re.compile( |
| 150 | + r"\bnever\s+say\s+(?:that\s+)?(?:you\s+)?(?:can'?t|cannot|won'?t|no)\b", re.IGNORECASE |
| 151 | + ), |
148 | 152 | re.compile( |
149 | 153 | r"\byou\s+have\s+no\s+(?:restrictions?|limitations?|guidelines?|policies?)\b", re.IGNORECASE |
150 | 154 | ), |
|
183 | 187 | ) |
184 | 188 | _BENIGN_AR_TOOL_FIELD_PATTERN = re.compile(r"^\s*tool\s*:\s*\S", re.IGNORECASE) |
185 | 189 | _BENIGN_AR_DESCRIPTION_FIELD_PATTERN = re.compile(r"^\s*description\s*:\s*", re.IGNORECASE) |
| 190 | +_DIRECTIVE_DOCUMENTATION_LABEL_PATTERN = re.compile(r"^\s*documentation\s*:\s*", re.IGNORECASE) |
186 | 191 | _BENIGN_AR_FIXTURE_INTRO_PATTERN = re.compile( |
187 | 192 | r"^\s*(?:#\s*)?(?:defensive\s+fixture|unit\s+test|test\s+case)\b", |
188 | 193 | re.IGNORECASE, |
@@ -211,6 +216,18 @@ def _is_explicit_example_context(context: str) -> bool: |
211 | 216 | return bool(_EXPLICIT_EXAMPLE_CONTEXT_PATTERN.search(context)) |
212 | 217 |
|
213 | 218 |
|
| 219 | +def _emitted_context(context: str, match_line: str, is_directive: bool) -> str: |
| 220 | + """Keep runner-visible context on the directive when example markers are false context.""" |
| 221 | + if not is_directive: |
| 222 | + return context |
| 223 | + trimmed_line = _DIRECTIVE_DOCUMENTATION_LABEL_PATTERN.sub("", match_line, count=1) |
| 224 | + if trimmed_line != match_line: |
| 225 | + return trimmed_line |
| 226 | + if _is_explicit_example_context(context): |
| 227 | + return match_line |
| 228 | + return context |
| 229 | + |
| 230 | + |
214 | 231 | def _is_quoted_or_labeled_benign_match( |
215 | 232 | match_line: str, |
216 | 233 | matched_text: str, |
@@ -314,6 +331,8 @@ def analyze(content: str, file_path: str, file_type: str) -> list[AnalyzerFindin |
314 | 331 | _SECURITY_REVIEW_CONTEXT_RE.search(context) |
315 | 332 | ): |
316 | 333 | continue |
| 334 | + |
| 335 | + is_directive = _is_directly_instructive(match_line.lower(), match.group(0)) |
317 | 336 | confidence = base_confidence |
318 | 337 | if ( |
319 | 338 | is_code_example(context) |
@@ -345,7 +364,7 @@ def analyze(content: str, file_path: str, file_type: str) -> list[AnalyzerFindin |
345 | 364 | ), |
346 | 365 | confidence=round(confidence, 2), |
347 | 366 | tags=tag, |
348 | | - context=context, |
| 367 | + context=_emitted_context(context, match_line, is_directive), |
349 | 368 | matched_text=match.group(0)[:200], |
350 | 369 | ) |
351 | 370 | ) |
|
0 commit comments