mirror of
https://github.com/PyCQA/flake8.git
synced 2026-03-30 18:56:53 +00:00
Merge branch 'bug/180' into 'master'
Handle repeated --quiet options again *Description of changes* Handle `-q`/`--quiet` again. *Related to:* #180 See merge request !89
This commit is contained in:
commit
b9658eaaae
4 changed files with 36 additions and 2 deletions
2
setup.py
2
setup.py
|
|
@ -107,6 +107,8 @@ setuptools.setup(
|
|||
'flake8.report': [
|
||||
'default = flake8.formatting.default:Default',
|
||||
'pylint = flake8.formatting.default:Pylint',
|
||||
'quiet-filename = flake8.formatting.default:FilenameOnly',
|
||||
'quiet-nothing = flake8.formatting.default:Nothing',
|
||||
],
|
||||
},
|
||||
classifiers=[
|
||||
|
|
|
|||
|
|
@ -164,7 +164,8 @@ class BaseFormatter(object):
|
|||
The source code that has been formatted and associated with the
|
||||
line of output.
|
||||
"""
|
||||
self._write(line)
|
||||
if line:
|
||||
self._write(line)
|
||||
if source:
|
||||
self._write(source)
|
||||
|
||||
|
|
|
|||
|
|
@ -54,3 +54,27 @@ class Pylint(SimpleFormatter):
|
|||
"""Pylint formatter for Flake8."""
|
||||
|
||||
error_format = '%(path)s:%(row)d: [%(code)s] %(text)s'
|
||||
|
||||
|
||||
class FilenameOnly(SimpleFormatter):
|
||||
"""Only print filenames, e.g., flake8 -q."""
|
||||
|
||||
error_format = '%(path)s'
|
||||
|
||||
def after_init(self):
|
||||
"""Initialize our set of filenames."""
|
||||
self.filenames_already_printed = set()
|
||||
|
||||
def format(self, error):
|
||||
"""Ensure we only print each error once."""
|
||||
if error.filename not in self.filenames_already_printed:
|
||||
self.filenames_already_printed.add(error.filename)
|
||||
return super(FilenameOnly, self).format(error)
|
||||
|
||||
|
||||
class Nothing(base.BaseFormatter):
|
||||
"""Print absolutely nothing."""
|
||||
|
||||
def format(self, error):
|
||||
"""Do nothing."""
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -181,10 +181,17 @@ class Application(object):
|
|||
# type: () -> NoneType
|
||||
"""Initialize a formatter based on the parsed options."""
|
||||
if self.formatter is None:
|
||||
format_plugin = self.options.format
|
||||
if 1 <= self.options.quiet < 2:
|
||||
format_plugin = 'quiet-filename'
|
||||
elif 2 <= self.options.quiet:
|
||||
format_plugin = 'quiet-nothing'
|
||||
|
||||
if formatter_class is None:
|
||||
formatter_class = self.formatting_plugins.get(
|
||||
self.options.format, self.formatting_plugins['default']
|
||||
format_plugin, self.formatting_plugins['default']
|
||||
).execute
|
||||
|
||||
self.formatter = formatter_class(self.options)
|
||||
|
||||
def make_notifier(self):
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue