25 lines
494 B
Python
25 lines
494 B
Python
|
import re
|
||
|
|
||
|
|
||
|
def detect_missplaced_return(code):
|
||
|
regex = re.compile(
|
||
|
r"def .+:.*\n(?P<indent> +)\S.*(?:\n(?P=indent)(?:(?P<return>return.*)|(?P<ireturn> *return.*)|.*))+",
|
||
|
re.MULTILINE,
|
||
|
)
|
||
|
|
||
|
result = regex.search(code)
|
||
|
|
||
|
if not result:
|
||
|
return False
|
||
|
|
||
|
if result.group("return"):
|
||
|
return False
|
||
|
|
||
|
if not result.group("ireturn"):
|
||
|
return False
|
||
|
|
||
|
# print("Flaw 4: Missplaced return statement")
|
||
|
# print(result.group(0))
|
||
|
|
||
|
return True
|