by _jayhack_ · 2y ago · 0 comments
This is trivial with codegen.com. Syntax below:
# Iterate through all files in the codebase
for file in codebase.files:
# Check for functions with the pytest.fixture decorator
for function in file.functions:
if any(d.name == "fixture" for d in function.decorators):
# Rename the 'db' parameter to 'database'
db_param = function.get_parameter("db")
if db_param:
db_param.set_name("database")
# Log the modification
print(f"Modified {function.name}")
Live example: https://www.codegen.sh/codemod/4697/public/diffIs each file getting parsed individually with tree-sitter or how is the codebase object constructed?
This enables APIs such as `function.call_sites`, `symbol.usages`, `class.parent_classes`, and more!