Completed
Pull Request — master (#1438)
by Sudheesh
01:34
created

bears.js.ESLintBear   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 24
Duplicated Lines 0 %
Metric Value
wmc 2
dl 0
loc 24
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 12 2
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=compact'
12
    output_regex = re.compile(
13
        r'(?P<file>^.+?): line (?P<line>\d+), col (?P<col>\d+), '
14
        r'(?:(?P<severity>Error|Warning)) - (?P<message>.+)',
15
        re.MULTILINE)
16
    severity_map = {
17
        "Error": RESULT_SEVERITY.MAJOR,
18
        "Warning": RESULT_SEVERITY.NORMAL
19
    }
20
21
    def run(self, filename, file, eslint_config: str=""):
22
        '''
23
        Checks the code with eslint. This will run eslint over each of the files
24
        seperately.
25
26
        :param eslint_config: The location of the .eslintrc config file.
27
        '''
28
        if eslint_config:
29
            self.arguments += (" --config "
30
                               + escape_path_argument(eslint_config))
31
32
        return self.lint(filename)
33