diff --git a/README.md b/README.md index c4b9c22..d672ec2 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/clang_tidy_converter/__main__.py b/clang_tidy_converter/__main__.py index e2c43c5..fd321ee 100644 --- a/clang_tidy_converter/__main__.py +++ b/clang_tidy_converter/__main__.py @@ -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): diff --git a/clang_tidy_converter/formatter/code_climate_formatter.py b/clang_tidy_converter/formatter/code_climate_formatter.py index df2efc8..04f433e 100644 --- a/clang_tidy_converter/formatter/code_climate_formatter.py +++ b/clang_tidy_converter/formatter/code_climate_formatter.py @@ -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 {