From 426636043b2bcaa37ae41280de6acb0fe5d3d8e7 Mon Sep 17 00:00:00 2001 From: piquel Date: Sun, 22 Nov 2026 21:28:20 +0100 Subject: [PATCH] chore(lint): every private item in the workspace is documented --- Cargo.toml | 1 + apps/auth-service/src/cli/output/mod.rs | 4 ++-- apps/auth-service/src/security/http.rs | 5 ++++- apps/web/src/pages.rs | 25 +++++++++++++++++++++---- crates/ui/src/lib.rs | 3 --- docs/dev/rust-conventions.md | 4 +++- tools/xtask/src/main.rs | 10 ++++++++++ tools/xtask/src/publish.rs | 1 + tools/xtask/src/release.rs | 7 +++++++ 9 files changed, 49 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 16baab021..868e4485f 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -40,6 +40,7 @@ unwrap_used = "warn" expect_used = "warn" panic = "warn" todo = "warn" +missing_docs_in_private_items = "warn" unimplemented = "warn" dbg_macro = "warn" # Every exception names its lint with `#[expect]` and says why. diff --git a/apps/auth-service/src/cli/output/mod.rs b/apps/auth-service/src/cli/output/mod.rs index 65ce04278..666d3dd41 100644 --- a/apps/auth-service/src/cli/output/mod.rs +++ b/apps/auth-service/src/cli/output/mod.rs @@ -37,8 +37,8 @@ pub(super) trait Report { fn human(&self, out: &mut HumanWriter<'_>) -> io::Result<()>; } -// Implements `Report` for a type, with its JSON the value itself and the block -// as `human`: `report!(Type, self, out, { ... })`. +/// Implements `Report` for a type, with its JSON the value itself and the block +/// as `human`: `report!(Type, self, out, { ... })`. macro_rules! report { ($ty:ty, $this:ident, $out:ident, $body:block) => { impl $crate::cli::output::Report for $ty { diff --git a/apps/auth-service/src/security/http.rs b/apps/auth-service/src/security/http.rs index d38677715..e2193d26a 100644 --- a/apps/auth-service/src/security/http.rs +++ b/apps/auth-service/src/security/http.rs @@ -77,7 +77,10 @@ pub(crate) enum CacheClass { Immutable, /// Public, credential-free data, the same for every caller and readable from any /// origin. Its route must accept any `Origin` and never read the session. - Public { max_age: StdDuration }, + Public { + /// How long a cache may keep it. + max_age: StdDuration, + }, } impl CacheClass { diff --git a/apps/web/src/pages.rs b/apps/web/src/pages.rs index 4c6aa4942..7d806502a 100644 --- a/apps/web/src/pages.rs +++ b/apps/web/src/pages.rs @@ -59,7 +59,12 @@ const DOCUMENTATION: &str = "https://docs.sourceorigin.dev"; /// The body of `page`; the homepage links auth's pages at `links`. #[component] -pub(crate) async fn page_body(page: Page, links: HomeLinks<'_>) -> Result { +pub(crate) async fn page_body( + /// The page. + page: Page, + /// Where the homepage links. + links: HomeLinks<'_>, +) -> Result { Ok(view! { match page { Page::Home => home(links: links), @@ -72,7 +77,10 @@ pub(crate) async fn page_body(page: Page, links: HomeLinks<'_>) -> Result Result { +async fn policy( + /// The policy, as trusted HTML. + text: &'static str, +) -> Result { Ok(view! {
(ViewHandle::unescaped_unchecked(text)) @@ -82,7 +90,10 @@ async fn policy(text: &'static str) -> Result { /// The homepage: what Origin Auth, SourceOrigin's sign-in, is, and each part of it. #[component] -async fn home(links: HomeLinks<'_>) -> Result { +async fn home( + /// Where the homepage links. + links: HomeLinks<'_>, +) -> Result { Ok(view! {

"SourceOrigin"

@@ -107,11 +118,17 @@ async fn home(links: HomeLinks<'_>) -> Result { /// its link, labelled `label`, to `href`. A `wide` card spans the grid. #[component] async fn feature<'a>( + /// What the part is called. title: &'a str, + /// What it does. text: &'a str, + /// What its link says. label: &'a str, + /// Where its link leads. href: &'a str, - #[default] wide: bool, + /// Whether the card spans the grid. + #[default] + wide: bool, ) -> Result { Ok(view! {
diff --git a/crates/ui/src/lib.rs b/crates/ui/src/lib.rs index 7a70cd125..3d1e86326 100644 --- a/crates/ui/src/lib.rs +++ b/crates/ui/src/lib.rs @@ -34,9 +34,6 @@ //! # } //! ``` -// Every private item, a component's parameters included, says what it takes and does. -#![warn(clippy::missing_docs_in_private_items)] - /// The admin dashboard, and auth's page handing administrators off to it. mod admin; /// Files pages link, embedded in the executable: the stylesheet and the diff --git a/docs/dev/rust-conventions.md b/docs/dev/rust-conventions.md index 0bd456d47..be9de8400 100644 --- a/docs/dev/rust-conventions.md +++ b/docs/dev/rust-conventions.md @@ -376,7 +376,9 @@ ever to need it, every block would carry a `// SAFETY:` comment ## Documentation and tests -Give every item a concise, useful doc comment, private items included. Explain +Give every item a concise, useful doc comment, private items included, a +component's parameters too: it says what goes in and what comes out or happens +(`missing_docs_in_private_items` enforces it). Explain security reasoning, protocol quirks, ordering and locking where they are not obvious. Keep documentation current. Tests should cover meaningful logic and boundaries; avoid repeated smoke tests. Run checks relevant to changed code while iterating, diff --git a/tools/xtask/src/main.rs b/tools/xtask/src/main.rs index 29e18dcbc..b580e9150 100644 --- a/tools/xtask/src/main.rs +++ b/tools/xtask/src/main.rs @@ -16,13 +16,16 @@ use std::{ /// The TypeScript SDK's directory, relative to the workspace root. const NPM_PACKAGE: &str = "packages/auth"; +/// The command line. #[derive(Parser)] #[command(about = "Development tasks for the SourceOrigin workspace")] struct Cli { + /// The task to run. #[command(subcommand)] task: Task, } +/// The development tasks. #[derive(Subcommand)] enum Task { /// Publish the SDKs: the Rust crates to crates.io, in dependency order, then @@ -73,8 +76,11 @@ struct Workspace { /// The fields of a crate's `cargo metadata` this reads. #[derive(Deserialize)] struct Package { + /// The crate's name. name: String, + /// Its version. version: String, + /// Its license, if it declares one. license: Option, /// The registries it may be published to: empty for `publish = false`. publish: Option>, @@ -83,17 +89,21 @@ struct Package { /// The TypeScript SDK's `package.json`, as far as this reads it. #[derive(Deserialize)] struct NpmPackage { + /// The package's name. name: String, + /// Its version. version: String, } /// The fields of `cargo metadata` this reads. #[derive(Deserialize)] struct Metadata { + /// The workspace's crates. packages: Vec, } impl Workspace { + /// The workspace the command runs in, from `git` and `cargo metadata`. fn current() -> Result { let root = PathBuf::from( Command::new("git") diff --git a/tools/xtask/src/publish.rs b/tools/xtask/src/publish.rs index 4fd081f25..5109c19f9 100644 --- a/tools/xtask/src/publish.rs +++ b/tools/xtask/src/publish.rs @@ -12,6 +12,7 @@ const LICENSE: &str = "Apache-2.0"; /// A publish of the SDKs at their current versions. pub struct Publish<'a> { + /// The workspace whose SDKs are published. pub workspace: &'a Workspace, /// Packages and builds everything without uploading, even versions already /// published, so it checks the packages whatever the registries hold. diff --git a/tools/xtask/src/release.rs b/tools/xtask/src/release.rs index f84ad1458..6281f5d50 100644 --- a/tools/xtask/src/release.rs +++ b/tools/xtask/src/release.rs @@ -7,6 +7,7 @@ use std::{fmt::Write as _, fs}; /// A release of the workspace version, from `HEAD`. pub struct Release<'a> { + /// The workspace released. workspace: &'a Workspace, /// The workspace version, such as `0.2.0`. version: String, @@ -16,6 +17,10 @@ pub struct Release<'a> { } impl<'a> Release<'a> { + /// A release of `workspace`'s current version, which only prints what it would do when `dry_run`. + /// + /// # Errors + /// Fails if the published crates do not share one version. pub fn new(workspace: &'a Workspace, dry_run: bool) -> Result { Ok(Self { workspace, @@ -242,8 +247,10 @@ enum Section { } impl Section { + /// Every section, in the order the notes list them. const ALL: [Self; 4] = [Self::Breaking, Self::Features, Self::Fixes, Self::Other]; + /// The section's heading in the release notes. fn title(self) -> &'static str { match self { Self::Breaking => "Breaking changes",