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

bears.linters.JSHintBear   A

Complexity

Total Complexity 2

Size/Duplication

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 15 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 JSHintBear(LocalBear, Lint):
10
    executable = 'jshint'
11
    arguments = '--verbose'
12
    output_regex = re.compile(
13
        r'.+?: line (?P<line>\d+), col (?P<col>\d+), '
14
        r'(?P<message>.+) \((?P<severity>\S)\d+\)')
15
    severity_map = {
16
        "E": RESULT_SEVERITY.MAJOR,
17
        "W": RESULT_SEVERITY.NORMAL,
18
        "I": RESULT_SEVERITY.NORMAL}
19
20
    def run(self,
21
            filename,
22
            file,
23
            jshint_config: str=""):
24
        '''
25
        Checks the code with jshint. This will run jshint over each file
26
        separately.
27
28
        :param jshint_config: The location of the jshintrc config file.
29
        '''
30
        if jshint_config:
31
            self.arguments += (" --config "
32
                               + escape_path_argument(jshint_config))
33
34
        return self.lint(filename)
35