Skip to content

harden(branding-lint): clap-aware sub-rule to catch /// doc-comment leaks (#75) - #78

Closed
thehoff wants to merge 1 commit into
developfrom
harden/branding-lint-clap-aware-75
Closed

thehoff wants to merge 1 commit into
developfrom
harden/branding-lint-clap-aware-75

Conversation

@thehoff

@thehoff thehoff commented May 19, 2026

Copy link
Copy Markdown
Owner

Closes #75.

Summary

Adds branding_lint_clap_doc_comments_fail_on_rtk — a 5th test in tests/branding_lint.rs that closes the known weakness of the broad rustdoc-comment mention (///) allowlist rule from #67.

The existing allowlist accepts ALL /// lines. That trade-off (hundreds of legitimate project-name mentions vs. the cost of per-line markers) meant NEW RTK phrasings in clap doc-comments (which become --help output) silently slipped through unless their exact wording already lived in FORBIDDEN_TOKENS. The v0.1.8 cycle paid for that with 3 hotfix rounds — RTK savings, RTK adoption, RTK equivalent, RTK artifacts, RTK and native.

Approach

Two-pass detector:

  1. Body-range scan — walks each .rs file finding top-level struct/enum spans whose declaration carries #[derive(... Parser|Subcommand|Args|ValueEnum ...)]. Brace-depth tracked.
  2. ///-line scan — for each /// line containing \brtk\b:
    • flag if inside one of the clap-derived bodies (field-doc leak)
    • flag if the doc block immediately precedes a #[derive(...clap...)] (struct top-level help leak)
    • flag if the doc block immediately precedes #[arg(...)], #[command(...)], or #[clap(...)] (field-attr leak — catches fields whose enclosing struct is across module boundaries)

Coherence with the existing allowlist

Structural categories that already justify rtk references — PATH_NEEDLES (e.g. .rtk/filters.toml), RTK_ENVISH_RE (e.g. RTK_DB_PATH), ATTRIBUTION_NEEDLES, HOOK_PROTOCOL_NEEDLES, DOC_EXAMPLE_NEEDLES — also exempt here. The broad /// blanket rule is explicitly not honored (would defeat the test).

The per-line // branding-lint: allow legacy escape hatch works.

Self-test

5 synthetic leak-simulation fixtures embedded in the test exercise the detector logic — 3 must-flag (clap-derive top-level docstring, field-attr precede, in-clap-body field) and 2 must-not-flag (doc above pub fn, doc above non-clap struct). Catches the case where someone weakens the heuristic and silently reopens the v0.1.8 regression class.

Current state

0 violations in src/ (the only candidate at src/main.rs:670 is a .rtk/filters.toml path reference and exempts via PATH_NEEDLES coherence).

Test plan

  • cargo test --test branding_lint — 5 passed
  • cargo test --workspace — 2177 passed, 6 ignored

🤖 Generated with Claude Code

…eaks before they reach --help (#75)

The allowlist-style branding lint from #67 accepts ALL `///` lines via
the broad `rustdoc-comment mention (///)` rule — too many legitimate
project-name mentions in rustdoc to enumerate. The trade-off: NEW
user-visible `RTK` phrasings in clap doc comments silently slip
through unless their exact phrasing already lives in FORBIDDEN_TOKENS.

That's how `RTK savings`, `RTK adoption`, `RTK equivalent`,
`RTK artifacts`, `RTK and native` (v0.1.7 round-3 sweep) all reached
production before being caught.

New test: `branding_lint_clap_doc_comments_fail_on_rtk`. Two-pass:
1. Pre-compute body line ranges of top-level structs/enums whose
   declaration carries a clap-derive (`Parser`/`Subcommand`/`Args`/
   `ValueEnum`). Brace-depth-tracked.
2. For each `///` line containing `\brtk\b`, flag it if any of:
   a. Inside a clap-derived body (field-doc leak)
   b. Doc block precedes a `#[derive(...clap...)]` (struct-level help leak)
   c. Doc block precedes `#[arg|command|clap(...)]` (field-attr leak)

Coherence with the existing allowlist: structural categories
(PATH_NEEDLES, RTK_ENVISH_RE, ATTRIBUTION_NEEDLES, HOOK_PROTOCOL_NEEDLES,
DOC_EXAMPLE_NEEDLES) still exempt — paths and env-var names are
intentional cross-cutting concerns even when they appear in clap docs.
The broad `///` blanket rule is explicitly NOT honored — that would
defeat the whole test.

Per-line `// branding-lint: allow legacy` escape hatch retained.

5 synthetic leak-simulation fixtures self-test the detector logic so
a future weakening reopens the v0.1.8 regression class loudly.

Current src/ violations: 0 (the only candidate at src/main.rs:670
was a `.rtk/filters.toml` path reference and exempts via PATH_NEEDLES
coherence rule).

cargo test --workspace: 2177 passed.

Closes #75.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@thehoff

thehoff commented Jun 10, 2026

Copy link
Copy Markdown
Owner Author

Closing as obsolete — the rtk/contextzip rebrand shipped (0.3.0 branding purge + 0.4.0 lib pivot). Branding-lint debt is no longer tracked.

@thehoff thehoff closed this Jun 10, 2026
@thehoff
thehoff deleted the harden/branding-lint-clap-aware-75 branch June 10, 2026 13:06
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.

harden(branding-lint): clap-aware sub-rule to catch /// doc-comment leaks before they reach --help

1 participant