diff options
| author | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-07-10 01:29:17 +0000 |
|---|---|---|
| committer | Ian Cordasco <graffatcolmingov@gmail.com> | 2016-07-10 01:29:17 +0000 |
| commit | edd84fba5298cedfb3c6f456a00107f1d3f642c2 (patch) | |
| tree | f383a70924372f6e8c3a691f455d469cb2f74d03 /src | |
| parent | 7ea6da2d55b8c5120358ba8aec16bde8f798e371 (diff) | |
| parent | e977c6671a470d431ffe869069d95692e846d261 (diff) | |
| download | flake8-edd84fba5298cedfb3c6f456a00107f1d3f642c2.tar.gz | |
Merge branch 'bug/157' into 'master'
Handle errors reported in empty files
*Description of changes*
Some plugins return errors in empty files which previously caused an IndexError.
*Related to:* #157
See merge request !71
Diffstat (limited to 'src')
| -rw-r--r-- | src/flake8/formatting/base.py | 5 | ||||
| -rw-r--r-- | src/flake8/processor.py | 8 |
2 files changed, 10 insertions, 3 deletions
diff --git a/src/flake8/formatting/base.py b/src/flake8/formatting/base.py index 4fda6f4..7c2e4b5 100644 --- a/src/flake8/formatting/base.py +++ b/src/flake8/formatting/base.py @@ -123,8 +123,9 @@ class BaseFormatter(object): :rtype: str """ - if not self.options.show_source: - return None + if not self.options.show_source or error.physical_line is None: + return '' + pointer = (' ' * error.column_number) + '^' # Physical lines have a newline at the end, no need to add an extra # one diff --git a/src/flake8/processor.py b/src/flake8/processor.py index 1824ed1..76c5512 100644 --- a/src/flake8/processor.py +++ b/src/flake8/processor.py @@ -250,7 +250,13 @@ class FileProcessor(object): def line_for(self, line_number): """Retrieve the physical line at the specified line number.""" - return self.lines[line_number - 1] + adjusted_line_number = line_number - 1 + # NOTE(sigmavirus24): Some plugins choose to report errors for empty + # files on Line 1. In those casese, we shouldn't bother trying to + # retrieve a physical line (since none exist). + if 0 <= adjusted_line_number < len(self.lines): + return self.lines[adjusted_line_number] + return None def next_line(self): """Get the next line from the list.""" |
