From 372d1110059e51af31afd461f979bbfd05d18806 Mon Sep 17 00:00:00 2001 From: Kevin DeJong Date: Tue, 27 Aug 2024 09:16:18 -0700 Subject: [PATCH] Fix pretty print with pipes --- src/cfnlint/formatters/pretty.py | 3 ++- test/unit/module/formatters/test_formatters.py | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/cfnlint/formatters/pretty.py b/src/cfnlint/formatters/pretty.py index eb570b94af..65abee7eca 100644 --- a/src/cfnlint/formatters/pretty.py +++ b/src/cfnlint/formatters/pretty.py @@ -28,7 +28,8 @@ def print_matches(self, matches, rules, config): # ruff: noqa: E501 results.append( - f"Cfn-lint scanned {colored(len(config.templates), color.bold_reset)} templates against " + f"Cfn-lint scanned {colored(len(config.templates) if config.templates else 1, color.bold_reset)}" + " templates against " f"{colored(len(rules.used_rules), color.bold_reset)} rules and found " f'{colored(len([i for i in matches if i.rule.severity.lower() == "error"]), color.error)} ' f'errors, {colored(len([i for i in matches if i.rule.severity.lower() == "warning"]), color.warning)} ' diff --git a/test/unit/module/formatters/test_formatters.py b/test/unit/module/formatters/test_formatters.py index d5659672e3..b34d4ad3c6 100644 --- a/test/unit/module/formatters/test_formatters.py +++ b/test/unit/module/formatters/test_formatters.py @@ -213,6 +213,20 @@ def test_pretty_formatter(self): ), ) + def test_pretty_formatter_pipe(self): + """Test pretty formatter""" + formatter = PrettyFormatter() + self.config.cli_args.templates = None + results = formatter.print_matches( + self.results, rules=self.rules, config=self.config + ).splitlines() + + if sys.stdout.isatty(): + self.assertIn("Cfn-lint scanned 1 templates", results[5]) + else: + # Check the errors + self.assertIn("Cfn-lint scanned 1 templates", results[5]) + def test_json_formatter(self): """Test JSON formatter""" formatter = JsonFormatter()