Skip to content

Commit c6e80fa

Browse files
authored
Fix pretty print with pipes (#3622)
1 parent a34f16c commit c6e80fa

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/cfnlint/formatters/pretty.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ def print_matches(self, matches, rules, config):
2828

2929
# ruff: noqa: E501
3030
results.append(
31-
f"Cfn-lint scanned {colored(len(config.templates), color.bold_reset)} templates against "
31+
f"Cfn-lint scanned {colored(len(config.templates) if config.templates else 1, color.bold_reset)}"
32+
" templates against "
3233
f"{colored(len(rules.used_rules), color.bold_reset)} rules and found "
3334
f'{colored(len([i for i in matches if i.rule.severity.lower() == "error"]), color.error)} '
3435
f'errors, {colored(len([i for i in matches if i.rule.severity.lower() == "warning"]), color.warning)} '

test/unit/module/formatters/test_formatters.py

+14
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,20 @@ def test_pretty_formatter(self):
213213
),
214214
)
215215

216+
def test_pretty_formatter_pipe(self):
217+
"""Test pretty formatter"""
218+
formatter = PrettyFormatter()
219+
self.config.cli_args.templates = None
220+
results = formatter.print_matches(
221+
self.results, rules=self.rules, config=self.config
222+
).splitlines()
223+
224+
if sys.stdout.isatty():
225+
self.assertIn("Cfn-lint scanned 1 templates", results[5])
226+
else:
227+
# Check the errors
228+
self.assertIn("Cfn-lint scanned 1 templates", results[5])
229+
216230
def test_json_formatter(self):
217231
"""Test JSON formatter"""
218232
formatter = JsonFormatter()

0 commit comments

Comments
 (0)