From 4d0e45f6635308926616fa706c4aff1be99427ac Mon Sep 17 00:00:00 2001 From: MK Date: Tue, 24 Feb 2026 16:57:56 +0800 Subject: [PATCH 1/3] feat: add clippy disallowed-macros rules for println!/eprintln! Enforce that all user-facing output goes through `vite_shared::output` functions instead of raw print macros. Also document CLI output conventions for both Rust and TypeScript in CLAUDE.md. --- .clippy.toml | 8 +++++++- CLAUDE.md | 7 +++++++ crates/vite_shared/src/output.rs | 10 +++++----- 3 files changed, 19 insertions(+), 6 deletions(-) diff --git a/.clippy.toml b/.clippy.toml index 8d0ebb2df8..709cb73042 100644 --- a/.clippy.toml +++ b/.clippy.toml @@ -18,4 +18,10 @@ disallowed-types = [ { path = "std::string::String", reason = "Use `vite_str::Str` for small strings. For large strings, prefer `Box/Rc/Arc` if mutation is not needed." }, ] -disallowed-macros = [{ path = "std::format", reason = "Use `vite_str::format` for small strings." }] +disallowed-macros = [ + { path = "std::format", reason = "Use `vite_str::format` for small strings." }, + { path = "std::println", reason = "Use `vite_shared::output` functions (`info`, `note`, `success`) instead." }, + { path = "std::print", reason = "Use `vite_shared::output` functions (`info`, `note`, `success`) instead." }, + { path = "std::eprintln", reason = "Use `vite_shared::output` functions (`warn`, `error`) instead." }, + { path = "std::eprint", reason = "Use `vite_shared::output` functions (`warn`, `error`) instead." }, +] diff --git a/CLAUDE.md b/CLAUDE.md index 65af8583ff..281949ddc2 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -78,6 +78,13 @@ vp run dev # runs dev script from package.json - **Passing to std functions**: `AbsolutePath` implements `AsRef`, use `.as_path()` when explicit `&Path` is required +## CLI Output + +All user-facing output must go through shared output modules instead of raw print calls. + +- **Rust**: Use `vite_shared::output` functions (`info`, `warn`, `error`, `note`, `success`) — never raw `println!`/`eprintln!` (enforced by clippy `disallowed-macros`) +- **TypeScript**: Use `packages/cli/src/utils/terminal.ts` functions (`infoMsg`, `warnMsg`, `errorMsg`, `noteMsg`, `log`) — never raw `console.log`/`console.error` + ## Git Workflow - Run `vp fmt` before committing to format code diff --git a/crates/vite_shared/src/output.rs b/crates/vite_shared/src/output.rs index 0026bc57de..1485b377d3 100644 --- a/crates/vite_shared/src/output.rs +++ b/crates/vite_shared/src/output.rs @@ -16,31 +16,31 @@ pub const WARN_SIGN: &str = "\u{26A0}"; pub const ARROW: &str = "\u{2192}"; /// Print an info message to stdout. -#[allow(clippy::print_stdout)] +#[allow(clippy::print_stdout, clippy::disallowed_macros)] pub fn info(msg: &str) { println!("{} {msg}", "info:".bright_blue().bold()); } /// Print a warning message to stderr. -#[allow(clippy::print_stderr)] +#[allow(clippy::print_stderr, clippy::disallowed_macros)] pub fn warn(msg: &str) { eprintln!("{} {msg}", "warn:".yellow().bold()); } /// Print an error message to stderr. -#[allow(clippy::print_stderr)] +#[allow(clippy::print_stderr, clippy::disallowed_macros)] pub fn error(msg: &str) { eprintln!("{} {msg}", "error:".red().bold()); } /// Print a note message to stdout (supplementary info). -#[allow(clippy::print_stdout)] +#[allow(clippy::print_stdout, clippy::disallowed_macros)] pub fn note(msg: &str) { println!("{} {msg}", "note:".dimmed().bold()); } /// Print a success line with checkmark to stdout. -#[allow(clippy::print_stdout)] +#[allow(clippy::print_stdout, clippy::disallowed_macros)] pub fn success(msg: &str) { println!("{} {msg}", CHECK.green()); } From 7195176a0f97c6187dc411a03960e67b029e09c8 Mon Sep 17 00:00:00 2001 From: MK Date: Tue, 24 Feb 2026 22:22:36 +0800 Subject: [PATCH 2/3] docs: add clippy rules reference to CLAUDE.md --- CLAUDE.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CLAUDE.md b/CLAUDE.md index 281949ddc2..d7144bf870 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -78,6 +78,10 @@ vp run dev # runs dev script from package.json - **Passing to std functions**: `AbsolutePath` implements `AsRef`, use `.as_path()` when explicit `&Path` is required +## Clippy Rules + +All Rust code must follow the custom clippy rules defined in `.clippy.toml` (disallowed types, macros, and methods). + ## CLI Output All user-facing output must go through shared output modules instead of raw print calls. From d4dc654227da7271c024d05d0cca6090ac5cbb8a Mon Sep 17 00:00:00 2001 From: MK Date: Tue, 24 Feb 2026 22:23:36 +0800 Subject: [PATCH 3/3] docs: clarify clippy rules apply to new code only --- CLAUDE.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CLAUDE.md b/CLAUDE.md index d7144bf870..82c1684499 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -80,7 +80,7 @@ vp run dev # runs dev script from package.json ## Clippy Rules -All Rust code must follow the custom clippy rules defined in `.clippy.toml` (disallowed types, macros, and methods). +All **new** Rust code must follow the custom clippy rules defined in `.clippy.toml` (disallowed types, macros, and methods). Existing code may not fully comply due to historical reasons. ## CLI Output