Add default formatting class

This commit is contained in:
Ian Cordasco 2016-02-06 15:22:36 -06:00
parent 7828b63002
commit 81495fd859
3 changed files with 36 additions and 1 deletions

View file

@ -0,0 +1,32 @@
"""Default formatting class for Flake8."""
from flake8.formatting import base
class Default(base.BaseFormatter):
"""Default formatter for Flake8.
This also handles backwards compatibility for people specifying a custom
format string.
"""
error_format = '%(path)s:%(row)d:%(col)d: %(code)s %(text)s'
def after_init(self):
"""Check for a custom format string."""
self.output_fd = None
if self.options.format.lower() != 'default':
self.error_format = self.options.format
def format(self, error):
"""Format and write error out.
If an output filename is specified, write formatted errors to that
file. Otherwise, print the formatted error to standard out.
"""
return self.error_format % {
"code": error.code,
"text": error.text,
"path": error.filename,
"row": error.line_number,
"col": error.column_number,
}

View file

@ -54,7 +54,7 @@ def register_default_options(option_manager):
# TODO(sigmavirus24): Figure out --first/--repeat
add_option(
'--format', metavar='format', default='default', choices=['default'],
'--format', metavar='format', default='default',
parse_from_config=True,
help='Format errors according to the chosen formatter.',
)

View file

@ -70,6 +70,9 @@ setuptools.setup(
'flake8.extension': [
'F = flake8.plugins.pyflakes:FlakesChecker',
],
'flake8.format': [
'default = flake8.formatting.default.Default',
],
},
classifiers=[
"Environment :: Console",