Determine where to insert the header. Returns the line index where the header should be placed. The header will be inserted *before* this index, with a blank line after it. Special cases: - Shebang (#!/...) on line 0 → insert at line 1 - Dockerfile `# syntax=` on line 0 → inser
(lines: list[str], path: Path)
| 215 | |
| 216 | |
| 217 | def find_insertion_point(lines: list[str], path: Path) -> int: |
| 218 | """Determine where to insert the header. |
| 219 | |
| 220 | Returns the line index where the header should be placed. The header |
| 221 | will be inserted *before* this index, with a blank line after it. |
| 222 | |
| 223 | Special cases: |
| 224 | - Shebang (#!/...) on line 0 → insert at line 1 |
| 225 | - Dockerfile `# syntax=` on line 0 → insert at line 1 |
| 226 | - Otherwise → insert at line 0 |
| 227 | """ |
| 228 | if not lines: |
| 229 | return 0 |
| 230 | |
| 231 | first = lines[0] |
| 232 | |
| 233 | # Shebang line — keep it on line 0, header goes after. |
| 234 | if first.startswith("#!"): |
| 235 | return 1 |
| 236 | |
| 237 | # Dockerfile syntax directive. |
| 238 | if is_dockerfile(path) and first.lower().startswith("# syntax="): |
| 239 | return 1 |
| 240 | |
| 241 | return 0 |
| 242 | |
| 243 | |
| 244 | def insert_header(content: str, comment: str, path: Path) -> str: |
no test coverage detected