Files
mio-code/clippy.toml
2026-11-17 18:10:13 +08:00

56 lines
4.4 KiB
TOML

# Clippy config for crates/codegen/**.
#
# NOTE: clippy uses the NEAREST clippy.toml (no merging), so this file must
# duplicate any settings from the repo-root //clippy.toml.
# TODO: remove after https://github.com/hyperium/tonic/issues/2253 fixed.
large-error-threshold = 256
# Tests may index and slice freely; an out-of-range index there is just a failing test.
# Production crates opt in with #![deny(clippy::indexing_slicing)] at the crate root.
# Like the bans below, this applies to `cargo clippy` only; the Bazel lint aspect
# reads the repo-root config, so inline #[cfg(test)] modules must not index in CI.
allow-indexing-slicing-in-tests = true
# Ban raw canonicalize: on Windows it returns verbatim `\\?\C:\...` paths that
# break external tools, leak into prompts, and poison path-equality keys.
# `dunce::canonicalize` keeps the verbatim form for paths it cannot simplify
# (over 260 chars, device names), so containment checks there fail closed.
#
# Ban raw child-process spawning: an unenrolled child outlives the session that
# started it, while an enrolled one dies with its scope. Allow with a reason
# where a child is waited on or deliberately detached.
#
# Ban std::env::home_dir: hand-rolled mio-home resolution drifted across
# crates ($HOME-only reads broke Windows GUI-spawned processes, which have
# USERPROFILE but no HOME). hoshizukimio-dirs carries the one sanctioned call.
# Deliberately scoped to crates/codegen: the tree that ships to Windows
# clients owns this policy, and repo-wide enforcement only produced
# false positives in server-side code.
#
# Ban dirs::home_dir for the same reason: on Windows it asks the known-folder
# API and ignores a redirected USERPROFILE, so it can disagree with
# hoshizukimio_dirs::home_dir — and with Node-based tools, whose os.homedir()
# reads USERPROFILE. Every home-anchored path resolves
# via hoshizukimio_dirs so all sites land in the same tree.
#
# The canonicalize and spawn bans below are enforced by `cargo clippy` and
# `just lint-rs` only: the Bazel lint aspect pins the repo-root config, which
# does not carry them.
disallowed-methods = [
{ path = "reqwest::Client::new", reason = "bypasses the mio TLS policy (backend pin, OS roots, MIO_EXTRA_CA_BUNDLE); build through hoshizukimio_mio_extra_ca; localhost-only clients allow with a reason" },
{ path = "reqwest::blocking::Client::new", reason = "bypasses the mio TLS policy (backend pin, OS roots, MIO_EXTRA_CA_BUNDLE); build through hoshizukimio_mio_extra_ca; localhost-only clients allow with a reason" },
{ path = "reqwest::ClientBuilder::build", reason = "use hoshizukimio_mio_extra_ca::build_reqwest_client: it applies the mio TLS policy and survives a broken OS store; localhost/test clients allow with a reason" },
{ path = "reqwest::blocking::ClientBuilder::build", reason = "use hoshizukimio_mio_extra_ca::build_blocking_reqwest_client: it applies the mio TLS policy and survives a broken OS store; localhost/test clients allow with a reason" },
{ path = "std::fs::canonicalize", reason = "returns \\\\?\\ verbatim paths on Windows; use dunce::canonicalize" },
{ path = "std::path::Path::canonicalize", reason = "returns \\\\?\\ verbatim paths on Windows; use dunce::canonicalize" },
{ path = "tokio::fs::canonicalize", reason = "returns \\\\?\\ verbatim paths on Windows; use hoshizukimio_mio_tools::util::fs helpers or spawn_blocking + dunce::canonicalize" },
{ path = "std::env::home_dir", reason = "mio-home resolution goes through hoshizukimio-dirs (uncached) or hoshizukimio_mio_config::mio_home (cached); generic home via hoshizukimio_dirs::home_dir" },
# allow-invalid: most codegen crates no longer depend on `dirs` at all,
# which would otherwise warn that the banned path is unreachable.
{ path = "dirs::home_dir", reason = "home-anchored paths resolve via hoshizukimio_dirs::home_dir so all sites agree; Node-based tools use os.homedir, which matches it, not the known-folder API", allow-invalid = true },
{ path = "std::process::Command::spawn", reason = "an unenrolled child outlives its session; use hoshizukimio_tty_utils::ProcessScope::enroll" },
{ path = "tokio::process::Command::spawn", reason = "an unenrolled child outlives its session; use hoshizukimio_tty_utils::ProcessScope::enroll", allow-invalid = true },
{ path = "portable_pty::SlavePty::spawn_command", reason = "an unenrolled pty child outlives its session; enroll the shell with hoshizukimio_tty_utils::ProcessScope::enroll_terminal_pid", allow-invalid = true },
]