Skip to content

Commit 5844065

Browse files
authored
feat: add clippy disallowed-macros rules for println!/eprintln! (#621)
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.
1 parent 0fd4d06 commit 5844065

3 files changed

Lines changed: 23 additions & 6 deletions

File tree

.clippy.toml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,10 @@ disallowed-types = [
1818
{ path = "std::string::String", reason = "Use `vite_str::Str` for small strings. For large strings, prefer `Box/Rc/Arc<str>` if mutation is not needed." },
1919
]
2020

21-
disallowed-macros = [{ path = "std::format", reason = "Use `vite_str::format` for small strings." }]
21+
disallowed-macros = [
22+
{ path = "std::format", reason = "Use `vite_str::format` for small strings." },
23+
{ path = "std::println", reason = "Use `vite_shared::output` functions (`info`, `note`, `success`) instead." },
24+
{ path = "std::print", reason = "Use `vite_shared::output` functions (`info`, `note`, `success`) instead." },
25+
{ path = "std::eprintln", reason = "Use `vite_shared::output` functions (`warn`, `error`) instead." },
26+
{ path = "std::eprint", reason = "Use `vite_shared::output` functions (`warn`, `error`) instead." },
27+
]

CLAUDE.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ vp run dev # runs dev script from package.json
7878

7979
- **Passing to std functions**: `AbsolutePath` implements `AsRef<Path>`, use `.as_path()` when explicit `&Path` is required
8080

81+
## Clippy Rules
82+
83+
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.
84+
85+
## CLI Output
86+
87+
All user-facing output must go through shared output modules instead of raw print calls.
88+
89+
- **Rust**: Use `vite_shared::output` functions (`info`, `warn`, `error`, `note`, `success`) — never raw `println!`/`eprintln!` (enforced by clippy `disallowed-macros`)
90+
- **TypeScript**: Use `packages/cli/src/utils/terminal.ts` functions (`infoMsg`, `warnMsg`, `errorMsg`, `noteMsg`, `log`) — never raw `console.log`/`console.error`
91+
8192
## Git Workflow
8293

8394
- Run `vp fmt` before committing to format code

crates/vite_shared/src/output.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,31 +16,31 @@ pub const WARN_SIGN: &str = "\u{26A0}";
1616
pub const ARROW: &str = "\u{2192}";
1717

1818
/// Print an info message to stdout.
19-
#[allow(clippy::print_stdout)]
19+
#[allow(clippy::print_stdout, clippy::disallowed_macros)]
2020
pub fn info(msg: &str) {
2121
println!("{} {msg}", "info:".bright_blue().bold());
2222
}
2323

2424
/// Print a warning message to stderr.
25-
#[allow(clippy::print_stderr)]
25+
#[allow(clippy::print_stderr, clippy::disallowed_macros)]
2626
pub fn warn(msg: &str) {
2727
eprintln!("{} {msg}", "warn:".yellow().bold());
2828
}
2929

3030
/// Print an error message to stderr.
31-
#[allow(clippy::print_stderr)]
31+
#[allow(clippy::print_stderr, clippy::disallowed_macros)]
3232
pub fn error(msg: &str) {
3333
eprintln!("{} {msg}", "error:".red().bold());
3434
}
3535

3636
/// Print a note message to stdout (supplementary info).
37-
#[allow(clippy::print_stdout)]
37+
#[allow(clippy::print_stdout, clippy::disallowed_macros)]
3838
pub fn note(msg: &str) {
3939
println!("{} {msg}", "note:".dimmed().bold());
4040
}
4141

4242
/// Print a success line with checkmark to stdout.
43-
#[allow(clippy::print_stdout)]
43+
#[allow(clippy::print_stdout, clippy::disallowed_macros)]
4444
pub fn success(msg: &str) {
4545
println!("{} {msg}", CHECK.green());
4646
}

0 commit comments

Comments
 (0)