summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorIan Cordasco <graffatcolmingov@gmail.com>2016-07-26 00:41:08 +0000
committerIan Cordasco <graffatcolmingov@gmail.com>2016-07-26 00:41:08 +0000
commitb9658eaaaed6cbfac28428042f03d4ac2c11dba0 (patch)
tree120fa2ee893fe32ec646d9895d588bf1d2af4ae5 /src
parent667a01f8df8a537216494e26e92b2a6e8633f24e (diff)
parent222292c4b2bb595c81d749bfd35ef9adc640bacb (diff)
downloadflake8-b9658eaaaed6cbfac28428042f03d4ac2c11dba0.tar.gz
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
Diffstat (limited to 'src')
-rw-r--r--src/flake8/formatting/base.py3
-rw-r--r--src/flake8/formatting/default.py24
-rw-r--r--src/flake8/main/application.py9
3 files changed, 34 insertions, 2 deletions
diff --git a/src/flake8/formatting/base.py b/src/flake8/formatting/base.py
index c4a626b..2ac0ed8 100644
--- a/src/flake8/formatting/base.py
+++ b/src/flake8/formatting/base.py
@@ -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)
diff --git a/src/flake8/formatting/default.py b/src/flake8/formatting/default.py
index bef8c88..f8e3a66 100644
--- a/src/flake8/formatting/default.py
+++ b/src/flake8/formatting/default.py
@@ -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
diff --git a/src/flake8/main/application.py b/src/flake8/main/application.py
index 5a9866f..1e864fc 100644
--- a/src/flake8/main/application.py
+++ b/src/flake8/main/application.py
@@ -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):