Failed Conditions
Pull Request — master (#1297)
by Sudheesh
01:51
created

bears.perl.PerlCriticBear   A

Complexity

Total Complexity 2

Size/Duplication

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 16 2
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