|
29 | 29 |
|
30 | 30 |
|
31 | 31 | def format_json_file(filename: str, check: bool) -> int: |
32 | | - """Reformat a JSON file in place using cfbs pretty-printer.""" |
| 32 | + """Reformat a JSON file in place using cfbs pretty-printer. |
| 33 | +
|
| 34 | + Returns 0 in case of successful reformat or no reformat needed. |
| 35 | + Returns 1 when check is True and reformat is needed. |
| 36 | + """ |
33 | 37 | assert filename.endswith(".json") |
34 | 38 |
|
35 | 39 | if check: |
36 | | - r = not pretty_check_file(filename) |
37 | | - if r: |
| 40 | + success = pretty_check_file(filename) |
| 41 | + # pretty_check_file() in cfbs needs correct typehint: |
| 42 | + assert type(success) is bool |
| 43 | + if not success: |
38 | 44 | print(f"JSON file '{filename}' needs reformatting") |
39 | | - return int(r) |
| 45 | + return int(not success) |
40 | 46 |
|
41 | | - r = pretty_file(filename) |
42 | | - if r: |
| 47 | + reformatted = pretty_file(filename) |
| 48 | + if reformatted: |
43 | 49 | print(f"JSON file '{filename}' was reformatted") |
44 | | - return int(r) |
| 50 | + return 0 # Successfully reformatted or no reformat needed |
45 | 51 |
|
46 | 52 |
|
47 | 53 | def text(node: Node) -> str: |
@@ -655,7 +661,10 @@ def autoformat( |
655 | 661 |
|
656 | 662 |
|
657 | 663 | def format_policy_file(filename: str, line_length: int, check: bool) -> int: |
658 | | - """Format a .cf policy file in place, writing only if content changed.""" |
| 664 | + """Format a .cf policy file in place, writing only if content changed. |
| 665 | +
|
| 666 | + Returns 0 in case of successful reformat or no reformat needed. |
| 667 | + Returns 1 when check is True and reformat is needed.""" |
659 | 668 | assert filename.endswith(".cf") |
660 | 669 |
|
661 | 670 | PY_LANGUAGE = Language(tscfengine.language()) |
|
0 commit comments