diff --git a/yamllint/cli.py b/yamllint/cli.py index cb87350..a73a157 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -22,6 +22,7 @@ import locale import os import platform import sys +from xml.sax.saxutils import escape from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION from yamllint import linter @@ -98,17 +99,31 @@ class Format(object): line += problem.desc return line + @staticmethod + def checkstyle(problem): + line = ' ' % file) + for problem in problems: max_level = max(max_level, PROBLEM_LEVELS[problem.level]) if no_warn and (problem.level != 'error'): continue if args_format == 'parsable': print(Format.parsable(problem, file)) + elif args_format == 'checkstyle': + print(Format.checkstyle(problem)) elif args_format == 'github' or (args_format == 'auto' and 'GITHUB_ACTIONS' in os.environ and 'GITHUB_WORKFLOW' in os.environ): @@ -128,6 +143,9 @@ def show_problems(problems, file, args_format, no_warn): if not first and args_format != 'parsable': print('') + if args_format == 'checkstyle': + print(' ') + return max_level @@ -149,7 +167,7 @@ def run(argv=None): help='custom configuration (as YAML source)') parser.add_argument('-f', '--format', choices=('parsable', 'standard', 'colored', 'github', - 'auto'), + 'checkstyle', 'auto'), default='auto', help='format for parsing output') parser.add_argument('-s', '--strict', action='store_true', @@ -199,6 +217,10 @@ def run(argv=None): max_level = 0 + if args.format == 'checkstyle': + print('') + print('') + for file in find_files_recursively(args.files, conf): filepath = file[2:] if file.startswith('./') else file try: @@ -222,6 +244,9 @@ def run(argv=None): no_warn=args.no_warnings) max_level = max(max_level, prob_level) + if args.format == 'checkstyle': + print('') + if max_level == PROBLEM_LEVELS['error']: return_code = 1 elif max_level == PROBLEM_LEVELS['warning']: