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..82c1684499 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -78,6 +78,17 @@ 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 **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 + +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()); }