1
"""Default formatting class for Flake8."""
2
from flake8.formatting import base
5
class SimpleFormatter(base.BaseFormatter):
6
"""Simple abstraction for Default and Pylint formatter commonality.
8
Sub-classes of this need to define an ``error_format`` attribute in order
9
to succeed. The ``format`` method relies on that attribute and expects the
10
``error_format`` string to use the old-style formatting strings with named
23
def format(self, error):
24
"""Format and write error out.
26
If an output filename is specified, write formatted errors to that
27
file. Otherwise, print the formatted error to standard out.
29
return self.error_format % {
32
"path": error.filename,
33
"row": error.line_number,
34
"col": error.column_number,
38
class Default(SimpleFormatter):
39
"""Default formatter for Flake8.
41
This also handles backwards compatibility for people specifying a custom
45
error_format = '%(path)s:%(row)d:%(col)d: %(code)s %(text)s'
48
"""Check for a custom format string."""
49
if self.options.format.lower() != 'default':
50
self.error_format = self.options.format
53
class Pylint(SimpleFormatter):
54
"""Pylint formatter for Flake8."""
56
error_format = '%(path)s:%(row)d: [%(code)s] %(text)s'
59
class FilenameOnly(SimpleFormatter):
60
"""Only print filenames, e.g., flake8 -q."""
62
error_format = '%(path)s'
65
"""Initialize our set of filenames."""
66
self.filenames_already_printed = set()
68
def show_source(self, error):
69
"""Do not include the source code."""
72
def format(self, error):
73
"""Ensure we only print each error once."""
74
if error.filename not in self.filenames_already_printed:
75
self.filenames_already_printed.add(error.filename)
76
return super(FilenameOnly, self).format(error)
79
class Nothing(base.BaseFormatter):
80
"""Print absolutely nothing."""
82
def format(self, error):
86
def show_source(self, error):
87
"""Do not print the source."""