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

Function _line_has_real_violation

ci/ci-iwyu.py:53–80  ·  view source on GitHub ↗

Check if the given line actually contains a removable #include or forward declaration.

(file_path: Path, line_num: int)

Source from the content-addressed store, hash-verified

51
52
53def _line_has_real_violation(file_path: Path, line_num: int) -> bool:
54 """Check if the given line actually contains a removable #include or forward declaration."""
55 try:
56 lines = file_path.read_text(encoding="utf-8", errors="replace").splitlines()
57 if line_num < 1 or line_num > len(lines):
58 return False
59 line = lines[line_num - 1].strip()
60 # Lines explicitly marked to keep are not violations
61 if "IWYU pragma: keep" in line:
62 return False
63 # Actual #include
64 if line.startswith("#include"):
65 return True
66 # Forward declarations (class/struct/enum/template)
67 for kw in ("class ", "struct ", "enum ", "template"):
68 if kw in line and "IWYU pragma: no_forward_declare" not in line:
69 return True
70 # Namespace-wrapped forward decls like "namespace fl { class Foo; }"
71 if line.startswith("namespace") and ("class " in line or "struct " in line):
72 return True
73 return False
74 except KeyboardInterrupt:
75 import _thread
76
77 _thread.interrupt_main()
78 return True # unreachable, satisfies type checker
79 except Exception:
80 return True # Can't read file — keep the violation to be safe
81
82
83# ---------------------------------------------------------------------------

Callers 2

_scan_one_headerFunction · 0.85
scan_single_fileFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected