Skip to content

Commit 2ddb4b8

Browse files
meshyTenzer
andcommitted
Add --indentation to vary spacing in JSON report
Some environments may want control over this to make working with existing style-guides easier. Co-authored-by: Jeppe Fihl-Pearson <[email protected]>
1 parent eeaccc4 commit 2ddb4b8

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
- *Action required:* Move existing behaviour under "parse" subcommand.
66
Invocations of `mypy-json-report` should now be replaced with `mypy-json-report parse`.
7+
- Add `parse --indentation` flag to grant control over how much indentation is used in the JSON report.
78
- Use GA version of Python 3.11 in test matrix.
89

910
## v0.1.3 [2022-09-07]

mypy_json_report.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ def main() -> None:
4040
parse_parser = subparsers.add_parser(
4141
"parse", help="Transform Mypy output into JSON."
4242
)
43+
parse_parser.add_argument(
44+
"-i",
45+
"--indentation",
46+
type=int,
47+
default=2,
48+
help="Number of spaces to indent JSON output.",
49+
)
4350

4451
parse_parser.set_defaults(func=_parse_command)
4552

@@ -50,7 +57,7 @@ def main() -> None:
5057
def _parse_command(args: argparse.Namespace) -> None:
5158
"""Handle the `parse` command."""
5259
errors = parse_errors_report(sys.stdin)
53-
error_json = json.dumps(errors, sort_keys=True, indent=2)
60+
error_json = json.dumps(errors, sort_keys=True, indent=args.indentation)
5461
print(error_json)
5562

5663

0 commit comments

Comments
 (0)