Check file content for raw noexcept keyword usage.
(self, file_content: FileContent)
| 65 | return True |
| 66 | |
| 67 | def check_file_content(self, file_content: FileContent) -> list[str]: |
| 68 | """Check file content for raw noexcept keyword usage.""" |
| 69 | # Fast file-level skip when noexcept is completely absent |
| 70 | if "noexcept" not in file_content.content: |
| 71 | return [] |
| 72 | |
| 73 | violations: list[tuple[int, str]] = [] |
| 74 | in_multiline_comment = False |
| 75 | |
| 76 | for line_number, line in enumerate(file_content.lines, 1): |
| 77 | stripped = line.strip() |
| 78 | |
| 79 | # Track multi-line comment state |
| 80 | if "/*" in line: |
| 81 | in_multiline_comment = True |
| 82 | if "*/" in line: |
| 83 | in_multiline_comment = False |
| 84 | continue # skip the closing */ line |
| 85 | |
| 86 | if in_multiline_comment: |
| 87 | continue |
| 88 | |
| 89 | # Skip pure single-line comments |
| 90 | if stripped.startswith("//"): |
| 91 | continue |
| 92 | |
| 93 | # Strip inline comment portion |
| 94 | code = stripped.split("//")[0].strip() |
| 95 | if not code: |
| 96 | continue |
| 97 | |
| 98 | # Skip preprocessor includes entirely — no raw noexcept there |
| 99 | if re.match(r"^#\s*include\b", code): |
| 100 | continue |
| 101 | |
| 102 | # Skip the #define FL_NOEXCEPT noexcept line (legal definition) |
| 103 | if _DEFINE_FL_NOEXCEPT.search(code): |
| 104 | continue |
| 105 | |
| 106 | # Only bother checking lines that contain noexcept |
| 107 | if not _RAW_NOEXCEPT.search(code): |
| 108 | continue |
| 109 | |
| 110 | # Allow noexcept(expr) — the noexcept operator/conditional specifier. |
| 111 | # Only flag bare 'noexcept' (specifier without parentheses). |
| 112 | # After stripping FL_NOEXCEPT occurrences, check if remaining |
| 113 | # noexcept keywords are all followed by '('. |
| 114 | temp = code.replace("FL_NOEXCEPT", "") |
| 115 | remaining = list(_RAW_NOEXCEPT.finditer(temp)) |
| 116 | all_operator_form = all( |
| 117 | temp[m.end() :].lstrip().startswith("(") for m in remaining |
| 118 | ) |
| 119 | if remaining and all_operator_form: |
| 120 | continue |
| 121 | |
| 122 | # Allow suppression comment on the same original line |
| 123 | if _SUPPRESSION.search(line): |
| 124 | continue |