summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/source/user/options.rst24
-rw-r--r--flake8/main/cli.py7
-rw-r--r--flake8/style_guide.py2
3 files changed, 33 insertions, 0 deletions
diff --git a/docs/source/user/options.rst b/docs/source/user/options.rst
index ce30bdf..e336daa 100644
--- a/docs/source/user/options.rst
+++ b/docs/source/user/options.rst
@@ -192,6 +192,30 @@
another-example*.py
+.. option:: --stdin-display-name=<display_name>
+
+ Provide the name to use to report warnings and errors from code on stdin.
+
+ Instead of reporting an error as something like:
+
+ .. code::
+
+ stdin:82:73 E501 line too long
+
+ You can specify this option to have it report whatever value you want
+ instead of stdin.
+
+ This defaults to: ``stdin``
+
+ Command-line example:
+
+ .. prompt:: bash
+
+ cat file.py | flake8 --stdin-display-name=file.py -
+
+ This **can not** be specified in config files.
+
+
.. option:: --format=<format>
Select the formatter used to display errors to the user.
diff --git a/flake8/main/cli.py b/flake8/main/cli.py
index b426e1e..0b50e27 100644
--- a/flake8/main/cli.py
+++ b/flake8/main/cli.py
@@ -86,6 +86,13 @@ def register_default_options(option_manager):
'separated list. (Default: %default)',
)
+ add_option(
+ '--stdin-display-name', default='stdin',
+ help='The name used when reporting errors from code passed via stdin.'
+ ' This is useful for editors piping the file contents to flake8.'
+ ' (Default: %default)',
+ )
+
# TODO(sigmavirus24): Figure out --first/--repeat
add_option(
diff --git a/flake8/style_guide.py b/flake8/style_guide.py
index 57d86b2..6be9ff6 100644
--- a/flake8/style_guide.py
+++ b/flake8/style_guide.py
@@ -237,6 +237,8 @@ class StyleGuide(object):
"""Handle an error reported by a check."""
error = Error(code, filename, line_number, column_number, text,
physical_line)
+ if error.filename is None or error.filename == '-':
+ error = error._replace(filename=self.options.stdin_display_name)
error_is_selected = (self.should_report_error(error.code) is
Decision.Selected)
is_not_inline_ignored = self.is_inline_ignored(error) is False