From b53f670af8a0c77c584cf3d5c47120a31a57e083 Mon Sep 17 00:00:00 2001 From: Christopher Pickering Date: Mon, 26 Sep 2022 13:47:41 +0200 Subject: [PATCH] feat(quiet): updated output of the --quiet flag to reduce unneeded verbose stuff --- src/djlint/__init__.py | 7 +++++-- src/djlint/output.py | 29 +++++++++++++---------------- tests/test_djlint/test_djlint.py | 2 +- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/src/djlint/__init__.py b/src/djlint/__init__.py index bebcca4d1..5c3dc5a10 100644 --- a/src/djlint/__init__.py +++ b/src/djlint/__init__.py @@ -221,7 +221,7 @@ def main( Style.RESET_ALL + " ", ) ) - if config.stdin is False or config.lint: + if config.stdin is False and config.quiet is False: echo() worker_count = os.cpu_count() or 1 @@ -239,7 +239,7 @@ def main( func = partial(process, config) futures = {exe.submit(func, this_file): this_file for this_file in file_list} - if temp_file is None or config.lint: + if temp_file is None: elapsed = "00:00" with tqdm( total=len(file_list), @@ -277,6 +277,9 @@ def main( leave=True, ) finished_bar.close() + else: + for future in as_completed(futures): + file_errors.append(future.result()) if temp_file and (config.reformat or config.check): # if using stdin, only give back formatted code. diff --git a/src/djlint/output.py b/src/djlint/output.py index c0917d36a..c1bd201fc 100644 --- a/src/djlint/output.py +++ b/src/djlint/output.py @@ -31,7 +31,9 @@ def print_output( lint_error_count = 0 format_error_count = 0 - if config.stdin is False or config.lint: + print_blanks = config.stdin is False and config.quiet is False + + if print_blanks: echo() for error in sorted(file_errors, key=lambda x: next(iter(list(x.values())[0]))): @@ -58,22 +60,26 @@ def print_output( f"Linted {file_quantity}, found {lint_error_count} {error_case}." ) - if config.stdin is False or config.lint: + if print_blanks: echo() - if config.stdin is False and (config.reformat or config.check): + if ( + config.quiet is False + and config.stdin is False + and (config.reformat or config.check) + ): reformat_success_color = ( Fore.RED + Style.BRIGHT if (format_error_count) > 0 else Fore.BLUE ) echo(f"{reformat_success_color}{reformat_success_message}{Style.RESET_ALL}") - if config.lint: + if config.lint and config.quiet is False: lint_success_color = ( Fore.RED + Style.BRIGHT if (lint_error_count) > 0 else Fore.BLUE ) echo(f"{lint_success_color}{lint_success_message}{Style.RESET_ALL}") - if config.stdin is False or config.lint: + if print_blanks: echo() return lint_error_count + format_error_count @@ -100,7 +106,7 @@ def build_output(error: dict, config: Config) -> int: filename = build_relative_path(list(error.keys())[0], config.project_root.resolve()) - if "{filename}" not in config.linter_output_format: + if "{filename}" not in config.linter_output_format and not config.stdin: echo( f"{Fore.GREEN}{Style.BRIGHT}\n{filename}\n{Style.DIM}" + "".join(["─" for x in range(1, width)]) @@ -140,16 +146,7 @@ def build_check_output(errors: dict, config: Config) -> int: color = {"-": Fore.YELLOW, "+": Fore.GREEN, "@": Style.BRIGHT + Fore.BLUE} width, _ = shutil.get_terminal_size() - if config.quiet is True and len(list(errors.values())[0]) > 0: - echo( - Fore.GREEN - + Style.BRIGHT - + build_relative_path(list(errors.keys())[0], config.project_root.resolve()) - + Style.DIM - + Style.RESET_ALL - ) - - elif config.quiet is False and len(list(errors.values())[0]) > 0: + if config.quiet is False and len(list(errors.values())[0]) > 0: echo( Fore.GREEN + Style.BRIGHT diff --git a/tests/test_djlint/test_djlint.py b/tests/test_djlint/test_djlint.py index 7aeda59db..1a0212093 100644 --- a/tests/test_djlint/test_djlint.py +++ b/tests/test_djlint/test_djlint.py @@ -174,7 +174,7 @@ def test_check_reformatter_simple_error_quiet( write_to_file(tmp_file.name, b"

nice stuff here

") result = runner.invoke(djlint, [tmp_file.name, "--check", "--quiet"]) assert result.exit_code == 1 - assert "1 file would be updated." in result.output + assert "1 file would be updated." not in result.output def test_check_reformatter_no_error(runner: CliRunner, tmp_file: TextIO) -> None: