pull/68/merge
Alex Kiousis 8 years ago committed by GitHub
commit 6d162247b2

@ -20,6 +20,7 @@ import os.path
import sys import sys
import argparse import argparse
import json
from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION
from yamllint.config import YamlLintConfig, YamlLintConfigError from yamllint.config import YamlLintConfig, YamlLintConfigError
@ -48,6 +49,18 @@ class Format(object):
'level': problem.level, 'level': problem.level,
'message': problem.message}) '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 @staticmethod
def standard(problem, filename): def standard(problem, filename):
line = ' %d:%d' % (problem.line, problem.column) line = ' %d:%d' % (problem.line, problem.column)
@ -87,8 +100,8 @@ def run(argv=None):
action='store', action='store',
help='custom configuration (as YAML source)') help='custom configuration (as YAML source)')
parser.add_argument('-f', '--format', parser.add_argument('-f', '--format',
choices=('parsable', 'standard'), default='standard', choices=('parsable', 'standard', 'json'),
help='format for parsing output') default='standard', help='format for parsing output')
parser.add_argument('-s', '--strict', parser.add_argument('-s', '--strict',
action='store_true', action='store_true',
help='return non-zero exit code on warnings ' help='return non-zero exit code on warnings '
@ -134,6 +147,8 @@ def run(argv=None):
for problem in linter.run(f, conf, filepath): for problem in linter.run(f, conf, filepath):
if args.format == 'parsable': if args.format == 'parsable':
print(Format.parsable(problem, file)) print(Format.parsable(problem, file))
elif args.format == 'json':
print(Format.json_output(problem, file))
elif sys.stdout.isatty(): elif sys.stdout.isatty():
if first: if first:
print('\033[4m%s\033[0m' % file) print('\033[4m%s\033[0m' % file)

Loading…
Cancel
Save