Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _tree_invariant_check(input_code, formatted_code):
input_code_parse_tree = parser.parse(input_code)
formatted_code_parse_tree = parser.parse(formatted_code)
loosen_tree_transformer = LoosenTreeTransformer()
input_code_parse_tree = loosen_tree_transformer.transform(input_code_parse_tree)
formatted_code_parse_tree = loosen_tree_transformer.transform(
formatted_code_parse_tree
)
diff = "\n".join(
difflib.unified_diff(
str(input_code_parse_tree.pretty()).splitlines(),
str(formatted_code_parse_tree.pretty()).splitlines(),
)
)
assert input_code_parse_tree == formatted_code_parse_tree, diff
"{} file{} would be reformatted, {} file{} would be left unchanged.".format(
formattable_num,
"s" if formattable_num != 1 else "",
left_unchanged_num,
"s" if left_unchanged_num != 1 else "",
),
file=sys.stderr,
)
sys.exit(1)
else:
formatted_files = set()
for file_path in files:
with open(file_path, "r+") as fh:
code = fh.read()
try:
code_parse_tree = parser.parse(code, gather_metadata=True)
comment_parse_tree = parser.parse_comments(code)
formatted_code = format_code(
gdscript_code=code,
max_line_length=line_length,
parse_tree=code_parse_tree,
comment_parse_tree=comment_parse_tree,
)
except Exception as e:
print(
"exception during formatting of {}".format(file_path),
file=sys.stderr,
)
raise e
if code != formatted_code:
try:
check_formatting_safety(
def main():
arguments = docopt(
__doc__,
version="gdformat {}".format(
pkg_resources.get_distribution("gdtoolkit").version
),
)
files: List[str] = find_files_from(arguments["