Failed Conditions
Pull Request — master (#1307)
by Lasse
01:44
created

bears.java.CheckstyleBear   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 20
Duplicated Lines 0 %
Metric Value
dl 0
loc 20
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 11 1
1
import re
2
from os.path import dirname, abspath, join
3
4
from coalib.bearlib.abstractions.Lint import Lint
5
from coalib.bears.LocalBear import LocalBear
6
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
7
8
9
class CheckstyleBear(LocalBear, Lint):
10
    executable = 'java'
11
    google_checks = join(dirname(abspath(__file__)), 'google_checks.xml')
12
    jar = join(dirname(abspath(__file__)), 'checkstyle.jar')
13
14
    severity_map = {
15
        "INFO": RESULT_SEVERITY.INFO,
16
        "WARN": RESULT_SEVERITY.NORMAL}
17
18
    def run(self, filename, file):
19
        """
20
        Checks the code using `checkstyle` using the Google codestyle
21
        specification.
22
        """
23
        self.output_regex = re.compile(
24
            r'\[(?P<severity>WARN|INFO)\]\s*' + abspath(filename) +
25
            r':(?P<line>\d+)(:(?P<col>\d+))?:\s*'
26
            r'(?P<message>.*?)\s*\[(?P<origin>[a-zA-Z]+?)\]')
27
        self.arguments = '-jar ' + self.jar + ' -c ' + self.google_checks
28
        return self.lint(filename)
29