(
filename: str,
skip_errors: bool,
)
| 120 | |
| 121 | |
| 122 | def format_file( |
| 123 | filename: str, |
| 124 | skip_errors: bool, |
| 125 | ) -> int: |
| 126 | with open(filename, encoding="UTF-8") as f: |
| 127 | contents = f.read() |
| 128 | new_contents, errors = format_str(contents) |
| 129 | for error in errors: |
| 130 | lineno = contents[: error.offset].count("\n") + 1 |
| 131 | print(f"{filename}:{lineno}: code block parse error {error.exc}") |
| 132 | if errors and not skip_errors: |
| 133 | return 1 |
| 134 | if contents != new_contents: |
| 135 | print(f"{filename}: Rewriting...") |
| 136 | with open(filename, "w", encoding="UTF-8") as f: |
| 137 | f.write(new_contents) |
| 138 | return 0 |
| 139 | else: |
| 140 | return 0 |
| 141 | |
| 142 | |
| 143 | def main(argv: Sequence[str] | None = None) -> int: |
no test coverage detected