Lint indentation rules

Write codeMedium14 min

Your task

Lint the indentation of a nested CI file. Rules: (a) leading indentation consists of spaces, if the first character after the leading spaces is a tab, the line is bad; (b) the space count must be even (level = spaces/2); (c) the first non-blank line must be at level 0; (d) compared with the previous non-blank line, a line may go deeper by at most ONE level, while any decrease is fine; (e) whitespace-only lines are invisible to all rules. Return true when every line passes, false at the first violation. An empty file is valid.

Examples

validate_indentation(lines: list[str]) -> bool
Example 1
Inputvalidate_indentation(["deploy:", " region: us-east", " "])
OutputTrue
Example 2
Inputvalidate_indentation(["jobs:", " build: go"])
OutputFalse