Completed
Pull Request — master (#1073)
by Lasse
01:56
created

bears.NaturalLanguage.reSTLintBear   A

Complexity

Total Complexity 2

Size/Duplication

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A run() 0 21 2
1
from restructuredtext_lint import lint
2
3
from coalib.bears.LocalBear import LocalBear
4
from coalib.results.RESULT_SEVERITY import RESULT_SEVERITY
5
from coalib.results.Result import Result
6
7
8
class reSTLintBear(LocalBear):
9
    def run(self, filename, file):
10
        """
11
        Lints reStructuredText.
12
        """
13
        content = ''.join(file)
14
        errors = lint(content)
15
16
        for error in errors:
17
            severity = {
18
                1: RESULT_SEVERITY.INFO,
19
                2: RESULT_SEVERITY.NORMAL,
20
                3: RESULT_SEVERITY.MAJOR,
21
                4: RESULT_SEVERITY.MAJOR}.get(error.level,
22
                                              RESULT_SEVERITY.NORMAL)
23
            yield Result.from_values(
24
                self,
25
                error.message,
26
                file=filename,
27
                line=error.line,
28
                debug_msg=error.full_message,
29
                severity=severity)
30