Add normalizer support for E701-E704.

This commit is contained in:
Dave Halter
2017-06-06 08:55:05 +02:00
parent 6bf52e8fe0
commit ebf5850cb9
2 changed files with 35 additions and 0 deletions

View File

@@ -119,6 +119,20 @@ class PEP8Normalizer(Normalizer):
self.add_issue(743, message % 'function', leaf)
else:
self.add_issuadd_issue(741, message % 'variables', leaf)
elif leaf.value == ':':
from parso.python.tree import Flow, Scope
if isinstance(leaf.parent, (Flow, Scope)) and leaf.parent.type != 'lambdef':
next_leaf = leaf.get_next_leaf()
if next_leaf.type != 'newline':
if leaf.parent.type == 'funcdef':
self.add_issue(704, 'Multiple statements on one line (def)', next_leaf)
else:
self.add_issue(701, 'Multiple statements on one line (colon)', next_leaf)
elif leaf.value == ';':
if leaf.get_next_leaf().type in ('newline', 'endmarker'):
self.add_issue(703, 'Statement ends with a semicolon', leaf)
else:
self.add_issue(702, 'Multiple statements on one line (semicolon)', leaf)
for part in leaf._split_prefix():
part

View File

@@ -0,0 +1,21 @@
#: E701:6
if a: a = False
#: E701:41
if not header or header[:6] != 'bytes=': return
#: E702:9
a = False; b = True
#: E702:16 E402
import bdist_egg; bdist_egg.write_safety_flag(cmd.egg_info, safe)
#: E703:12 E402
import shlex;
#: E702:8 E703:22
del a[:]; a.append(42);
#: E704:10
def f(x): return 2
#: E704:16
async def f(x): return 2
#: E704:10
def f(x): return 2 * x
while all is round:
#: E704:10
def f(x): return 2 * x