Bring every CRAP score under 10 except the option parser.
The reader, the normalizer, the TypeScript picker, and the fingerprint printer are each a small function. parse_args stays the option switch.
This commit is contained in:
+18
-11
@@ -104,22 +104,29 @@ def _python_nodes(data: bytes, root) -> list:
|
||||
return found
|
||||
|
||||
|
||||
def _keep_typescript_function(node) -> bool:
|
||||
return _has(node, "statement_block") and not _inside(node, _TS_FUNCTION)
|
||||
|
||||
|
||||
def _typescript_parent(node):
|
||||
parent = node.parent
|
||||
if parent is None or parent.type not in _DEFINITION_PARENTS:
|
||||
return None
|
||||
if _inside(parent, _TS_FUNCTION):
|
||||
return None
|
||||
return parent
|
||||
|
||||
|
||||
def _typescript_nodes(data: bytes, root) -> list:
|
||||
found = []
|
||||
for node in descendants(root):
|
||||
if node.type == "function_declaration":
|
||||
if _has(node, "statement_block") and not _inside(node, _TS_FUNCTION):
|
||||
found.append(node)
|
||||
elif node.type == "method_definition":
|
||||
if _has(node, "statement_block") and not _inside(node, _TS_FUNCTION):
|
||||
if node.type in {"function_declaration", "method_definition"}:
|
||||
if _keep_typescript_function(node):
|
||||
found.append(node)
|
||||
elif node.type in {"arrow_function", "function_expression"}:
|
||||
parent = node.parent
|
||||
if parent is None or parent.type not in _DEFINITION_PARENTS:
|
||||
continue
|
||||
if _inside(parent, _TS_FUNCTION):
|
||||
continue
|
||||
found.append(parent)
|
||||
parent = _typescript_parent(node)
|
||||
if parent is not None:
|
||||
found.append(parent)
|
||||
return found
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user