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

Function check_hierarchy

ci/lint_cpp/test_unity_build.py:270–308  ·  view source on GitHub ↗

Check that _build.hpp files only include immediate children (one level down). Returns: list of violation strings

(src_dir: Path)

Source from the content-addressed store, hash-verified

268
269
270def check_hierarchy(src_dir: Path) -> list[str]:
271 """
272 Check that _build.hpp files only include immediate children (one level down).
273
274 Returns:
275 list of violation strings
276 """
277 violations: list[str] = []
278
279 for build_hpp in src_dir.rglob(BUILD_HPP):
280 namespace_path = _get_namespace_path(build_hpp, src_dir)
281 if namespace_path is None:
282 continue # Not in src/ directory
283
284 content = build_hpp.read_text(encoding="utf-8")
285
286 for match in BUILD_HPP_INCLUDE_PATTERN.finditer(content):
287 included_path = match.group(1)
288 depth = _calculate_include_depth(included_path, namespace_path)
289
290 if depth == 0:
291 # Include doesn't match expected namespace prefix
292 line_num = _get_line_number(content, match.start())
293 rel_file = build_hpp.relative_to(PROJECT_ROOT)
294 violations.append(
295 f"{rel_file.as_posix()}:{line_num}: "
296 f"Include '{included_path}' doesn't match expected prefix '{namespace_path}/'"
297 )
298 elif depth != 1:
299 # Include is too deep (grandchild or deeper)
300 line_num = _get_line_number(content, match.start())
301 rel_file = build_hpp.relative_to(PROJECT_ROOT)
302 violations.append(
303 f"{rel_file.as_posix()}:{line_num}: "
304 f"Include '{included_path}' is {depth} levels deep, but should be exactly 1 level. "
305 f"Expected pattern: '{namespace_path}/<dir>/_build.hpp'"
306 )
307
308 return violations
309
310
311def _check_cpp_hpp_files(src_dir: Path, cpp_hpp_by_dir: CppHppByDir) -> list[str]:

Callers 1

check_scanned_dataFunction · 0.85

Calls 5

_get_namespace_pathFunction · 0.85
_calculate_include_depthFunction · 0.85
_get_line_numberFunction · 0.85
startMethod · 0.45
appendMethod · 0.45

Tested by

no test coverage detected