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

bears.NaturalLanguage.reSTLintBear.run()   A

Complexity

Conditions 2

Size

Total Lines 21

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 2
dl 0
loc 21
rs 9.3143
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