Skip to content

Commit

Permalink
Fix pretty print with pipes (#3622)
Browse files Browse the repository at this point in the history
  • Loading branch information
kddejong authored Aug 27, 2024
1 parent a34f16c commit c6e80fa
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/cfnlint/formatters/pretty.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)} '
Expand Down
14 changes: 14 additions & 0 deletions test/unit/module/formatters/test_formatters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit c6e80fa

Please sign in to comment.