View on GitHub

Graft Documentation

Safe, structural code transformation using Tree-sitter

Rule Files (TOML)

For complex refactorings or recurring tasks, you can define rules in a TOML file.

Rule Structure

A rule file consists of an array of rules:

[[rules]]
name = "upgrade-api"
language = "rust"
priority = 10
query = """
(call_expression
  function: (identifier) @name (#eq? @name "old_api")
  arguments: (arguments) @args) @target
"""
template = "new_api${args}"

Fields

Using a Rule File

Pass the -f or --rule-file flag:

graft src/ -f my_rules.toml --in-place

Graft will:

  1. Load all rules from the file.
  2. Filter rules that match the language of each target file.
  3. Sort matching rules by priority (descending).
  4. Apply them sequentially to the file.