feat: json formater
This commit is contained in:
@@ -59,7 +59,7 @@ def run(argv=None):
|
|||||||
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', 'colored', 'github',
|
choices=('parsable', 'standard', 'colored', 'github',
|
||||||
'auto'),
|
'json', 'auto'),
|
||||||
default='auto', help='format for parsing output')
|
default='auto', help='format for parsing output')
|
||||||
parser.add_argument('-s', '--strict',
|
parser.add_argument('-s', '--strict',
|
||||||
action='store_true',
|
action='store_true',
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ from __future__ import print_function
|
|||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
|
import json
|
||||||
|
|
||||||
from yamllint.linter import PROBLEM_LEVELS
|
from yamllint.linter import PROBLEM_LEVELS
|
||||||
|
|
||||||
@@ -209,6 +210,26 @@ class StandardFormater(Formater):
|
|||||||
return line
|
return line
|
||||||
|
|
||||||
|
|
||||||
|
class JSONFormater(Formater):
|
||||||
|
"""The parsable formater."""
|
||||||
|
name = 'json'
|
||||||
|
|
||||||
|
def show_problems_for_all_files(self, all_problems):
|
||||||
|
"""Show all problems of all files."""
|
||||||
|
lst = []
|
||||||
|
for k, v in all_problems.items():
|
||||||
|
lst += self.show_problems_for_file(v, k)
|
||||||
|
return json.dumps(lst, indent=4)
|
||||||
|
|
||||||
|
def show_problems_for_file(self, problems, file):
|
||||||
|
"""Show all problems of a specific file."""
|
||||||
|
return list(map(self.show_problem, problems, [file] * len(problems)))
|
||||||
|
|
||||||
|
def show_problem(self, problem, file):
|
||||||
|
"""Show all problems of a specific file."""
|
||||||
|
return {**problem.dict, "file": file}
|
||||||
|
|
||||||
|
|
||||||
def max_level(all_problems):
|
def max_level(all_problems):
|
||||||
"""Return the max level of all problems."""
|
"""Return the max level of all problems."""
|
||||||
all_levels = [problem.level for problems in all_problems.values() for problem in problems]
|
all_levels = [problem.level for problems in all_problems.values() for problem in problems]
|
||||||
|
|||||||
@@ -62,6 +62,17 @@ class LintProblem(object):
|
|||||||
def __repr__(self):
|
def __repr__(self):
|
||||||
return '%d:%d: %s' % (self.line, self.column, self.message)
|
return '%d:%d: %s' % (self.line, self.column, self.message)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def dict(self):
|
||||||
|
"""Return self as a dictionary."""
|
||||||
|
return {
|
||||||
|
"line": self.line,
|
||||||
|
"column": self.column,
|
||||||
|
"desc": self.desc,
|
||||||
|
"rule": self.rule,
|
||||||
|
"level": self.level,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
def get_cosmetic_problems(buffer, conf, filepath):
|
def get_cosmetic_problems(buffer, conf, filepath):
|
||||||
rules = conf.enabled_rules(filepath)
|
rules = conf.enabled_rules(filepath)
|
||||||
|
|||||||
Reference in New Issue
Block a user