Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
gdscript_code_lines = [
"",
*gdscript_code.splitlines(),
] # type: List[str]
formatted_lines = [] # type: FormattedLines
context = Context(
indent=0,
previously_processed_line_number=0,
max_line_length=max_line_length,
gdscript_code_lines=gdscript_code_lines,
standalone_comments=gather_standalone_comments(
gdscript_code, comment_parse_tree
),
inline_comments=gather_inline_comments(gdscript_code, comment_parse_tree),
)
formatted_lines, _ = format_block(
parse_tree.children,
format_class_statement,
context,
GLOBAL_SCOPE_SURROUNDING_EMPTY_LINES_TABLE,
)
formatted_lines.append((None, ""))
formatted_lines_with_inlined_comments = _add_inline_comments(
formatted_lines, context.inline_comments
)
return "\n".join([line for _, line in formatted_lines_with_inlined_comments])
def _format_class_statement(statement: Node, context: Context) -> Outcome:
last_processed_line_no = statement.line
name = statement.children[0].value
formatted_lines = [
(statement.line, "{}class {}:".format(context.indent_string, name))
]
class_lines, last_processed_line_no = format_block(
statement.children[1:],
format_class_statement,
context.create_child_context(last_processed_line_no),
)
formatted_lines += class_lines
return (formatted_lines, last_processed_line_no)
context: Context,
) -> Outcome:
if expr_position is not None:
expr = statement.children[expr_position]
expression_context = ExpressionContext(prefix, statement.line, suffix)
header_lines, last_processed_line_no = format_expression(
expr, expression_context, context
)
offset = expr_position + 1
else:
header_lines = [
(statement.line, "{}{}{}".format(context.indent_string, prefix, suffix))
]
last_processed_line_no = statement.line
offset = 0
body_lines, last_processed_line_no = format_block(
statement.children[offset:],
format_func_statement,
context.create_child_context(last_processed_line_no),
)
return (header_lines + body_lines, last_processed_line_no)
first_statement_offset + 1
if _has_func_args(statement)
else first_statement_offset
)
first_statement_offset = (
first_statement_offset + 1
if _has_parent_call(statement)
else first_statement_offset
)
first_statement_offset = (
first_statement_offset + 1
if _has_return_type(statement)
else first_statement_offset
)
formatted_lines, last_processed_line_no = _format_func_header(statement, context)
func_lines, last_processed_line_no = format_block(
statement.children[first_statement_offset:],
format_func_statement,
context.create_child_context(last_processed_line_no),
)
formatted_lines += func_lines
return (formatted_lines, last_processed_line_no)