Skip to content

Commit cc0a19f

Browse files
committed
Fix #240: Allow errors on empty files
The noqa check crashes when the file is empty. The soultion is to not check for noqa when the file is empty -- if it's empty, the user might not possibly put any #noqa comments in there.
1 parent 8d65869 commit cc0a19f

2 files changed

Lines changed: 2 additions & 1 deletion

File tree

CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ Changelog
55
1.x (unreleased)
66
----------------
77

8+
* Allow the checkers to report errors on empty files. (Issue #240)
89
* Fix ignoring too many checks when ``--select`` is used with codes
910
declared in a flake8 extension. (Issue #216)
1011

pep8.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1344,7 +1344,7 @@ def check_ast(self):
13441344
for name, cls, _ in self._ast_checks:
13451345
checker = cls(tree, self.filename)
13461346
for lineno, offset, text, check in checker.run():
1347-
if not noqa(self.lines[lineno - 1]):
1347+
if not self.lines or not noqa(self.lines[lineno - 1]):
13481348
self.report_error(lineno, offset, text, check)
13491349

13501350
def generate_tokens(self):

0 commit comments

Comments
 (0)