Skip to content

Commit 8edc304

Browse files
authored
style: clippy autofix (#210)
1 parent 80d2d3d commit 8edc304

10 files changed

Lines changed: 221 additions & 209 deletions

File tree

Cargo.lock

Lines changed: 186 additions & 166 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/vite_package_manager/src/package_manager.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ fn get_package_manager_type_and_version(
279279
&& let Some((name, version_with_hash)) = package_json.package_manager.split_once('@')
280280
{
281281
// Parse version and optional hash (format: version+sha512.hash)
282-
let (version, hash) = if let Some((ver, hash_part)) = version_with_hash.split_once("+")
282+
let (version, hash) = if let Some((ver, hash_part)) = version_with_hash.split_once('+')
283283
{
284284
(ver, Some(hash_part.into()))
285285
} else {

crates/vite_package_manager/src/request.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ pub async fn verify_file_hash(
236236
if actual_hex != expected_hex {
237237
return Err(Error::HashMismatch {
238238
expected: expected_hash.into(),
239-
actual: format!("{}.{}", algorithm, actual_hex).into(),
239+
actual: format!("{algorithm}.{actual_hex}").into(),
240240
});
241241
}
242242

crates/vite_task/src/config/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ impl ResolvedTask {
9898
}
9999
}
100100

101-
pub fn is_builtin(&self) -> bool {
101+
pub const fn is_builtin(&self) -> bool {
102102
self.name.package_name.is_none()
103103
}
104104

crates/vite_task/src/execute.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -320,8 +320,7 @@ pub static CURRENT_EXECUTION_ID: LazyLock<Option<String>> =
320320

321321
pub static EXECUTION_SUMMARY_DIR: LazyLock<PathBuf> = LazyLock::new(|| {
322322
std::env::var("VITE_TASK_EXECUTION_DIR")
323-
.map(PathBuf::from)
324-
.unwrap_or_else(|_| tempfile::tempdir().unwrap().keep())
323+
.map_or_else(|_| tempfile::tempdir().unwrap().keep(), PathBuf::from)
325324
});
326325

327326
pub async fn execute_task(
@@ -358,7 +357,7 @@ pub async fn execute_task(
358357
if resolved_command.fingerprint.command.has_inner_runner() {
359358
resolved_command.fingerprint.command.to_string()
360359
} else {
361-
"".to_string()
360+
String::new()
362361
},
363362
)
364363
.env("VITE_TASK_EXECUTION_ID", execution_id)

crates/vite_task/src/fs.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ impl FileSystem for RealFileSystem {
8181
// Is a directory on Unix - use the optimized nix implementation first
8282
#[cfg(unix)]
8383
{
84-
return RealFileSystem::process_directory_unix(reader.into_inner(), path_read);
84+
return Self::process_directory_unix(reader.into_inner(), path_read);
8585
}
8686
#[cfg(windows)]
8787
{

crates/vite_task/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,8 @@ pub async fn main<
342342
.await?;
343343
let resolved_vite_config: Option<ResolvedUniversalViteConfig> = vite_config
344344
.map(|vite_config| {
345-
serde_json::from_str(&vite_config).map_err(|err| {
345+
serde_json::from_str(&vite_config).inspect_err(|_| {
346346
tracing::error!("Failed to parse vite config: {vite_config}");
347-
err
348347
})
349348
})
350349
.transpose()?;
@@ -455,7 +454,7 @@ pub async fn main<
455454
}
456455
}
457456

458-
let _ = std::fs::remove_dir_all(&execution_summary_dir);
457+
let _ = std::fs::remove_dir_all(execution_summary_dir);
459458
if matches!(&args.commands, Commands::Run { .. }) {
460459
print!("{}", &summary);
461460
}

crates/vite_task/src/schedule.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct ExecutionStatus {
5656
/// `Err(_)` means the task doesn't have a exit status at all, e.g. skipped due to failed direct or indirect dependency.
5757
///
5858
/// For example, for three tasks declared as: "false && echo foo && echo bar",
59-
/// their execution_result in order would be:
59+
/// their `execution_result` in order would be:
6060
/// - `Ok(ExitStatus(1))`
6161
/// - `Err(SkippedDueToFailedDependency)`
6262
/// - `Err(SkippedDueToFailedDependency)`
@@ -162,7 +162,7 @@ impl ExecutionPlan {
162162

163163
// The inner runner is expected to display the command and the cache status. The outer runner will skip displaying them.
164164
if !has_inner_runner {
165-
print!("{}", pre_execution_status);
165+
print!("{pre_execution_status}");
166166
}
167167

168168
// Execute or replay the task

crates/vite_task/src/ui.rs

Lines changed: 24 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ pub fn get_display_command(display_options: DisplayOptions, task: &ResolvedTask)
4040
let cwd = task.resolved_command.fingerprint.cwd.as_str();
4141
Some(format!(
4242
"{}$ {}",
43-
if cwd.is_empty() { format_args!("") } else { format_args!("~/{}", cwd) },
43+
if cwd.is_empty() { format_args!("") } else { format_args!("~/{cwd}") },
4444
display_command
4545
))
4646
}
@@ -56,12 +56,12 @@ impl Display for PreExecutionStatus {
5656
// No message for "Cache not found" as requested
5757
tracing::debug!("{}", "Cache not found".style(CACHE_MISS_STYLE));
5858
if let Some(display_command) = &display_command {
59-
writeln!(f, "{}", display_command)?;
59+
writeln!(f, "{display_command}")?;
6060
}
6161
}
6262
CacheStatus::CacheMiss(CacheMiss::FingerprintMismatch(mismatch)) => {
6363
if let Some(display_command) = &display_command {
64-
write!(f, "{} ", display_command)?;
64+
write!(f, "{display_command} ")?;
6565
}
6666

6767
let current = &self.task.resolved_command.fingerprint;
@@ -71,22 +71,22 @@ impl Display for PreExecutionStatus {
7171
// For now, just say "command changed" for any command fingerprint mismatch
7272
// The detailed analysis will be in the summary
7373
if previous.command != current.command {
74-
format!("command changed")
74+
"command changed".to_string()
7575
} else if previous.cwd != current.cwd {
76-
format!("working directory changed")
76+
"working directory changed".to_string()
7777
} else if previous.envs_without_pass_through
7878
!= current.envs_without_pass_through
7979
|| previous.pass_through_envs != current.pass_through_envs
8080
{
81-
format!("envs changed")
81+
"envs changed".to_string()
8282
} else {
83-
format!("command configuration changed")
83+
"command configuration changed".to_string()
8484
}
8585
}
8686
FingerprintMismatch::PostRunFingerprintMismatch(
8787
PostRunFingerprintMismatch::InputContentChanged { path },
8888
) => {
89-
format!("content of input '{}' changed", path)
89+
format!("content of input '{path}' changed")
9090
}
9191
};
9292
writeln!(
@@ -104,7 +104,7 @@ impl Display for PreExecutionStatus {
104104
CacheStatus::CacheHit { .. } => {
105105
if !self.display_options.ignore_replay {
106106
if let Some(display_command) = &display_command {
107-
write!(f, "{} ", display_command)?;
107+
write!(f, "{display_command} ")?;
108108
}
109109
writeln!(
110110
f,
@@ -176,20 +176,20 @@ impl Display for ExecutionSummary {
176176
f,
177177
"{} {} {} {} {}",
178178
"Statistics:".style(Style::new().bold()),
179-
format!(" {} tasks", total).style(Style::new().bright_white()),
180-
format!("• {} cache hits", cache_hits).style(Style::new().green()),
181-
format!("• {} cache misses", cache_misses).style(CACHE_MISS_STYLE),
179+
format!(" {total} tasks").style(Style::new().bright_white()),
180+
format!("• {cache_hits} cache hits").style(Style::new().green()),
181+
format!("• {cache_misses} cache misses").style(CACHE_MISS_STYLE),
182182
if failed > 0 {
183-
format!("• {} failed", failed).style(Style::new().red()).to_string()
183+
format!("• {failed} failed").style(Style::new().red()).to_string()
184184
} else if skipped > 0 {
185-
format!("• {} skipped", skipped).style(Style::new().bright_black()).to_string()
185+
format!("• {skipped} skipped").style(Style::new().bright_black()).to_string()
186186
} else {
187187
String::new()
188188
}
189189
)?;
190190

191191
let cache_rate =
192-
if total > 0 { (cache_hits as f64 / total as f64 * 100.0) as u32 } else { 0 };
192+
if total > 0 { (f64::from(cache_hits) / total as f64 * 100.0) as u32 } else { 0 };
193193

194194
let total_duration = self
195195
.execution_statuses
@@ -209,7 +209,7 @@ impl Display for ExecutionSummary {
209209
f,
210210
"{} {} cache hit rate",
211211
"Performance:".style(Style::new().bold()),
212-
format_args!("{}%", cache_rate).style(if cache_rate >= 75 {
212+
format_args!("{cache_rate}%").style(if cache_rate >= 75 {
213213
Style::new().green().bold()
214214
} else if cache_rate >= 50 {
215215
CACHE_MISS_STYLE
@@ -260,7 +260,7 @@ impl Display for ExecutionSummary {
260260
f,
261261
" {} {}",
262262
"✗".style(Style::new().red().bold()),
263-
format!("(exit code: {})", exit_status).style(Style::new().red())
263+
format!("(exit code: {exit_status})").style(Style::new().red())
264264
)?;
265265
}
266266
Err(ExecutionFailure::SkippedDueToFailedDependency) => {
@@ -281,7 +281,7 @@ impl Display for ExecutionSummary {
281281
f,
282282
" {} {}",
283283
"→ Cache hit - output replayed".style(Style::new().green()),
284-
format!("- {:.2?} saved", original_duration).style(Style::new().green())
284+
format!("- {original_duration:.2?} saved").style(Style::new().green())
285285
)?;
286286
}
287287
CacheStatus::CacheMiss(miss) => {
@@ -312,7 +312,7 @@ impl Display for ExecutionSummary {
312312
if previous_command_fingerprint.cwd
313313
!= current_command_fingerprint.cwd
314314
{
315-
fn display_cwd(cwd: &RelativePath) -> &str {
315+
const fn display_cwd(cwd: &RelativePath) -> &str {
316316
if cwd.as_str().is_empty() { "." } else { cwd.as_str() }
317317
}
318318
changes.push(format!(
@@ -353,22 +353,16 @@ impl Display for ExecutionSummary {
353353
{
354354
if &previous_env_value != current_value {
355355
changes.push(format!(
356-
"env {} value changed from '{}' to '{}'",
357-
key, previous_env_value, current_value,
356+
"env {key} value changed from '{previous_env_value}' to '{current_value}'",
358357
));
359358
}
360359
} else {
361-
changes.push(format!(
362-
"env {}={} added",
363-
key, current_value,
364-
));
360+
changes
361+
.push(format!("env {key}={current_value} added",));
365362
}
366363
}
367364
for (key, previous_value) in previous_envs {
368-
changes.push(format!(
369-
"env {}={} removed",
370-
key, previous_value
371-
));
365+
changes.push(format!("env {key}={previous_value} removed"));
372366
}
373367

374368
if changes.is_empty() {
@@ -391,7 +385,7 @@ impl Display for ExecutionSummary {
391385
writeln!(
392386
f,
393387
"{}",
394-
format!("content of input '{}' changed", path)
388+
format!("content of input '{path}' changed")
395389
.style(CACHE_MISS_STYLE)
396390
)?;
397391
}

packages/cli/binding/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@ pub async fn run(options: CliOptions) -> Result<i32> {
206206
_ => {
207207
// Convert Rust errors to NAPI errors for JavaScript
208208
tracing::error!("Rust error: {:?}", e);
209-
return Err(anyhow::Error::from(e).into());
209+
Err(anyhow::Error::from(e).into())
210210
}
211211
}
212212
}

0 commit comments

Comments
 (0)