mirror of
https://github.com/davidhalter/parso.git
synced 2026-01-16 08:07:04 +08:00
Add normalizer support for E701-E704.
This commit is contained in:
@@ -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
|
||||
|
||||
21
test/normalizer_issue_files/E70.py
Normal file
21
test/normalizer_issue_files/E70.py
Normal 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
|
||||
Reference in New Issue
Block a user