Skip to content

feat: add custom walker support#698

Open
tobim wants to merge 7 commits into
numtide:mainfrom
tobim:push-spzzmzrpkzzq
Open

feat: add custom walker support#698
tobim wants to merge 7 commits into
numtide:mainfrom
tobim:push-spzzmzrpkzzq

Conversation

@tobim
Copy link
Copy Markdown

@tobim tobim commented May 15, 2026

As the title says.

Example: Format a git repo + a specific submodule:

walk = "repoPlusSubmodule"

[walker.repoPlusSubmodule]
command = "bash"
options = [
  "-c",
  '''
    submodule="path/to/submodule"
    {
      git ls-files --cached --others --exclude-standard --full-name
      git -C "$submodule" ls-files --cached --others --exclude-standard --full-name \
        | sed "s#^#$submodule/#"
    }
  ''',
]

Example: Format a pijul repo:

walk = "pijul"

[walker.pijul]
command = "pijul"
options = ["ls"]

tobim added 5 commits May 15, 2026 08:15
Add documentation for selecting a custom walker with the global
walk option and defining its command and options under [walker.<name>].
Document that custom walker commands run from the tree root, emit one
relative path per line, and do not need to handle path arguments.
Parse [walker.<name>] tables into the configuration model and validate
walker names, commands, and walk values. Accept documented camel-case
walker names even when Viper normalizes table keys.
Introduce a command-backed walker reader that runs from the tree root,
reads one path per stdout line, filters configured subpaths inside
treefmt, and converts accepted paths into walk.File values. Route custom
walk names through the format command without changing built-in walkers.
Cover selecting a custom walker from treefmt.toml, passing configured
walker options, and filtering walker output when treefmt is invoked with
a directory path argument.
Use bash -c for custom walker test commands instead of temporary scripts
with /usr/bin/env shebangs, so the tests also run inside the Nix build
sandbox.
tobim added 2 commits May 15, 2026 08:56
Make the custom walker own its stdout and stderr pipes instead of
combining StdoutPipe with a concurrent Wait call. This avoids surfacing
a spurious file-closed read error at process exit and preserves command
failures for Close().
Refactor custom walker configuration lookup to satisfy nesting limits,
remove an unused gosec suppression, and adjust test spacing to satisfy
golangci-lint in the Nix check derivation.
Copy link
Copy Markdown
Collaborator

@jfly jfly left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tobim, thanks for the contribution! I am supportive of this change, but haven't had a chance to read the code yet.

I wanted to warn you that #694 touches some of the same code you've touched here. It may land before this PR, apologies if the conflicts are annoying to deal with.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants