From 3601817dd2b9ecb272d5e52808ae75601345b8bc Mon Sep 17 00:00:00 2001 From: QuentinN42 Date: Thu, 3 Feb 2022 20:59:27 +0100 Subject: [PATCH] refactor: moved output at the end of the tests --- yamllint/cli.py | 21 ++++++++++++--------- yamllint/format.py | 10 ++++++++++ 2 files changed, 22 insertions(+), 9 deletions(-) diff --git a/yamllint/cli.py b/yamllint/cli.py index 4d3a53d..93cecc5 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -26,7 +26,7 @@ from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION from yamllint import linter from yamllint.config import YamlLintConfig, YamlLintConfigError from yamllint.linter import PROBLEM_LEVELS -from yamllint.format import show_problems +from yamllint.format import show_all_problems def find_files_recursively(items, conf): @@ -107,7 +107,8 @@ def run(argv=None): if conf.locale is not None: locale.setlocale(locale.LC_ALL, conf.locale) - max_level = 0 + # problems dict: {file: problems} + all_problems = dict() for file in find_files_recursively(args.files, conf): filepath = file[2:] if file.startswith('./') else file @@ -117,20 +118,22 @@ def run(argv=None): except EnvironmentError as e: print(e, file=sys.stderr) sys.exit(-1) - prob_level = show_problems(problems, file, args_format=args.format, - no_warn=args.no_warnings) - max_level = max(max_level, prob_level) + all_problems[file] = problems - # read yaml from stdin if args.stdin: + # read yaml from stdin try: problems = linter.run(sys.stdin, conf, '') except EnvironmentError as e: print(e, file=sys.stderr) sys.exit(-1) - prob_level = show_problems(problems, 'stdin', args_format=args.format, - no_warn=args.no_warnings) - max_level = max(max_level, prob_level) + all_problems['stdin'] = problems + + max_level = show_all_problems( + all_problems, + args_format=args.format, + no_warn=args.no_warnings + ) if max_level == PROBLEM_LEVELS['error']: return_code = 1 diff --git a/yamllint/format.py b/yamllint/format.py index 6df0e6f..ad32c81 100644 --- a/yamllint/format.py +++ b/yamllint/format.py @@ -16,6 +16,7 @@ def supports_color(): return (supported_platform and hasattr(sys.stdout, 'isatty') and sys.stdout.isatty()) + class Format(object): @staticmethod def parsable(problem, filename): @@ -109,3 +110,12 @@ def show_problems(problems, file, args_format, no_warn): print('') return max_level + + +def show_all_problems(all_problems, args_format, no_warn): + """Print all problems, return the max level.""" + max_level = 0 + + for file, problem in all_problems.items(): + curr_level = show_problems(problem, file, args_format, no_warn) + max_level = max(curr_level, max_level)