Move formatters to dedicated module
Signed-off-by: Mathieu Rul <mathroule@gmail.com>pull/579/head
parent
6e432b2130
commit
ea560f0fb4
@ -0,0 +1,48 @@
|
|||||||
|
# Copyright (C) 2016 Adrien Vergé
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from yamllint.linter import PROBLEM_LEVELS
|
||||||
|
|
||||||
|
|
||||||
|
def format_results(results, no_warn):
|
||||||
|
max_level = 0
|
||||||
|
|
||||||
|
for file in results:
|
||||||
|
print('\033[4m%s\033[0m' % file)
|
||||||
|
|
||||||
|
for problem in results[file]:
|
||||||
|
max_level = max(max_level, PROBLEM_LEVELS[problem.level])
|
||||||
|
if no_warn and (problem.level != 'error'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(format_problem(problem))
|
||||||
|
|
||||||
|
print('')
|
||||||
|
|
||||||
|
return max_level
|
||||||
|
|
||||||
|
|
||||||
|
def format_problem(problem):
|
||||||
|
line = ' \033[2m%d:%d\033[0m' % (problem.line, problem.column)
|
||||||
|
line += max(20 - len(line), 0) * ' '
|
||||||
|
if problem.level == 'warning':
|
||||||
|
line += '\033[33m%s\033[0m' % problem.level
|
||||||
|
else:
|
||||||
|
line += '\033[31m%s\033[0m' % problem.level
|
||||||
|
line += max(38 - len(line), 0) * ' '
|
||||||
|
line += problem.desc
|
||||||
|
if problem.rule:
|
||||||
|
line += ' \033[2m(%s)\033[0m' % problem.rule
|
||||||
|
return line
|
@ -0,0 +1,52 @@
|
|||||||
|
# Copyright (C) 2016 Adrien Vergé
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from yamllint.linter import PROBLEM_LEVELS
|
||||||
|
|
||||||
|
|
||||||
|
def format_results(results, no_warn):
|
||||||
|
max_level = 0
|
||||||
|
|
||||||
|
for file in results:
|
||||||
|
print('::group::%s' % file)
|
||||||
|
|
||||||
|
for problem in results[file]:
|
||||||
|
max_level = max(max_level, PROBLEM_LEVELS[problem.level])
|
||||||
|
if no_warn and (problem.level != 'error'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(format_problem(problem, file))
|
||||||
|
|
||||||
|
print('::endgroup::')
|
||||||
|
print('')
|
||||||
|
|
||||||
|
return max_level
|
||||||
|
|
||||||
|
|
||||||
|
def format_problem(problem, filename):
|
||||||
|
line = '::'
|
||||||
|
line += problem.level
|
||||||
|
line += ' file=' + filename + ','
|
||||||
|
line += 'line=' + format(problem.line) + ','
|
||||||
|
line += 'col=' + format(problem.column)
|
||||||
|
line += '::'
|
||||||
|
line += format(problem.line)
|
||||||
|
line += ':'
|
||||||
|
line += format(problem.column)
|
||||||
|
line += ' '
|
||||||
|
if problem.rule:
|
||||||
|
line += '[' + problem.rule + '] '
|
||||||
|
line += problem.desc
|
||||||
|
return line
|
@ -0,0 +1,39 @@
|
|||||||
|
# Copyright (C) 2016 Adrien Vergé
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from yamllint.linter import PROBLEM_LEVELS
|
||||||
|
|
||||||
|
|
||||||
|
def format_results(results, no_warn):
|
||||||
|
max_level = 0
|
||||||
|
|
||||||
|
for file in results:
|
||||||
|
for problem in results[file]:
|
||||||
|
max_level = max(max_level, PROBLEM_LEVELS[problem.level])
|
||||||
|
if no_warn and (problem.level != 'error'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(format_problem(problem, file))
|
||||||
|
|
||||||
|
return max_level
|
||||||
|
|
||||||
|
|
||||||
|
def format_problem(problem, filename):
|
||||||
|
return ('%(file)s:%(line)s:%(column)s: [%(level)s] %(message)s' %
|
||||||
|
{'file': filename,
|
||||||
|
'line': problem.line,
|
||||||
|
'column': problem.column,
|
||||||
|
'level': problem.level,
|
||||||
|
'message': problem.message})
|
@ -0,0 +1,45 @@
|
|||||||
|
# Copyright (C) 2016 Adrien Vergé
|
||||||
|
#
|
||||||
|
# This program is free software: you can redistribute it and/or modify
|
||||||
|
# it under the terms of the GNU General Public License as published by
|
||||||
|
# the Free Software Foundation, either version 3 of the License, or
|
||||||
|
# (at your option) any later version.
|
||||||
|
#
|
||||||
|
# This program is distributed in the hope that it will be useful,
|
||||||
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
# GNU General Public License for more details.
|
||||||
|
#
|
||||||
|
# You should have received a copy of the GNU General Public License
|
||||||
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
from yamllint.linter import PROBLEM_LEVELS
|
||||||
|
|
||||||
|
|
||||||
|
def format_results(results, no_warn):
|
||||||
|
max_level = 0
|
||||||
|
|
||||||
|
for file in results:
|
||||||
|
print(file)
|
||||||
|
|
||||||
|
for problem in results[file]:
|
||||||
|
max_level = max(max_level, PROBLEM_LEVELS[problem.level])
|
||||||
|
if no_warn and (problem.level != 'error'):
|
||||||
|
continue
|
||||||
|
|
||||||
|
print(format_problem(problem))
|
||||||
|
|
||||||
|
print('')
|
||||||
|
|
||||||
|
return max_level
|
||||||
|
|
||||||
|
|
||||||
|
def format_problem(problem):
|
||||||
|
line = ' %d:%d' % (problem.line, problem.column)
|
||||||
|
line += max(12 - len(line), 0) * ' '
|
||||||
|
line += problem.level
|
||||||
|
line += max(21 - len(line), 0) * ' '
|
||||||
|
line += problem.desc
|
||||||
|
if problem.rule:
|
||||||
|
line += ' (%s)' % problem.rule
|
||||||
|
return line
|
Loading…
Reference in New Issue