Failed Conditions
Pull Request — master (#1438)
by Sudheesh
01:36
created

bears.js.ESLintBear   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 36
Duplicated Lines 0 %
Metric Value
dl 0
loc 36
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A run() 0 12 2
A _process_issues() 0 14 4
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.misc.Shell import escape_path_argument
7
from coalib.results.Result import Result
8
9
10
class ESLintBear(LocalBear, Lint):
11
    executable = 'eslint'
12
    arguments = '--no-ignore --no-color -f=json'
13
    severity_map = {
14
        "2": RESULT_SEVERITY.MAJOR,
15
        "1": RESULT_SEVERITY.NORMAL,
16
        "0": RESULT_SEVERITY.INFO
17
    }
18
19
    def run(self, filename, file, eslint_config: str=""):
20
        '''
21
        Checks the code with eslint. This will run eslint over each of the files
22
        seperately.
23
24
        :param eslint_config: The location of the .eslintrc config file.
25
        '''
26
        if eslint_config:
27
            self.arguments += (" --config "
28
                               + escape_path_argument(eslint_config))
29
30
        return self.lint(filename)
31
32
    def _process_issues(self, output, filename):
33
        try:
34
            output = json.loads("".join(output))
35
            for lintLines in output[0]['messages']:
36
                if lintLines['severity'] == '0':
37
                    continue
38
                yield Result.from_values(
39
                    origin=self,
40
                    message=lintLines['message'],
41
                    file=filename,
42
                    severity=self.severity_map[str(lintLines['severity'])],
43
                    line=lintLines['line'])
44
        except (json.decoder.JSONDecodeError):
0 ignored issues
show
Unused Code Coding Style introduced by
There is an unnecessary parenthesis after except.
Loading history...
45
            output = {}
46