Skip to content

Commit

Permalink
Add --indentation to vary spacing in JSON report
Browse files Browse the repository at this point in the history
Some environments may want control over this to make working with
existing style-guides easier.

Co-authored-by: Jeppe Fihl-Pearson <[email protected]>
  • Loading branch information
meshy and Tenzer committed Jan 31, 2023
1 parent eeaccc4 commit 2ddb4b8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

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

## v0.1.3 [2022-09-07]
Expand Down
9 changes: 8 additions & 1 deletion mypy_json_report.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,13 @@ def main() -> None:
parse_parser = subparsers.add_parser(
"parse", help="Transform Mypy output into JSON."
)
parse_parser.add_argument(
"-i",
"--indentation",
type=int,
default=2,
help="Number of spaces to indent JSON output.",
)

parse_parser.set_defaults(func=_parse_command)

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


Expand Down

0 comments on commit 2ddb4b8

Please sign in to comment.