Repository navigation
Exclude files from formatting with yamark.toml - #47
Merged
Merged
Conversation
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.
There was a problem hiding this comment.
💡 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".
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add
[format] excludeso a repository can leave selected files unchanged across the CLI, Git filter, and editor, including format-on-save. Closes #46.--stdin-file-pathyamark to-yamldoes not readexclude.Design choices and alternatives
Alternatives to adding
excludehave different scopes or trade-offs:.gitignoreor.ignoreto 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.gitignoredoes not exclude it. Ruff has a separateforce-excludefor this distinction. Ignore files continue to prune directory walks only.yamark.tomlgives the entry points one repository-level answer.<!-- fmt: skip file -->remains available, including after Quarto front matter, but it requires editing the file..gitattributes-filteraffects only Git. It remains the option for removing a file from the Git filter while keeping normal formatting.Within the
excludedesign:[paths]-style keys would be less expressive. Gitignore syntax covers directories, globs, anchoring, and negation; it matches Air'sexcludeand uses the existingignorecrate without a new dependency.git addto fail. Passing input through with status 0 lets editors and Git consume stdout; skipping decoding also permits non-UTF-8 input.!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
excludeacross formatting, stdin, Git filters, and the editor. Git filteradopt,join, andcheckskip round-trip verification for excluded files while still counting them.[paths]overrides for nonexistent stdin paths through symlinked directories or on Windows, where they could previously fail to match the config directory.Internal changes
src/config.rs; skip excluded candidates before reading them.Testing
scripts/check.shon macOS: formatting, clippy, the fullcargo testsuite including CLI transcripts, external tests, and editor tests.tests/cases/config_exclude_*.case,tests/cases/git_filter_clean_excluded.case,tests/spec_cli/, andtests/git_filter_paths.rs.Windows behavior, including verbatim path prefixes and symlink privileges, was not run locally and relies on CI.