From 90f023d3258472e2feb65e8d7b235a0d58b40cb3 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Tue, 20 Sep 2022 08:34:58 +0200 Subject: [PATCH] feat(stats): moved linter stats to be appended to lint output closes #396 --- src/djlint/output.py | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/djlint/output.py b/src/djlint/output.py index 74fe2d9..aa54f9b 100644 --- a/src/djlint/output.py +++ b/src/djlint/output.py @@ -34,22 +34,17 @@ def print_output( if config.stdin is False or config.lint: echo() - if config.statistics: - lint_error_count = build_stats_output( - [x.get("lint_message") for x in file_errors], config - ) + for error in sorted(file_errors, key=lambda x: next(iter(list(x.values())[0]))): + if error.get("format_message") and config.stdin is False: + # reformat message + format_error_count += build_check_output(error["format_message"], config) - else: - for error in sorted(file_errors, key=lambda x: next(iter(list(x.values())[0]))): - if error.get("format_message") and config.stdin is False: - # reformat message - format_error_count += build_check_output( - error["format_message"], config - ) + if error.get("lint_message"): + # lint message + lint_error_count += build_output(error["lint_message"], config) - if error.get("lint_message"): - # lint message - lint_error_count += build_output(error["lint_message"], config) + if config.statistics and config.lint: + build_stats_output([x.get("lint_message") for x in file_errors], config) tense_message = ( build_quantity(format_error_count) + " would be" @@ -206,6 +201,14 @@ def build_stats_output(errors: List[Optional[Any]], config: Config) -> int: rule["rule"]["name"]: rule["rule"]["message"] for rule in config.linter_rules } + echo() + width, _ = shutil.get_terminal_size() + echo( + f"{Fore.GREEN}{Style.BRIGHT}Statistics{Style.RESET_ALL}\n{Style.DIM}" + + "".join(["─" for x in range(1, width)]) + + Style.RESET_ALL + ) + if messages and codes: longest_code = len(max(messages.keys(), key=len))