diff --git a/yamllint/cli.py b/yamllint/cli.py index 41695a3..841dd93 100644 --- a/yamllint/cli.py +++ b/yamllint/cli.py @@ -20,6 +20,7 @@ import os.path import sys import argparse +import json from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION from yamllint.config import YamlLintConfig, YamlLintConfigError @@ -48,6 +49,18 @@ class Format(object): 'level': problem.level, 'message': problem.message}) + @staticmethod + def json_output(problem, filename): + return json.dumps({ + "path": filename, + "line": problem.line, + "char": problem.column, + "description": problem.message, + "code": "YAMLLINT", + "name": "YAMLLINT", + "severity": problem.level, + }) + @staticmethod def standard(problem, filename): line = ' %d:%d' % (problem.line, problem.column) @@ -87,8 +100,8 @@ def run(argv=None): action='store', help='custom configuration (as YAML source)') parser.add_argument('-f', '--format', - choices=('parsable', 'standard'), default='standard', - help='format for parsing output') + choices=('parsable', 'standard', 'json'), + default='standard', help='format for parsing output') parser.add_argument('-s', '--strict', action='store_true', help='return non-zero exit code on warnings ' @@ -134,6 +147,8 @@ def run(argv=None): for problem in linter.run(f, conf, filepath): if args.format == 'parsable': print(Format.parsable(problem, file)) + elif args.format == 'json': + print(Format.json_output(problem, file)) elif sys.stdout.isatty(): if first: print('\033[4m%s\033[0m' % file)