Checker for banned preprocessor macros - should use FL_* wrappers instead.
| 74 | |
| 75 | |
| 76 | class BannedMacrosChecker(FileContentChecker): |
| 77 | """Checker for banned preprocessor macros - should use FL_* wrappers instead.""" |
| 78 | |
| 79 | def __init__(self): |
| 80 | self.violations: dict[str, list[tuple[int, str]]] = {} |
| 81 | |
| 82 | def should_process_file(self, file_path: str) -> bool: |
| 83 | """Check if file should be processed.""" |
| 84 | # Check C++ file extensions |
| 85 | if not file_path.endswith((".cpp", ".h", ".hpp", ".ino", ".cpp.hpp")): |
| 86 | return False |
| 87 | |
| 88 | # Skip files that define the portable wrappers themselves |
| 89 | if file_path.endswith("has_include.h") or file_path.endswith( |
| 90 | ("compiler_control.h", "cpp_compat.h", "static_assert.h") |
| 91 | ): |
| 92 | return False |
| 93 | |
| 94 | # Skip third-party libraries (they define their own macros) |
| 95 | if "/third_party/" in file_path.replace("\\", "/"): |
| 96 | return False |
| 97 | |
| 98 | # Skip external test frameworks (doctest.h, etc.) |
| 99 | if file_path.endswith(("doctest.h", "catch.hpp", "gtest.h")): |
| 100 | return False |
| 101 | |
| 102 | # Skip documentation files |
| 103 | if file_path.endswith((".md", ".txt")): |
| 104 | return False |
| 105 | |
| 106 | return True |
| 107 | |
| 108 | def check_file_content(self, file_content: FileContent) -> list[str]: |
| 109 | """Check file content for banned preprocessor macro usage.""" |
| 110 | violations: list[tuple[int, str]] = [] |
| 111 | in_multiline_comment = False |
| 112 | |
| 113 | for line_number, line in enumerate(file_content.lines, 1): |
| 114 | stripped = line.strip() |
| 115 | |
| 116 | # Track multi-line comment state |
| 117 | if "/*" in line: |
| 118 | in_multiline_comment = True |
| 119 | if "*/" in line: |
| 120 | in_multiline_comment = False |
| 121 | continue |
| 122 | |
| 123 | # Skip if inside multi-line comment |
| 124 | if in_multiline_comment: |
| 125 | continue |
| 126 | |
| 127 | # Skip single-line comment lines |
| 128 | if stripped.startswith("//"): |
| 129 | continue |
| 130 | |
| 131 | # Remove single-line comment portion before checking |
| 132 | code_part = line.split("//")[0] |
| 133 |
no outgoing calls