Failed Conditions
Pull Request — master (#1109)
by Abdeali
02:02
created

bears.linters.DockerfileLintBear.process_output()   A

Complexity

Conditions 4

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 4
dl 0
loc 12
rs 9.2
1
import json
2
3
from coalib.bearlib.abstractions.Lint import Lint
4
from coalib.bears.LocalBear import LocalBear
5
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
6
from coalib.results.Result import Result
7
8
class DockerfileLintBear(LocalBear, Lint):
9
    executable = 'dockerfile_lint'
10
    arguments = '--json -f'
11
    severity_map = {
12
        "error": RESULT_SEVERITY.MAJOR,
13
        "warn": RESULT_SEVERITY.NORMAL,
14
        "info": RESULT_SEVERITY.INFO}
15
16
    def run(self, filename, file):
17
        '''
18
        Checks the given file with dockerfile_lint.
19
        '''
20
        return self.lint(filename)
21
22
    def process_output(self, output, filename):
23
        output = json.loads(output)
24
        for severity in output:
25
            if severity == "summary":
26
                continue
27
            for issue in output[severity]["data"]:
28
                yield Result.from_values(
29
                    origin=self,
30
                    message=issue["message"],
31
                    file=filename,
32
                    severity=self.severity_map[issue["level"]],
33
                    line=issue["line"])
34