mirror of
https://github.com/davidhalter/parso.git
synced 2025-12-06 12:54:29 +08:00
Fix E392.
This commit is contained in:
@@ -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']
|
||||||
|
|||||||
@@ -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')
|
||||||
|
|||||||
Reference in New Issue
Block a user