diff --git a/src/ansiblelint/formatters/__init__.py b/src/ansiblelint/formatters/__init__.py index eba6294d61..7836b3b228 100644 --- a/src/ansiblelint/formatters/__init__.py +++ b/src/ansiblelint/formatters/__init__.py @@ -171,7 +171,8 @@ def format_result(self, matches: list[MatchError]) -> str: # Append issue to result list result.append(issue) - return json.dumps(result, sort_keys=False, indent=2) + # Keep it single line due to https://github.com/ansible/ansible-navigator/issues/1490 + return json.dumps(result, sort_keys=False) @staticmethod def _remap_severity(match: MatchError) -> str: @@ -237,8 +238,8 @@ def format_result(self, matches: list[MatchError]) -> str: "version": self.SARIF_SCHEMA_VERSION, "runs": runs, } - - return json.dumps(report, sort_keys=False, indent=2) + # Keep it single line due to https://github.com/ansible/ansible-navigator/issues/1490 + return json.dumps(report, sort_keys=False) def _extract_results( self, diff --git a/test/test_formatter_json.py b/test/test_formatter_json.py index c5856a3da2..3c79229610 100644 --- a/test/test_formatter_json.py +++ b/test/test_formatter_json.py @@ -59,7 +59,10 @@ def test_format_list(self) -> None: def test_result_is_json(self) -> None: """Test if returned string value is a JSON.""" assert isinstance(self.formatter, CodeclimateJSONFormatter) - json.loads(self.formatter.format_result(self.matches)) + output = self.formatter.format_result(self.matches) + json.loads(output) + # https://github.com/ansible/ansible-navigator/issues/1490 + assert "\n" not in output def test_single_match(self) -> None: """Test negative case. Only lists are allowed. Otherwise a RuntimeError will be raised.""" diff --git a/test/test_formatter_sarif.py b/test/test_formatter_sarif.py index a38738379b..c807fdd27c 100644 --- a/test/test_formatter_sarif.py +++ b/test/test_formatter_sarif.py @@ -63,7 +63,10 @@ def test_format_list(self) -> None: def test_result_is_json(self) -> None: """Test if returned string value is a JSON.""" assert isinstance(self.formatter, SarifFormatter) - json.loads(self.formatter.format_result(self.matches)) + output = self.formatter.format_result(self.matches) + json.loads(output) + # https://github.com/ansible/ansible-navigator/issues/1490 + assert "\n" not in output def test_single_match(self) -> None: """Test negative case. Only lists are allowed. Otherwise, a RuntimeError will be raised."""