Skip to content

Commit

Permalink
Avoid index errors when input file is empty (#66)
Browse files Browse the repository at this point in the history
* Avoid index errors when input file is empty

* Add test for blank file
  • Loading branch information
m-akinc authored Sep 9, 2021
1 parent 85726da commit 0ff7698
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
8 changes: 6 additions & 2 deletions ni_python_styleguide/_acknowledge_existing_errors/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,16 +73,20 @@ def acknowledge_lint_errors(lint_errors):
for bad_file, errors_in_file in lint_errors_by_file.items():
path = pathlib.Path(bad_file)
lines = path.read_text().splitlines(keepends=True)
# sometimes errors are reported on line 1 for empty files.
# to make suppressions work for those cases, add an empty line.
if len(lines) == 0:
lines = [""]
multiline_checker = _InMultiLineStringChecker(error_file=bad_file)

# to avoid double marking a line with the same code, keep track of lines and codes
handled_lines = defaultdict(list)
for error in errors_in_file:
skip = 0

while multiline_checker.in_multiline_string(
while error.line + skip < len(lines) and multiline_checker.in_multiline_string(
lineno=error.line + skip
) and error.line + skip < len(lines):
):
# find when the multiline ends
skip += 1

Expand Down
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# noqa D100: Missing docstring in public module (auto-generated noqa)

0 comments on commit 0ff7698

Please sign in to comment.