Skip to content

Commit

Permalink
Added --as_json_array option.
Browse files Browse the repository at this point in the history
Option instructs script to output all issues as JSON array instead of
ending each one with \0.
  • Loading branch information
yuriisk committed Jul 13, 2021
1 parent 47ab7d2 commit 464c765
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Reads Clang-Tidy output from `STDIN` and prints Code Climate JSON to `STDOUT`.
* `-h, --help` - show help message and exit.
* `-r PROJECT_ROOT, --project_root PROJECT_ROOT` - output file paths relative to `PROJECT_ROOT`. E.g. Clang-Tidy outputs '/home/user/projects/A/src/main.cpp' file path and `PROJECT_ROOT` is set to '/home/user/projects/A' then Code Climate JSON mentions the file as 'src/main.cpp'.
* `-l, --use_location_lines` - use _line-based_ locations instead of _position-based_ as defined in _Locations_ section of Code Climate specification.
* `-j, --as_json_array` - output as JSON array instead of ending each issue with \0.

## Example

Expand Down
5 changes: 4 additions & 1 deletion clang_tidy_converter/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
def create_argparser():
p = ArgumentParser(description='Reads Clang-Tidy output from STDIN and prints Code Climate JSON to STDOUT.')
p.add_argument('-r', '--project_root', default='', help='output file paths relative to PROJECT_ROOT')
p.add_argument('-l', '--use_location_lines', action='store_const', const=True, default=False, help='use line-based locations instead of position-based as defined in Locations section of Code Climate specification.')
p.add_argument('-l', '--use_location_lines', action='store_const', const=True, default=False,
help='use line-based locations instead of position-based as defined in Locations section of Code Climate specification')
p.add_argument('-j', '--as_json_array', action='store_const', const=True, default=False,
help='output as JSON array instead of ending each issue with \\0')
return p

def main(args):
Expand Down
8 changes: 4 additions & 4 deletions clang_tidy_converter/formatter/code_climate_formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def __init__(self):
pass

def format(self, messages, args):
formatted_string = ""
for message in messages:
formatted_string += json.dumps(self._format_message(message, args), indent=2) + '\0\n'
return formatted_string
if args.as_json_array:
return json.dumps([self._format_message(msg, args) for msg in messages], indent=2)
else:
return ''.join(json.dumps(self._format_message(msg, args), indent=2) + '\0\n' for msg in messages)

def _format_message(self, message, args):
return {
Expand Down

0 comments on commit 464c765

Please sign in to comment.