Scan comment text in @p src_text and emit one finding per banned pattern. Walks every line: `// ...` line comments contribute their tail text, and ` * ...` lines inside a doxygen / block comment contribute their body (minus the leading `*`). String literals and code outside comments are
(
src_text: str, path: Path, fence_mask: list[bool]
)
| 3031 | |
| 3032 | |
| 3033 | def _comment_narration_findings( |
| 3034 | src_text: str, path: Path, fence_mask: list[bool] |
| 3035 | ) -> list[Finding]: |
| 3036 | """Scan comment text in @p src_text and emit one finding per banned pattern. |
| 3037 | |
| 3038 | Walks every line: `// ...` line comments contribute their tail text, and |
| 3039 | ` * ...` lines inside a doxygen / block comment contribute their body |
| 3040 | (minus the leading `*`). String literals and code outside comments are |
| 3041 | not visited. @brief lines are skipped. |
| 3042 | """ |
| 3043 | if _is_vendored_path(path): |
| 3044 | return [] |
| 3045 | |
| 3046 | out: list[Finding] = [] |
| 3047 | lines = src_text.split("\n") |
| 3048 | for i, raw in enumerate(lines, start=1): |
| 3049 | if i - 1 < len(fence_mask) and fence_mask[i - 1]: |
| 3050 | continue |
| 3051 | |
| 3052 | # `//` line comment -- everything after the marker is prose. |
| 3053 | m_line = re.search(r"//(.*)$", raw) |
| 3054 | # ` * ` doxygen continuation -- a line starting with whitespace + `*` |
| 3055 | # but NOT starting a `*/` close or a `/**` open is prose. The opener |
| 3056 | # `/**` line itself often contains @brief and runs through the |
| 3057 | # @brief filter below. |
| 3058 | m_doxy = re.match(r"^\s*\*\s?(.*)$", raw) |
| 3059 | |
| 3060 | if m_line: |
| 3061 | text = m_line.group(1) |
| 3062 | elif m_doxy and not m_doxy.group(1).startswith("/"): |
| 3063 | text = m_doxy.group(1) |
| 3064 | else: |
| 3065 | continue |
| 3066 | |
| 3067 | if _is_brief_line(text): |
| 3068 | continue |
| 3069 | |
| 3070 | for pat, msg in _NARRATION_PATTERNS: |
| 3071 | if pat.search(text): |
| 3072 | out.append(Finding(i, "comment-narration", msg)) |
| 3073 | break # one finding per line is plenty |
| 3074 | return out |
| 3075 | |
| 3076 | |
| 3077 | # --------------------------------------------------------------------------- |
no test coverage detected