Checker that flags raw _Pragma() usage. Use FL_DISABLE_WARNING_PUSH / FL_DISABLE_WARNING( ) / FL_DISABLE_WARNING_POP from fl/stl/compiler_control.h instead.
| 22 | |
| 23 | |
| 24 | class RawPragmaChecker(FileContentChecker): |
| 25 | """Checker that flags raw _Pragma() usage. |
| 26 | |
| 27 | Use FL_DISABLE_WARNING_PUSH / FL_DISABLE_WARNING(<name>) / FL_DISABLE_WARNING_POP |
| 28 | from fl/stl/compiler_control.h instead. |
| 29 | """ |
| 30 | |
| 31 | def __init__(self): |
| 32 | self.violations: dict[str, list[tuple[int, str]]] = {} |
| 33 | |
| 34 | def should_process_file(self, file_path: str) -> bool: |
| 35 | """Check if file should be processed.""" |
| 36 | if not file_path.endswith((".cpp", ".h", ".hpp", ".ino", ".cpp.hpp")): |
| 37 | return False |
| 38 | |
| 39 | normalized = file_path.replace("\\", "/") |
| 40 | |
| 41 | # Skip compiler_control.h — it defines the FL_DISABLE_WARNING macros using _Pragma |
| 42 | if normalized.endswith("compiler_control.h"): |
| 43 | return False |
| 44 | |
| 45 | # Skip third-party code — not under our control |
| 46 | if "/third_party/" in normalized: |
| 47 | return False |
| 48 | |
| 49 | return True |
| 50 | |
| 51 | def check_file_content(self, file_content: FileContent) -> list[str]: |
| 52 | """Check file content for raw _Pragma() usage.""" |
| 53 | violations: list[tuple[int, str]] = [] |
| 54 | lines = file_content.lines |
| 55 | in_multiline_comment = False |
| 56 | |
| 57 | for line_number, line in enumerate(lines, 1): |
| 58 | stripped = line.strip() |
| 59 | |
| 60 | # Track multi-line comment state |
| 61 | if "/*" in line: |
| 62 | in_multiline_comment = True |
| 63 | if "*/" in line: |
| 64 | in_multiline_comment = False |
| 65 | continue |
| 66 | |
| 67 | if in_multiline_comment: |
| 68 | continue |
| 69 | |
| 70 | # Skip single-line comment lines |
| 71 | if stripped.startswith("//"): |
| 72 | continue |
| 73 | |
| 74 | if RAW_PRAGMA_PATTERN.search(line): |
| 75 | violations.append( |
| 76 | ( |
| 77 | line_number, |
| 78 | f"Raw _Pragma() usage: {stripped}\n" |
| 79 | f" Use FL_DISABLE_WARNING_PUSH / FL_DISABLE_WARNING_* / " |
| 80 | f"FL_DISABLE_WARNING_POP from fl/stl/compiler_control.h instead.\n" |
| 81 | f" _Pragma() is not portable across all target compilers.", |
no outgoing calls
no test coverage detected