Fix E392.

This commit is contained in:
Dave Halter
2017-07-06 01:46:52 +02:00
parent 0a76c45153
commit 280f3edf6d
2 changed files with 16 additions and 1 deletions

View File

@@ -642,6 +642,9 @@ class PEP8Normalizer(Normalizer):
indentation = re.match('[ \t]*', line).group(0) indentation = re.match('[ \t]*', line).group(0)
start_pos = leaf.line + i, len(indentation) start_pos = leaf.line + i, len(indentation)
# TODO check multiline 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 return leaf.value
@@ -676,7 +679,7 @@ class FooRule(Rule):
@PEP8NormalizerConfig.register_rule @PEP8NormalizerConfig.register_rule
class BlankLineAtEnd(Rule): class BlankLineAtEnd(Rule):
code = 'W391' code = 391
message = 'blank line at end of file' message = 'blank line at end of file'
leaf_event = ['endmarker'] leaf_event = ['endmarker']

View File

@@ -19,3 +19,15 @@ def test_eof_newline():
assert_issue('# foobar') assert_issue('# foobar')
assert_issue('') assert_issue('')
assert_issue('foo = 1 # comment') 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')