Find the indent in the first non empty line in a code sample. Args: code (`str`): The code to inspect. Returns: `str`: The indent looked at (as string).
(code: str)
| 545 | |
| 546 | |
| 547 | def get_indent(code: str) -> str: |
| 548 | """ |
| 549 | Find the indent in the first non empty line in a code sample. |
| 550 | |
| 551 | Args: |
| 552 | code (`str`): The code to inspect. |
| 553 | |
| 554 | Returns: |
| 555 | `str`: The indent looked at (as string). |
| 556 | """ |
| 557 | lines = code.split("\n") |
| 558 | idx = 0 |
| 559 | while idx < len(lines) and len(lines[idx]) == 0: |
| 560 | idx += 1 |
| 561 | if idx < len(lines): |
| 562 | return re.search(r"^(\s*)\S", lines[idx]).groups()[0] |
| 563 | return "" |
| 564 | |
| 565 | |
| 566 | def run_ruff(code, check=False): |
no test coverage detected