diff --git a/README.md b/README.md index ca4e255..3fbdb1c 100644 --- a/README.md +++ b/README.md @@ -73,6 +73,10 @@ template = "gpl3" # indicators = [] # Optional line prepended to every header. Supports template placeholders. # greetings = "بِسْمِ اللَّهِ الرَّحْمَنِ الرَّحِيم" + +# Directories or files to exclude by name or relative path suffix. +# TOML files are always ignored by default (Cargo.toml is still synced). +# ignore = ["vendor", "generated.rs"] ``` ## Header Configuration @@ -109,6 +113,37 @@ This will produce: // SPDX-License-Identifier: Apache-2.0 OR MIT ``` +## File Selection + +The `ignore` field at the top level of `forehead.toml` controls which files and directories are excluded from processing. + +```toml +ignore = ["vendor", "generated.rs", "build/out.rs"] +``` + +**Matching rules:** + +- **Name match** — an entry matches if it equals the file or directory name. `ignore = ["vendor"]` excludes any directory named `vendor` and its entire subtree. +- **Path suffix match** — an entry matches if the file's relative path ends with it. `ignore = ["gen.rs"]` excludes `src/gen.rs`, `build/gen.rs`, etc., without needing to specify the full path. + +**Default exclusions:** + +| Entry | Reason | +|-------|--------| +| `.git/` | Git internals | +| `target/` | Rust build output | +| `node_modules/` | JavaScript dependencies | +| `.github/` | GitHub Actions workflows and CI config | +| `Cargo.lock` | Rust lockfile (auto-generated) | +| `forehead.toml` | The tool's own config | +| `*.toml` (except `Cargo.toml`) | Config files; `Cargo.toml` is still visited for its `license` field | + +The default exclusions are always applied — they don't need to be listed in `ignore`. The `ignore` list is additive on top of them. + +**Legacy key:** The old key name `skip` is still accepted as an alias for backward compatibility. + +**Idempotent application:** When applying headers, forehead detects stale license headers anywhere in a file (not just at the top) and replaces them instead of stacking a new header on top. This means headers are never duplicated, even if the file was previously modified by another tool or an older version of forehead. + ## Template Placeholders | Placeholder | Description | Example | @@ -127,13 +162,15 @@ This will produce: | Comment Style | Languages | |--------------|-----------| | `//` line | Rust, Go, C/C++, Java, JS/TS, Swift, Kotlin, Dart, Zig, PHP, C#, Scala, Svelte, Vue | -| `#` line | Python, Ruby, Shell, YAML, TOML, R, Julia, Perl, Nix, Makefile, CMake, Dockerfile, config files | +| `#` line | Python, Ruby, Shell, YAML, R, Julia, Perl, Nix, Makefile, CMake, Dockerfile, config files | | `--` line | SQL, Haskell, Lua, Ada, VHDL | | `%` line | TeX/LaTeX, MATLAB, Prolog | | `;` line | Lisp, Clojure, Scheme | | `` block | HTML, XML, SVG, Markdown | | `/* */` block | CSS, SCSS, Less, GraphQL, Protocol Buffers, Solidity | +> **Note:** TOML files are skipped by default and are not processed for headers. `Cargo.toml` is the only exception — it is still visited so forehead can maintain its `license` field, but no comment header is ever added to it. + ## Library Usage ```rust diff --git a/prdoc/pr_20.prdoc b/prdoc/pr_20.prdoc new file mode 100644 index 0000000..318443a --- /dev/null +++ b/prdoc/pr_20.prdoc @@ -0,0 +1,18 @@ +--- +title: "docs: document ignore field, file selection, default exclusions, and dedup in README" +author: balqaasem +pr: 20 + +doc: + - audience: Developer + description: | + Document the new \ignore\ field, file selection matching rules, default + exclusions, and the idempotent header application behavior in the root + README, AGENTS.md, and the init template. + +crates: + - name: forehead-cli + bump: none + - name: forehead-core + bump: none +--- \ No newline at end of file