Failed Conditions
Pull Request — master (#1297)
by Sudheesh
02:25 queued 39s
created

bears.perl.PerlCriticBear.run()   A

Complexity

Conditions 2

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 16
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.misc.Shell import escape_path_argument
6
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
7
8
9
class PerlCriticBear(LocalBear, Lint):
10
    executable = 'perlcritic'
11
    arguments = '--no-color --verbose "%l|%c|%s|%p|%m (%e)"'
12
    output_regex = re.compile(
13
            r'(?P<line>\d+)\|(?P<column>\d+)\|(?P<severity>\d+)\|'
14
            r'(?P<origin>.*?)\|(?P<message>.*)')
15
    severity_map = {
16
        "1": RESULT_SEVERITY.MAJOR,
17
        "2": RESULT_SEVERITY.MAJOR,
18
        "3": RESULT_SEVERITY.NORMAL,
19
        "4": RESULT_SEVERITY.NORMAL,
20
        "5": RESULT_SEVERITY.INFO}
21
22
    def run(self,
23
            filename,
24
            file,
25
            perlcritic_config: str=""):
26
        '''
27
        Checks the code with perlcritic. This will run perlcritic over
28
        each of the files seperately
29
30
        :param perlcritic_config: Location of the perlcriticrc config file.
31
        '''
32
33
        if perlcritic_config:
34
            self.arguments += (" --config "
35
                               + escape_path_argument(perlcritic_config))
36
37
        return self.lint(filename)
38