diff --git a/parso/python/normalizer.py b/parso/python/normalizer.py index 755a252..8f8cec6 100644 --- a/parso/python/normalizer.py +++ b/parso/python/normalizer.py @@ -642,6 +642,9 @@ class PEP8Normalizer(Normalizer): indentation = re.match('[ \t]*', line).group(0) start_pos = leaf.line + i, len(indentation) # TODO check multiline indentation. + elif typ == 'endmarker': + if self._newline_count >= 2: + self.add_issue(391, 'Blank line at end of file', leaf) return leaf.value @@ -676,7 +679,7 @@ class FooRule(Rule): @PEP8NormalizerConfig.register_rule class BlankLineAtEnd(Rule): - code = 'W391' + code = 391 message = 'blank line at end of file' leaf_event = ['endmarker'] diff --git a/test/test_pep8.py b/test/test_pep8.py index 3173e9b..ec4cd86 100644 --- a/test/test_pep8.py +++ b/test/test_pep8.py @@ -19,3 +19,15 @@ def test_eof_newline(): assert_issue('# foobar') assert_issue('') assert_issue('foo = 1 # comment') + + +def test_eof_blankline(): + def assert_issue(code): + found = issues(code) + assert len(found) == 1 + issue, = found + assert issue.code == 391 + + assert_issue('asdf = 1\n\n') + assert_issue('# foobar\n\n') + assert_issue('\n\n')