diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-02-10 22:44:23 -0600 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-02-10 22:44:27 -0600 |
| commit | c20793b49c8421059b702943360d38fd2c76304f (patch) | |
| tree | 1ee8f6b8a453b36677fd8c7885ad204ced7d9dc8 /flake8 | |
| parent | f824cbae9321527214b9fb9c3e7688c1d05f4b47 (diff) | |
| download | flake8-c20793b49c8421059b702943360d38fd2c76304f.tar.gz | |
Add internal documentation around default formatters
Diffstat (limited to 'flake8')
| -rw-r--r-- | flake8/formatting/default.py | 45 |
1 files changed, 27 insertions, 18 deletions
diff --git a/flake8/formatting/default.py b/flake8/formatting/default.py index 036d13f..e0686a0 100644 --- a/flake8/formatting/default.py +++ b/flake8/formatting/default.py @@ -2,19 +2,21 @@ from flake8.formatting import base -class Default(base.BaseFormatter): - """Default formatter for Flake8. +class SimpleFormatter(base.BaseFormatter): + """Simple abstraction for Default and Pylint formatter commonality. - This also handles backwards compatibility for people specifying a custom - format string. - """ + Sub-classes of this need to define an ``error_format`` attribute in order + to succeed. The ``format`` method relies on that attribute and expects the + ``error_format`` string to use the old-style formatting strings with named + parameters: - error_format = '%(path)s:%(row)d:%(col)d: %(code)s %(text)s' + * code + * text + * path + * row + * col - def after_init(self): - """Check for a custom format string.""" - if self.options.format.lower() != 'default': - self.error_format = self.options.format + """ def format(self, error): """Format and write error out. @@ -31,15 +33,22 @@ class Default(base.BaseFormatter): } -class Pylint(Default): - """Pylint formatter for Flake8.""" +class Default(SimpleFormatter): + """Default formatter for Flake8. - error_format = '%(path)s:%(row)d: [%(code)s] %(text)s' + 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): - """Do not check the value of --format. + """Check for a custom format string.""" + if self.options.format.lower() != 'default': + self.error_format = self.options.format - In the default formatter, this makes sense for backwards - compatibility, but it does not make sense here. - """ - pass + +class Pylint(SimpleFormatter): + """Pylint formatter for Flake8.""" + + error_format = '%(path)s:%(row)d: [%(code)s] %(text)s' |
