Skip to content

Commit

Permalink
feat(quiet): updated output of the --quiet flag to reduce unneeded ve…
Browse files Browse the repository at this point in the history
…rbose stuff
  • Loading branch information
christopherpickering committed Sep 26, 2022
1 parent 67e8c64 commit b53f670
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
7 changes: 5 additions & 2 deletions src/djlint/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down Expand Up @@ -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.
Expand Down
29 changes: 13 additions & 16 deletions src/djlint/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]))):
Expand All @@ -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
Expand All @@ -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)])
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/test_djlint/test_djlint.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ def test_check_reformatter_simple_error_quiet(
write_to_file(tmp_file.name, b"<div><p>nice stuff here</p></div>")
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:
Expand Down

0 comments on commit b53f670

Please sign in to comment.