Remove leading and trailing blank lines, and make the minimum idention 0
(s: str)
| 44 | |
| 45 | |
| 46 | def format_script(s: str) -> str: |
| 47 | """ |
| 48 | Remove leading and trailing blank lines, and make the minimum idention 0 |
| 49 | """ |
| 50 | s = s.strip("\n") |
| 51 | |
| 52 | non_empty_lines = [line for line in s.splitlines() if line and not line.isspace()] |
| 53 | if not non_empty_lines: |
| 54 | # no actual content |
| 55 | return "\n" |
| 56 | |
| 57 | line_indents = [len(line) - len(line.lstrip(" ")) for line in non_empty_lines] |
| 58 | spaces_to_remove = min(line_indents) |
| 59 | |
| 60 | cleaned_lines = "\n".join(line[spaces_to_remove:] for line in s.splitlines()) |
| 61 | if not cleaned_lines.endswith("\n"): |
| 62 | cleaned_lines += "\n" |
| 63 | return cleaned_lines.strip() |
| 64 | |
| 65 | |
| 66 | def test_underline_basic(): |
no test coverage detected
searching dependent graphs…