Completed
Pull Request — master (#1438)
by Sudheesh
01:41 queued 14s
created

bears.js.ESLintBear.run()   A

Complexity

Conditions 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 12
rs 9.4285
1
import re
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
8
9
class ESLintBear(LocalBear, Lint):
10
    executable = 'eslint'
11
    arguments = '--no-ignore --no-color -f=unix'
12
    output_regex = re.compile(
13
        r'(?P<file>.+?)\:(?P<line>\d+)\:(?P<column>\d+)\: '
14
        r'(?P<message>.+?)\[(?P<severity>(Error|Warning))/(?P<ruleId>.+?)\]')
15
    severity_map = {
16
        "Error": RESULT_SEVERITY.MAJOR,
17
        "Warning": RESULT_SEVERITY.NORMAL
18
    }
19
20
    def run(self, filename, file, eslint_config: str=""):
21
        '''
22
        Checks the code with eslint. This will run eslint over each of the files
23
        seperately.
24
25
        :param eslint_config: The location of the .eslintrc config file.
26
        '''
27
        if eslint_config:
28
            self.arguments += (" --config "
29
                               + escape_path_argument(eslint_config))
30
31
        return self.lint(filename)
32