-
Notifications
You must be signed in to change notification settings - Fork 581
/
Copy pathYAMLLintBear.py
66 lines (59 loc) · 2.23 KB
/
YAMLLintBear.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
from coalib.bearlib.abstractions.Linter import linter
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
from dependency_management.requirements.PipRequirement import PipRequirement
import yaml
@linter(executable='yamllint',
output_format='regex',
output_regex=r'.+:(?P<line>\d+):(?P<column>\d+): '
r'\[(?P<severity>error|warning)\] (?P<message>.+)',
severity_map={'error': RESULT_SEVERITY.MAJOR,
'warning': RESULT_SEVERITY.NORMAL})
class YAMLLintBear:
"""
Check yaml code for errors and possible problems.
You can read more about capabilities at
<http://yamllint.readthedocs.org/en/latest/rules.html>.
"""
LANGUAGES = {'YAML'}
REQUIREMENTS = {PipRequirement('yamllint', '1.12.0')}
AUTHORS = {'The coala developers'}
AUTHORS_EMAILS = {'coala-devel@googlegroups.com'}
LICENSE = 'AGPL-3.0'
CAN_DETECT = {'Syntax', 'Formatting'}
@staticmethod
def generate_config(filename, file,
document_start: bool = None,
max_line_length: int = 80,
):
"""
:param document_start:
Use this rule to require or forbid the use of document start
marker (---).
:param max_line_length:
Maximum number of characters for a line, the newline character
being excluded.
"""
yamllint_configs = {
'extends': 'default',
'rules': {
'document-start': 'disable' if document_start is None
else {'present': document_start},
'line-length': {
'max': max_line_length,
},
},
}
return yaml.dump(yamllint_configs)
@staticmethod
def create_arguments(filename, file, config_file,
yamllint_config: str = '',
):
"""
:param yamllint_config: Path to a custom configuration file.
"""
args = ('-f', 'parsable', filename)
if yamllint_config:
args += ('--config-file=' + yamllint_config,)
else:
args += ('--config-file=' + config_file,)
return args