Skip to content
Astel

Prism-native Ruby tooling

Parse once. Change only what you mean.

Astel gives codemods and linters focused APIs for AST traversal, declarative matching, and non-destructive source rewriting.

Ruby 3.3+ · MIT licensed

example.rb Astel::Rewriter

Source

1  old_name
2

Result

1  new_name
2

rewriter.rewrite(validate: :parse)

The original source stays untouched. Conflicting edits fail clearly.

One parse

Keep the AST, comments, errors, and formatting together.

Flat, byte-safe edits

Detect overlaps before rewritten source leaves memory.

Opt-in extensions

Add structured refactors and unified diffs only when needed.

Built for Ruby tools, not framework ceremony.

Use the parts your tool needs. Astel stays a library: no CLI, rule framework, or hidden process pool.

Focused traversal

Visit the tree once while dispatching multiple callbacks by Prism node type.

Declarative matching

Compile reusable patterns with named fields, alternatives, and captures.

Atomic changes

Group related edits in transactions that register together or not at all.

Source-aware output

Preserve encodings, indentation, comments, and CRLF line endings.

A short path from source to safe output.

Read the codemod guide
  1. 1

    Parse

    Create one SourceFile with Prism.

  2. 2

    Dispatch

    Visit relevant node types once.

  3. 3

    Match

    Select exact shapes with compiled patterns.

  4. 4

    Rewrite

    Apply flat edits and validate the result.

Start with one command.

Add Astel to your bundle, then compose only the parsing, matching, and rewriting APIs your tool needs.

Open the full quick start

Terminal

$ bundle add astel

Ruby

require "astel"

source = Astel::SourceFile.from_string("old_name\n")
rewriter = Astel::Rewriter.new(source)
rewriter.replace(source.ast.statements.body.first.location, "new_name")

rewriter.rewrite(validate: :parse)