Avoid index errors when input file is empty #66
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When we try to add suppressions in empty files, it results in index out of range errors. Really, it's a result of a linter error being reported on a non-existent line (i.e. line 1 of empty file). The _add_noqa_to_line function takes in the array of lines and modifies the contents, so the easiest way to avoid this problem is to populate the lines array with a single blank line when the file is empty. Also, the multiline checker has a similar problem, but we can avoid that easily by checking that the error.line is within range before calling multiline_checker.in_multiline_string.