MCPcopy Create free account
hub / github.com/Serial-Studio/Serial-Studio / _check_shallow_id

Function _check_shallow_id

scripts/code-verify.py:804–866  ·  view source on GitHub ↗
(
    lines: list[LogicalLine],
    start: int,
    end: int,
    path: Path,
    violations: list[Violation],
    blanks_after: list[int],
)

Source from the content-addressed store, hash-verified

802
803
804def _check_shallow_id(
805 lines: list[LogicalLine],
806 start: int,
807 end: int,
808 path: Path,
809 violations: list[Violation],
810 blanks_after: list[int],
811) -> None:
812 # Find the first non-blank, non-comment logical line at depth 0 of this body
813 inner_depth = 0
814 first_content_idx = None
815 shallow_id_idx = None
816
817 for i in range(start, end):
818 line = lines[i]
819 # Update inner depth before recording this line so nested-block
820 # content is excluded from the shallow content walk
821 if inner_depth == 0:
822 if line.kind in ("blank", "comment"):
823 continue
824 if first_content_idx is None:
825 first_content_idx = i
826 if line.kind == "id":
827 shallow_id_idx = i
828 break
829 # A non-id content line before the id (or no id) — stop looking at shallow depth
830 break
831 # Move through nested block content
832 if line.kind == "close" and inner_depth > 0:
833 inner_depth += _brace_delta(line)
834 continue
835 inner_depth += _brace_delta(line)
836
837 if shallow_id_idx is None:
838 return
839
840 # If the first content line wasn't the id, flag it (no auto-fix — moving
841 # arbitrary content above the id would risk reordering side effects).
842 if first_content_idx != shallow_id_idx:
843 violations.append(
844 Violation(
845 path,
846 lines[shallow_id_idx].start_idx + 1,
847 "id-placement",
848 "`id:` must be the first content line inside the block",
849 )
850 )
851 return
852
853 # Ensure blank line after the id — auto-fixable by inserting one.
854 next_idx = shallow_id_idx + 1
855 if next_idx < end and lines[next_idx].kind != "blank":
856 id_line = lines[shallow_id_idx]
857 violations.append(
858 Violation(
859 path,
860 id_line.start_idx + 1,
861 "id-blank-line",

Callers 1

check_id_placementFunction · 0.85

Calls 3

_brace_deltaFunction · 0.85
ViolationClass · 0.85
appendMethod · 0.45

Tested by

no test coverage detected