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

Class PlatformIncludesChecker

ci/lint_cpp/platform_includes_checker.py:57–165  ·  view source on GitHub ↗

Checker for direct platform-specific header includes.

Source from the content-addressed store, hash-verified

55
56
57class PlatformIncludesChecker(FileContentChecker):
58 """Checker for direct platform-specific header includes."""
59
60 def __init__(self):
61 self.violations: dict[str, list[tuple[int, str]]] = {}
62
63 def should_process_file(self, file_path: str) -> bool:
64 """Only process HEADER files in platform-agnostic locations.
65
66 This checker focuses on headers (.h, .hpp) because they define public APIs
67 that should remain platform-agnostic. Implementation files (.cpp) are allowed
68 to include platform-specific headers when necessary for implementation.
69 """
70 # Normalize path separators for cross-platform compatibility
71 normalized_path = file_path.replace("\\", "/")
72
73 # Check file extension - ONLY check headers (.h, .hpp), not .cpp or .ino
74 if not file_path.endswith((".h", ".hpp")):
75 return False
76
77 # Check if file is in excluded list
78 if any(file_path.endswith(excluded) for excluded in EXCLUDED_FILES):
79 return False
80
81 # ALLOWED: Files in platform implementation directories (can use platform headers)
82 if "/platforms/" in normalized_path:
83 # Allow platform implementation code to use platform headers
84 # Exception: Don't check files in src/platforms/*/
85 return False
86
87 # ALLOWED: Platform-specific test files
88 if "/tests/platforms/" in normalized_path:
89 return False
90
91 # CHECK: Platform-agnostic HEADER locations must use trampolines
92 platform_agnostic_locations = [
93 "/src/fl/",
94 "/src/fx/",
95 "/src/lib8tion/",
96 "/src/sensors/",
97 "/tests/fl/",
98 "/tests/fx/",
99 "/examples/",
100 ]
101
102 return any(
103 location in normalized_path for location in platform_agnostic_locations
104 )
105
106 def check_file_content(self, file_content: FileContent) -> list[str]:
107 """Check file for deep platform-specific header includes."""
108 violations: list[tuple[int, str]] = []
109 in_multiline_comment = False
110
111 for line_number, line in enumerate(file_content.lines, 1):
112 stripped = line.strip()
113
114 # Track multi-line comment state

Callers 3

create_checkersFunction · 0.90
setUpMethod · 0.90
mainFunction · 0.70

Calls

no outgoing calls

Tested by 1

setUpMethod · 0.72