Skip to content
acfriedmanPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

SwiftWhy

A checker that holds a branch to saying why. Each declaration a branch changes owes a sentence or two of reason, written in a Markdown story that is committed with the code. You can draft the story from the branch's commits, and check it in a hook or in CI.

Why

A diff shows what changed, and a doc comment says what the code does now. Neither says why the change was made. The reason lives in the author's head, or in a pull request description that covers forty changes in one paragraph, and a few months later it is gone. Commit messages help, but one message speaks for everything its commit touched. SwiftWhy asks for the reason while it is cheapest to give, and checks that none is missing:

  • Every change gets its reason. Each declaration that is new, gone, moved, or changed owes a note of its own, so a reviewer looking at one change reads why it was made.
  • Reasons live with the code. A story is a Markdown file committed on its branch. It travels to review, and stays in the repository as the record of why.
  • Checked, not hoped for. swiftwhy check fails when a change has no reason, and prints each gap in compiler format at the declaration that changed.
  • Drafted for you. swiftwhy draft starts the story: a theme per commit, with the commit's message as its prose, and a note to fill in for each change.
  • Only real changes count. Declarations are compared by name and by what they say. Moving code, reformatting it, or rewrapping a doc comment owes nothing.

Say a branch named price changes one method of a cart:

struct Cart {
    /// The sum of every line.
    func total() -> Double { lines.reduce(0) { $0 + $1.price } }
}

swiftwhy check says what the story leaves out:

Sources/Shop/Cart.swift:2:1: error: ``Cart/total()`` changed, and the story gives no reason for it. Add a note headed by that link, under the theme that explains it. [no-reason]

And the story, at .swiftwhy/changes/price.md, answers it:

# Price carts in fractions

Totals were rounded to whole cents line by line, so long carts lost money.

## Totals keep their cents

``Cart`` adds prices as they are, and rounds once, when the total is shown.

### ``Cart/total()``

Returns a `Double`, since a whole number cannot hold a fraction of a cent.

Get started

SwiftWhy needs macOS 14+ and Swift 6 (Xcode 16 or later), and a project kept in git.

  1. Install it with Mint, and put ~/.mint/bin on your PATH:

    mint install acfriedman/SwiftWhy
  2. On a branch with some work on it, draft the branch's story:

    swiftwhy draft --write Sources
  3. Open the story it names, and replace each placeholder with the reason, in a sentence or two.

  4. Check that nothing is left out, then commit the story with the branch:

    swiftwhy check Sources

Learn more

Guide Covers
Installation Mint, a version pinned in your repository, building from source
Usage both commands, every flag, the output, exit codes, and which files are read
Setup adopting it on a team, commit hooks, the pre-commit framework, Xcode, CI
Stories the story's format, how links name code, what owes a reason, and what is no change
Configuration .swiftwhy.json: where stories are kept, the base branch, tests
Advanced how changes are matched, the commits behind a draft, speed, the libraries

License

Copyright 2026 Andrew C. Friedman. Licensed under the MIT License.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages