Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix pretty print with pipes #3622

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading