Skip to content

craftvscruft/mend

Repository files navigation

Mend

Tests License: APACHE

Scripted disciplined refactoring for legacy code

What is this?

Working in "mends" means breaking down large remodeling into tiny auditable steps.

  • A Mend is a series of Steps starting from a known state
  • A Step is an invocation of exactly one known Recipe
  • A Recipe is an executable script taking zero or more arguments
  • A Run leaves a trail of source code changes with one Step per commit, with tests run after each

These tiny steps can often increase the effectiveness of humans working on legacy code. Moreover, this may currently be the only reliable way for Large Language Models (LLMs) to edit code.

What can recipes do?

Recipes are just scripts, they can do anything that can be reliably automated. For many languages, this includes formatting, lint auto-fixes, renames, extract, move, and others.

Most of this functionality has historically been coupled to IDEs. However, there are a few good command line tools available - such as clang-rename for C/C++, Eclim for Java, good old-fashioned sed - and we should build more of them!

The sister project Untangler is an effort to build the first multi-language automation-friendly refactoring CLI.

Status

Beta testing, looking for feedback.

Example

Here we run mend on Yusuke Endoh's 2020 IOCCC winner using the steps in examples/mend.toml.

code refactoring animation

Requirements

  • Building:
    • Rust (tested with 1.71.1)
  • Running
    • git
    • sh on path (usually bound to bash or zsh)

Running

Make sure ~/.cargo/bin is on you path:

export PATH="$PATH:$HOME/.cargo/bin"

Then clone the project and run cargo install:

git clone [email protected]:craftvscruft/mend.git
cd mend

cargo install --path .

Then you can run with mend

mend -f mend.toml

More info on creating mend.toml coming soon, in the meantime checkout examples/mend.toml.

Running without installing

cd mend

cargo run -- <ARGS>

Testing

cargo test

If the approval test results have changed, review them with:

cargo insta review

Author

👤 Ray Myers

Inspiration

📝 License

Copyright © 2023 Ray Myers.

This project is Apache 2 licensed.

About

Repeatable disciplined refactoring of legacy code

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published