MCPcopy Create free account
hub / github.com/FastLED/FastLED / WeakAttributeChecker

Class WeakAttributeChecker

ci/lint_cpp/weak_attribute_checker.py:14–74  ·  view source on GitHub ↗

Checker for raw __attribute__((weak)) usage - should use FL_LINK_WEAK instead.

Source from the content-addressed store, hash-verified

12
13
14class 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:

Callers 2

create_checkersFunction · 0.90
mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected