|
|
|
@ -22,6 +22,7 @@ import locale
|
|
|
|
|
import os
|
|
|
|
|
import platform
|
|
|
|
|
import sys
|
|
|
|
|
import json
|
|
|
|
|
|
|
|
|
|
from yamllint import APP_DESCRIPTION, APP_NAME, APP_VERSION
|
|
|
|
|
from yamllint import linter
|
|
|
|
@ -85,10 +86,20 @@ class Format(object):
|
|
|
|
|
line += ' \033[2m(%s)\033[0m' % problem.rule
|
|
|
|
|
return line
|
|
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
|
def json(problem, filename):
|
|
|
|
|
return {
|
|
|
|
|
"path": filename,
|
|
|
|
|
"line": problem.line,
|
|
|
|
|
"char": problem.column,
|
|
|
|
|
"description": problem.message,
|
|
|
|
|
"severity": problem.level,
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
def show_problems(problems, file, args_format, no_warn):
|
|
|
|
|
max_level = 0
|
|
|
|
|
first = True
|
|
|
|
|
problems_json = []
|
|
|
|
|
|
|
|
|
|
for problem in problems:
|
|
|
|
|
max_level = max(max_level, PROBLEM_LEVELS[problem.level])
|
|
|
|
@ -96,6 +107,8 @@ def show_problems(problems, file, args_format, no_warn):
|
|
|
|
|
continue
|
|
|
|
|
if args_format == 'parsable':
|
|
|
|
|
print(Format.parsable(problem, file))
|
|
|
|
|
elif args_format == 'json':
|
|
|
|
|
problems_json.append(Format.json(problem, file))
|
|
|
|
|
elif args_format == 'colored' or \
|
|
|
|
|
(args_format == 'auto' and supports_color()):
|
|
|
|
|
if first:
|
|
|
|
@ -108,6 +121,9 @@ def show_problems(problems, file, args_format, no_warn):
|
|
|
|
|
first = False
|
|
|
|
|
print(Format.standard(problem, file))
|
|
|
|
|
|
|
|
|
|
if args_format == 'json':
|
|
|
|
|
print(json.dumps(problems_json))
|
|
|
|
|
|
|
|
|
|
if not first and args_format != 'parsable':
|
|
|
|
|
print('')
|
|
|
|
|
|
|
|
|
@ -131,7 +147,7 @@ def run(argv=None):
|
|
|
|
|
action='store',
|
|
|
|
|
help='custom configuration (as YAML source)')
|
|
|
|
|
parser.add_argument('-f', '--format',
|
|
|
|
|
choices=('parsable', 'standard', 'colored', 'auto'),
|
|
|
|
|
choices=('parsable', 'standard', 'colored', 'json', 'auto'),
|
|
|
|
|
default='auto', help='format for parsing output')
|
|
|
|
|
parser.add_argument('-s', '--strict',
|
|
|
|
|
action='store_true',
|
|
|
|
|