mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-04 12:16:53 +00:00
Add default formatting class
This commit is contained in:
parent
7828b63002
commit
81495fd859
3 changed files with 36 additions and 1 deletions
32
flake8/formatting/default.py
Normal file
32
flake8/formatting/default.py
Normal 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,
|
||||
}
|
||||
|
|
@ -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.',
|
||||
)
|
||||
|
|
|
|||
3
setup.py
3
setup.py
|
|
@ -70,6 +70,9 @@ setuptools.setup(
|
|||
'flake8.extension': [
|
||||
'F = flake8.plugins.pyflakes:FlakesChecker',
|
||||
],
|
||||
'flake8.format': [
|
||||
'default = flake8.formatting.default.Default',
|
||||
],
|
||||
},
|
||||
classifiers=[
|
||||
"Environment :: Console",
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue