Skip to content

Exclude files from formatting with yamark.toml - #47

Merged
t-kalinowski merged 9 commits into
mainfrom
feat/config-exclude
Nov 16, 2026
Merged

t-kalinowski merged 9 commits into
mainfrom
feat/config-exclude

Conversation

@t-kalinowski

Copy link
Copy Markdown
Member

Add [format] exclude so a repository can leave selected files unchanged across the CLI, Git filter, and editor, including format-on-save. Closes #46.

[format]
exclude = ["slides/deck.qmd", "*.generated.md"]
Entry point Behavior for excluded files
Directory walk or explicit path Counted as skipped without being read or written.
--stdin-file-path Input is returned byte for byte without decoding, and the command exits 0. Editors therefore leave excluded files unchanged during Format Document and format-on-save; a configured next formatter still runs.
Git clean and smudge filters Input is returned byte for byte without decoding, and the command exits 0.

yamark to-yaml does not read exclude.

Design choices and alternatives

Alternatives to adding exclude have different scopes or trade-offs:

  • Ignore files: Applying .gitignore or .ignore to explicit paths and stdin would silently change behavior for users who explicitly format ignored files. An ignored file, such as an untracked draft, may still be one the user wants to format explicitly; conversely, putting a tracked file in .gitignore does not exclude it. Ruff has a separate force-exclude for this distinction. Ignore files continue to prune directory walks only.
  • Editor setting: An extension path list could disagree with the CLI and Git filter, and it would live in user settings. yamark.toml gives the entry points one repository-level answer.
  • In-file directive: <!-- fmt: skip file --> remains available, including after Quarto front matter, but it requires editing the file.
  • Git attributes: .gitattributes -filter affects only Git. It remains the option for removing a file from the Git filter while keeping normal formatting.

Within the exclude design:

  • Pattern syntax: Plain [paths]-style keys would be less expressive. Gitignore syntax covers directories, globs, anchoring, and negation; it matches Air's exclude and uses the existing ignore crate without a new dependency.
  • Excluded stdin: An error would cause format-on-save or git add to fail. Passing input through with status 0 lets editors and Git consume stdout; skipping decoding also permits non-UTF-8 input.
  • Matching: Patterns are relative to the config directory and never match outside it. As in Git, ! cannot re-include a file below an excluded directory, and a symlink matches by its own name; [paths] keys continue to match resolved locations.

Public-facing changes

  • Add exclude across formatting, stdin, Git filters, and the editor. Git filter adopt, join, and check skip round-trip verification for excluded files while still counting them.
  • Fix [paths] overrides for nonexistent stdin paths through symlinked directories or on Windows, where they could previously fail to match the config directory.
  • Update documentation and release notes.

Internal changes

  • Compile and match exclusions in src/config.rs; skip excluded candidates before reading them.
  • Read stdin as bytes before decoding, and preserve bytes through Git filter handling.

Testing

  • scripts/check.sh on macOS: formatting, clippy, the full cargo test suite including CLI transcripts, external tests, and editor tests.
  • New coverage is in tests/cases/config_exclude_*.case, tests/cases/git_filter_clean_excluded.case, tests/spec_cli/, and tests/git_filter_paths.rs.

Windows behavior, including verbatim path prefixes and symlink privileges, was not run locally and relies on CI.

Allow `[format] exclude` in `yamark.toml` to list gitignore-style
patterns relative to the config directory. Matching files are skipped
without being read when selected explicitly or by directory traversal.
For `--stdin-file-path` and Git filters, the input passes through
unchanged. Patterns do not match files outside the config directory.

Ignore files only affect directory walks, so they cannot exclude a file
from editor format-on-save, which uses `--stdin-file-path`.
Describe the pattern rules and results for each way of selecting a
file. Add examples for editor format-on-save and explain how exclusions
interact with Git filters and chained editor formatters. Add a release
note and document where exclusions are applied.
Explain how exclusion patterns apply to explicit paths, stdin, and
editors. Clarify that patterns are relative to the config directory
and that a configured next formatter still runs.
Canonicalize the deepest existing ancestor of a stdin path, then
resolve the remaining components. This lets `[paths]` overrides and
`exclude` patterns match paths that do not exist on disk.

Previously, matching could fail on Windows or when a path passed
through a symlinked directory.
A `!` pattern cannot re-include a file below an excluded directory,
regardless of pattern order, matching Git's behavior. A later `!`
pattern can still re-include a file matched by a file-level pattern.
Canonicalizing paths before matching exclusions caused symlinks to
match their targets' names. Match names below the config directory as
written, while identifying the config directory by its canonical path.
Path overrides continue to match resolved locations.

Keep excluded and formatted candidates separate when deduplicating, so
an excluded symlink does not hide its target from the same run.
Excluded stdin was decoded before exclusion was checked, so UTF-16 and
invalid UTF-8 input failed, including through the Git clean filter.
Return excluded input byte for byte; non-excluded input still requires
UTF-8.

Skip round-trip verification for excluded files during Git filter
adoption, joining, and checking, and write smudged files as bytes.
Excluded files still count in the reported Markdown file total.
Describe how exclusions match symlink names and how excluded stdin and
Git filter content pass through without decoding. Record the distinction
from resolved path overrides and identify the tests covering symlinks
and non-UTF-8 input.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c873c9a0f2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/config.rs Resolved
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 16, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-16T14:47:05.297930Z cc53a5a New commits
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

Lexically collapsing `..` after a symlink could cause an excluded file
to be formatted. Resolve the path through its last `..` component
using the filesystem when possible, keeping later names as written.
@t-kalinowski
t-kalinowski merged commit 6cb9852 into main Nov 16, 2026
3 checks passed
@t-kalinowski
t-kalinowski deleted the feat/config-exclude branch December 3, 2026 13:07
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.

Exclude a file from format-on-save without editing the file

1 participant