Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 |
Expand All @@ -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
Expand Down
18 changes: 18 additions & 0 deletions prdoc/pr_20.prdoc
Original file line number Diff line number Diff line change
@@ -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
---
Loading