-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathlinter.py
62 lines (49 loc) · 1.69 KB
/
linter.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
#
# linter.py
# Linter for SublimeLinter3, a code checking framework for Sublime Text 3
#
# Written by Ivan Filenko
# Copyright (c) 2017 Ivan Filenko
#
# License: MIT
#
"""This module exports the Dockerfilelint plugin class."""
import json
from SublimeLinter.lint import Linter, util
class Dockerfilelint(Linter):
"""Provides an interface to dockerfilelint."""
syntax = 'dockerfile'
cmd = 'dockerfilelint --json'
executable = 'dockerfilelint'
version_args = '--version'
version_re = r'(?P<version>\d+\.\d+\.\d+)'
version_requirement = '>= 1.4.0'
config_file = ('.dockerfilelintrc', '~')
# The following regex parses text in format <file>:<line>:<error>:<message>\n
#
# Possible Bug & Deprecation marked as errors
#
# Optimization & Clarity marked as warnings
regex = (
r'^.+?:(?P<line>\d+):'
r'(?:(?P<error>Possible Bug|Deprecation|)|(?P<warning>Optimization|Clarity|)):'
r'(?P<message>.+)$\r?\n'
)
multiline = True
error_stream = util.STREAM_STDOUT
selectors = {}
defaults = {}
def run(self, cmd, code):
output = super().run(cmd, code)
return self.format(output)
def format(self, output):
"""Formats json output to text <file>:<line>:<error>:<message>\n"""
json_output = json.loads(output)
formatted_lines = []
for issue in json_output['files'][0]['issues']:
file = json_output['files'][0]['file']
line = issue['line']
error = issue['category']
message = issue['description']
formatted_lines.append(''.join([file, ':', line, ':', error, ':', message, "\n"]))
return ''.join(formatted_lines)