agentleFS
padamsonpadamson/playwright-rust/.claude/skills/doctest-conventions/SKILL.md

doctest-conventions

Skill166 starsChanged 7 days agoApache-2.0View on GitHub

Conventions for authoring rustdoc doctests in playwright-rust — the `no_run` annotation, module-level placement, hidden scaffolding lines, and how doctests are exercised in CI vs pre-commit.

The file

We split this skill into the rules it gives an agent

3 rules. About 0 are common, 0 are distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈0

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Every rustdoc example is compile-checked on every cargo test --doc (pre-commit and CI).

    line 12
  2. Very specific:

    Prefer one comprehensive module-level doctest (//!) per protocol file, demonstrating related APIs in a realistic scenario.

    line 44
  3. Very specific:

    Use hidden scaffolding lines (# -prefixed) so the rendered docs show only the instructive lines while the compiler sees a complete program:

    line 49

≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Doctest Conventions

Philosophy: documentation that cannot rot

Every rustdoc example is compile-checked on every cargo test --doc (pre-commit and CI). Browser automation can't execute in a doctest harness, so examples are compiled but not run — same contract as the agent-doc snippets (verify-agent-docs) and landing-page snippets (verify-site-snippets).

The annotation: no_run

no_run  — compiled every time, never executed.  ← use this
ignore  — never compiled, never executed; rustdoc only highlights it.
(none)  — compiled AND executed; only for pure, browser-free examples.

Use ```no_run for anything that would launch a browser or talk to the Playwright server. Plain ```rust is fine for pure logic (selector builders, option construction) that can really execute.

Never use ```ignore except when the code genuinely cannot compile in this crate — the only sanctioned case is the macros/trace crates' module docs showing downstream playwright-rs usage, which would need a cyclic dev-dependency to compile.

History. Until 2026-06, the convention was ignore + a CI step running cargo test --doc -- --ignored, believed to execute them. It never did: rustdoc surfaces ignore blocks as empty always-pass stubs (83 "passed" in 0.00s). The examples had zero protection and ~10 had silently rotted. no_run is what the convention always intended.

Structure

Prefer one comprehensive module-level doctest (//!) per protocol file, demonstrating related APIs in a realistic scenario. Per-function examples are allowed where they pull their weight — they must compile like everything else.

Use hidden scaffolding lines (# -prefixed) so the rendered docs show only the instructive lines while the compiler sees a complete program:

/// # Example
///
/// ```no_run
/// # use playwright_rs::Playwright;
/// # async fn example() -> Result<(), Box<dyn std::error::Error>> {
/// # let pw = Playwright::launch().await?;
/// # let page = pw.chromium().launch().await?.new_page().await?;
/// page.goto("https://example.com", None).await?;
/// let title = page.title().await?;
/// # Ok(())
/// # }
/// ```

Module-level (//!) doctests use //! # for hidden lines. A full #[tokio::main] async fn main() is also fine when showing the whole program is the point.

Running doctests

# Compile-check all doctests (pre-commit AND CI run exactly this)
cargo test --doc --workspace

# Pure examples without no_run also execute in the same pass

CI / pre-commit integration

Both run the same command — there is no separate execution lane:

- name: Compile doc-tests
  run: cargo test --doc --workspace

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.