Checker for raw __attribute__((weak)) usage - should use FL_LINK_WEAK instead.
| 12 | |
| 13 | |
| 14 | class WeakAttributeChecker(FileContentChecker): |
| 15 | """Checker for raw __attribute__((weak)) usage - should use FL_LINK_WEAK instead.""" |
| 16 | |
| 17 | def __init__(self): |
| 18 | self.violations: dict[str, list[tuple[int, str]]] = {} |
| 19 | |
| 20 | def should_process_file(self, file_path: str) -> bool: |
| 21 | """Check if file should be processed.""" |
| 22 | # Check C++ file extensions |
| 23 | if not file_path.endswith((".cpp", ".h", ".hpp", ".ino", ".cpp.hpp")): |
| 24 | return False |
| 25 | |
| 26 | # Skip the file that defines FL_LINK_WEAK |
| 27 | if file_path.endswith("compiler_control.h"): |
| 28 | return False |
| 29 | |
| 30 | return True |
| 31 | |
| 32 | def check_file_content(self, file_content: FileContent) -> list[str]: |
| 33 | """Check file content for raw __attribute__((weak)) usage.""" |
| 34 | violations: list[tuple[int, str]] = [] |
| 35 | in_multiline_comment = False |
| 36 | |
| 37 | for line_number, line in enumerate(file_content.lines, 1): |
| 38 | stripped = line.strip() |
| 39 | |
| 40 | # Track multi-line comment state |
| 41 | if "/*" in line: |
| 42 | in_multiline_comment = True |
| 43 | if "*/" in line: |
| 44 | in_multiline_comment = False |
| 45 | continue |
| 46 | |
| 47 | # Skip if inside multi-line comment |
| 48 | if in_multiline_comment: |
| 49 | continue |
| 50 | |
| 51 | # Skip single-line comment lines |
| 52 | if stripped.startswith("//"): |
| 53 | continue |
| 54 | |
| 55 | # Remove single-line comment portion before checking |
| 56 | code_part = line.split("//")[0] |
| 57 | |
| 58 | # Skip lines that define FL_LINK_WEAK macro |
| 59 | if "#define" in code_part and "FL_LINK_WEAK" in code_part: |
| 60 | continue |
| 61 | |
| 62 | # Check for __attribute__((weak)) pattern |
| 63 | if WEAK_ATTR_PATTERN.search(code_part): |
| 64 | violations.append( |
| 65 | ( |
| 66 | line_number, |
| 67 | f"Use FL_LINK_WEAK instead of __attribute__((weak)): {stripped}", |
| 68 | ) |
| 69 | ) |
| 70 | |
| 71 | if violations: |
no outgoing calls
no test coverage detected