Skip to content

Commit 9b7af08

Browse files
committed
refactor: tighten visibility and avoid unnecessary clones in check module
- Revert resolve_and_build_command to private (only used within cli.rs) - Narrow LintMessageKind and methods from pub(crate)/pub to pub(super) - Make combine_output take ownership of CapturedCommandOutput to avoid cloning stdout/stderr strings on every call
1 parent b9ee8a9 commit 9b7af08

File tree

3 files changed

+18
-19
lines changed

3 files changed

+18
-19
lines changed

packages/cli/binding/src/check/analysis.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ pub(super) struct LintFailure {
3636
}
3737

3838
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
39-
pub(crate) enum LintMessageKind {
39+
pub(super) enum LintMessageKind {
4040
LintOnly,
4141
LintAndTypeCheck,
4242
}
4343

4444
impl LintMessageKind {
45-
pub fn from_lint_config(lint_config: Option<&serde_json::Value>) -> Self {
45+
pub(super) fn from_lint_config(lint_config: Option<&serde_json::Value>) -> Self {
4646
let type_check_enabled = lint_config
4747
.and_then(|config| config.get("options"))
4848
.and_then(|options| options.get("typeCheck"))
@@ -52,21 +52,21 @@ impl LintMessageKind {
5252
if type_check_enabled { Self::LintAndTypeCheck } else { Self::LintOnly }
5353
}
5454

55-
pub fn success_label(self) -> &'static str {
55+
pub(super) fn success_label(self) -> &'static str {
5656
match self {
5757
Self::LintOnly => "Found no warnings or lint errors",
5858
Self::LintAndTypeCheck => "Found no warnings, lint errors, or type errors",
5959
}
6060
}
6161

62-
pub fn warning_heading(self) -> &'static str {
62+
pub(super) fn warning_heading(self) -> &'static str {
6363
match self {
6464
Self::LintOnly => "Lint warnings found",
6565
Self::LintAndTypeCheck => "Lint or type warnings found",
6666
}
6767
}
6868

69-
pub fn issue_heading(self) -> &'static str {
69+
pub(super) fn issue_heading(self) -> &'static str {
7070
match self {
7171
Self::LintOnly => "Lint issues found",
7272
Self::LintAndTypeCheck => "Lint or type issues found",

packages/cli/binding/src/check/mod.rs

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,8 @@ pub(crate) async fn execute_check(
6161
false,
6262
)
6363
.await?;
64-
status = captured.status;
65-
66-
let combined_output = combine_output(&captured);
64+
let (fmt_status, combined_output) = combine_output(captured);
65+
status = fmt_status;
6766

6867
if !fix {
6968
match analyze_fmt_check_output(&combined_output) {
@@ -141,9 +140,8 @@ pub(crate) async fn execute_check(
141140
true,
142141
)
143142
.await?;
144-
status = captured.status;
145-
146-
let combined_output = combine_output(&captured);
143+
let (lint_status, combined_output) = combine_output(captured);
144+
status = lint_status;
147145

148146
match analyze_lint_output(&combined_output) {
149147
Some(Ok(success)) => {
@@ -209,9 +207,9 @@ pub(crate) async fn execute_check(
209207
false,
210208
)
211209
.await?;
212-
status = captured.status;
210+
let (refmt_status, combined_output) = combine_output(captured);
211+
status = refmt_status;
213212
if status != ExitStatus::SUCCESS {
214-
let combined_output = combine_output(&captured);
215213
print_error_block(
216214
"Formatting could not finish after lint fixes",
217215
&combined_output,
@@ -234,12 +232,13 @@ pub(crate) async fn execute_check(
234232
}
235233

236234
/// Combine stdout and stderr from a captured command output.
237-
fn combine_output(captured: &CapturedCommandOutput) -> String {
238-
if captured.stderr.is_empty() {
239-
captured.stdout.clone()
235+
fn combine_output(captured: CapturedCommandOutput) -> (ExitStatus, String) {
236+
let combined = if captured.stderr.is_empty() {
237+
captured.stdout
240238
} else if captured.stdout.is_empty() {
241-
captured.stderr.clone()
239+
captured.stderr
242240
} else {
243241
format!("{}{}", captured.stdout, captured.stderr)
244-
}
242+
};
243+
(captured.status, combined)
245244
}

packages/cli/binding/src/cli.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -697,7 +697,7 @@ impl UserConfigLoader for VitePlusConfigLoader {
697697
}
698698

699699
/// Resolve a subcommand into a prepared `tokio::process::Command`.
700-
pub(crate) async fn resolve_and_build_command(
700+
async fn resolve_and_build_command(
701701
resolver: &SubcommandResolver,
702702
subcommand: SynthesizableSubcommand,
703703
resolved_vite_config: Option<&ResolvedUniversalViteConfig>,

0 commit comments

Comments
 (0)