Completed
Pull Request — master (#1404)
by Abdeali
01:43
created

bears.python.PEP8Bear.lint()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 4
rs 10
1
import autopep8
2
3
from coalib.bearlib.abstractions.Lint import Lint
4
from coalib.bearlib.spacing.SpacingHelper import SpacingHelper
5
from coalib.bears.LocalBear import LocalBear
6
from coalib.settings.Setting import typed_list
7
8
9
class PEP8Bear(Lint, LocalBear):
10
    diff_message = "The code does not comply to PEP8."
11
    gives_corrected = True
12
13
    def lint(self, filename, file, **kwargs):
14
        new_file = autopep8.fix_code(''.join(file), options=kwargs)
15
        output = new_file.splitlines(True)
16
        return self.process_output(output, filename, file)
17
18
    def run(self,
19
            filename,
20
            file,
21
            max_line_length: int=80,
22
            tab_width: int=SpacingHelper.DEFAULT_TAB_WIDTH,
23
            pep_ignore: typed_list(str)=(),
24
            pep_select: typed_list(str)=()):
25
        """
26
        Detects and fixes PEP8 incompliant code. This bear will not change
27
        functionality of the code in any way.
28
29
        :param max_line_length: Maximum number of characters for a line.
30
        :param tab_width:       Number of spaces per indent level.
31
        :param pep_ignore:      A list of errors/warnings to ignore.
32
        :param pep_select:      A list of errors/warnings to exclusively apply.
33
        """
34
        return self.lint(filename,
35
                         file,
36
                         ignore=pep_ignore,
37
                         select=pep_select,
38
                         max_line_length=max_line_length,
39
                         indent_size=tab_width)
40