Add --stdin-display-name to modify report output

This commit is contained in:
Ian Cordasco 2016-06-06 19:46:29 -05:00
parent 689562f1e8
commit 02bcbee245
No known key found for this signature in database
GPG key ID: 656D3395E4A9791A
3 changed files with 33 additions and 0 deletions

View file

@ -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.

View file

@ -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(

View file

@ -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