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
|
|
|
output = json.loads("".join(output)) |
34
|
|
|
|
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
|
|
|
|