Skip to content

Commit 0cb68a1

Browse files
branchseerclaude
andcommitted
fix: resolve clippy warnings for CI
- Add const fn and #[must_use] to ResolvedInputConfig methods - Add #[expect(too_many_arguments)] to plan_spawn_execution - Fix disallowed types/methods in glob_inputs.rs with #[expect] - Remove unfulfilled large_enum_variant expectation on FingerprintMismatch - Use HashMap::default() instead of Default::default() - Fix doc comment backtick formatting in spawn.rs - Rewrite if-let-else to map_or in execute_spawn - Replace [x].into_iter() with std::iter::once(x) in tests Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 59faab5 commit 0cb68a1

6 files changed

Lines changed: 48 additions & 51 deletions

File tree

crates/vite_task/src/session/cache/mod.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,21 @@ pub struct PreRunFingerprint {
3333
pub glob_base: RelativePathBuf,
3434
/// Hashes of explicit input files computed from positive globs.
3535
/// Files matching negative globs are already filtered out.
36-
/// Path is relative to workspace root, value is xxHash3_64 of file content.
36+
/// Path is relative to workspace root, value is `xxHash3_64` of file content.
3737
pub globbed_inputs: BTreeMap<RelativePathBuf, u64>,
3838
}
3939

4040
impl PreRunFingerprint {
4141
/// Build a pre-run fingerprint from cache metadata and globbed inputs.
4242
///
4343
/// # Arguments
44-
/// * `cache_metadata` - Cache metadata from plan stage (contains absolute glob_base)
44+
/// * `cache_metadata` - Cache metadata from plan stage (contains absolute `glob_base`)
4545
/// * `globbed_inputs` - Hashes of explicit input files computed from positive globs
46-
/// * `workspace_root` - Workspace root for converting absolute glob_base to relative
46+
/// * `workspace_root` - Workspace root for converting absolute `glob_base` to relative
47+
#[expect(
48+
clippy::disallowed_macros,
49+
reason = "anyhow::anyhow! internally uses std::format! for error messages"
50+
)]
4751
fn from_cache_metadata(
4852
cache_metadata: &CacheMetadata,
4953
globbed_inputs: BTreeMap<RelativePathBuf, u64>,
@@ -98,10 +102,6 @@ pub enum CacheMiss {
98102
}
99103

100104
#[derive(Debug, Serialize, Deserialize)]
101-
#[expect(
102-
clippy::large_enum_variant,
103-
reason = "SpawnFingerprintMismatch holds two SpawnFingerprints for comparison; boxing would add unnecessary indirection for a short-lived enum"
104-
)]
105105
pub enum FingerprintMismatch {
106106
/// Found the cache entry of the same task run, but the spawn fingerprint mismatches
107107
/// this happens when the command itself or an env changes.
@@ -205,17 +205,14 @@ impl ExecutionCache {
205205
// Try to directly find the cache by pre-run fingerprint first
206206
if let Some(cache_value) = self.get_by_pre_run_fingerprint(&pre_run_fingerprint).await? {
207207
// Validate post-run fingerprint (inferred inputs) only if auto inference is enabled
208-
if input_config.includes_auto {
209-
if let Some(post_run_fingerprint_mismatch) =
208+
if input_config.includes_auto
209+
&& let Some(post_run_fingerprint_mismatch) =
210210
cache_value.post_run_fingerprint.validate(workspace_root)?
211-
{
212-
// Found the cache with the same pre-run fingerprint, but the post-run fingerprint mismatches
213-
return Ok(Err(CacheMiss::FingerprintMismatch(
214-
FingerprintMismatch::PostRunFingerprintMismatch(
215-
post_run_fingerprint_mismatch,
216-
),
217-
)));
218-
}
211+
{
212+
// Found the cache with the same pre-run fingerprint, but the post-run fingerprint mismatches
213+
return Ok(Err(CacheMiss::FingerprintMismatch(
214+
FingerprintMismatch::PostRunFingerprintMismatch(post_run_fingerprint_mismatch),
215+
)));
219216
}
220217
// Associate the execution key to the spawn fingerprint if not already,
221218
// so that next time we can find it and report spawn fingerprint mismatch

crates/vite_task/src/session/execute/glob_inputs.rs

Lines changed: 23 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ use wax::{Glob, walk::Entry as _};
2626
/// * `negative_globs` - Glob patterns that should exclude files from the result
2727
///
2828
/// # Returns
29-
/// A sorted map of relative paths (from workspace_root) to their content hashes.
29+
/// A sorted map of relative paths (from `workspace_root`) to their content hashes.
3030
/// Only files are included (directories are skipped).
3131
///
3232
/// # Example
@@ -40,6 +40,10 @@ use wax::{Glob, walk::Entry as _};
4040
/// )?;
4141
/// // Returns: { "packages/foo/src/index.ts" => 0x1234..., ... }
4242
/// ```
43+
#[expect(
44+
clippy::disallowed_methods,
45+
reason = "str::replace needed for path normalization; cow_replace unavailable in this crate"
46+
)]
4347
pub fn compute_globbed_inputs(
4448
base_dir: &AbsolutePath,
4549
workspace_root: &AbsolutePath,
@@ -65,9 +69,8 @@ pub fn compute_globbed_inputs(
6569
for pattern in positive_globs {
6670
let glob = Glob::new(pattern.as_str())?;
6771
for entry in glob.walk(base_dir.as_path()) {
68-
let entry = match entry {
69-
Ok(e) => e,
70-
Err(_) => continue,
72+
let Ok(entry) = entry else {
73+
continue;
7174
};
7275

7376
// Skip non-files
@@ -78,11 +81,9 @@ pub fn compute_globbed_inputs(
7881
let absolute_path = entry.path();
7982

8083
// Compute path relative to base_dir for negative pattern matching
81-
let relative_to_base: &std::path::Path =
82-
match absolute_path.strip_prefix(base_dir.as_path()) {
83-
Ok(rel) => rel,
84-
Err(_) => continue, // Skip if path is outside base_dir
85-
};
84+
let Ok(relative_to_base) = absolute_path.strip_prefix(base_dir.as_path()) else {
85+
continue; // Skip if path is outside base_dir
86+
};
8687

8788
// Apply negative patterns (relative to base_dir)
8889
if let Some(ref matcher) = negative_matcher {
@@ -98,7 +99,7 @@ pub fn compute_globbed_inputs(
9899
let Some(relative_to_workspace) = absolute_path
99100
.strip_prefix(workspace_root.as_path())
100101
.ok()
101-
.and_then(|p: &std::path::Path| RelativePathBuf::new(p.to_path_buf()).ok())
102+
.and_then(|p| RelativePathBuf::new(p).ok())
102103
else {
103104
continue; // Skip if path is outside workspace_root
104105
};
@@ -110,7 +111,6 @@ pub fn compute_globbed_inputs(
110111
}
111112
Err(err) if err.kind() == io::ErrorKind::NotFound => {
112113
// File was deleted between walk and hash, skip it
113-
continue;
114114
}
115115
Err(err) => {
116116
return Err(err.into());
@@ -122,7 +122,8 @@ pub fn compute_globbed_inputs(
122122
Ok(result)
123123
}
124124

125-
/// Hash file content using xxHash3_64
125+
/// Hash file content using `xxHash3_64`.
126+
#[expect(clippy::disallowed_types, reason = "receives std::path::Path from wax glob walker")]
126127
fn hash_file_content(path: &std::path::Path) -> io::Result<u64> {
127128
let file = File::open(path)?;
128129
let mut reader = io::BufReader::new(file);
@@ -187,7 +188,7 @@ mod tests {
187188
fn test_single_positive_glob() {
188189
let (_temp, workspace, package) = create_test_workspace();
189190
let positive: std::collections::BTreeSet<Str> =
190-
["src/**/*.ts".into()].into_iter().collect();
191+
std::iter::once("src/**/*.ts".into()).collect();
191192
let negative = std::collections::BTreeSet::new();
192193

193194
let result = compute_globbed_inputs(&package, &workspace, &positive, &negative).unwrap();
@@ -217,9 +218,9 @@ mod tests {
217218
fn test_positive_with_negative_exclusion() {
218219
let (_temp, workspace, package) = create_test_workspace();
219220
let positive: std::collections::BTreeSet<Str> =
220-
["src/**/*.ts".into()].into_iter().collect();
221+
std::iter::once("src/**/*.ts".into()).collect();
221222
let negative: std::collections::BTreeSet<Str> =
222-
["**/*.test.ts".into()].into_iter().collect();
223+
std::iter::once("**/*.test.ts".into()).collect();
223224

224225
let result = compute_globbed_inputs(&package, &workspace, &positive, &negative).unwrap();
225226

@@ -251,7 +252,7 @@ mod tests {
251252
let positive: std::collections::BTreeSet<Str> =
252253
["src/**/*.ts".into(), "package.json".into()].into_iter().collect();
253254
let negative: std::collections::BTreeSet<Str> =
254-
["**/*.test.ts".into()].into_iter().collect();
255+
std::iter::once("**/*.test.ts".into()).collect();
255256

256257
let result = compute_globbed_inputs(&package, &workspace, &positive, &negative).unwrap();
257258

@@ -302,7 +303,7 @@ mod tests {
302303
let (_temp, workspace, package) = create_test_workspace();
303304
let positive: std::collections::BTreeSet<Str> = std::collections::BTreeSet::new();
304305
let negative: std::collections::BTreeSet<Str> =
305-
["**/*.test.ts".into()].into_iter().collect();
306+
std::iter::once("**/*.test.ts".into()).collect();
306307

307308
let result = compute_globbed_inputs(&package, &workspace, &positive, &negative).unwrap();
308309

@@ -314,7 +315,7 @@ mod tests {
314315
fn test_file_hashes_are_consistent() {
315316
let (_temp, workspace, package) = create_test_workspace();
316317
let positive: std::collections::BTreeSet<Str> =
317-
["src/index.ts".into()].into_iter().collect();
318+
std::iter::once("src/index.ts".into()).collect();
318319
let negative = std::collections::BTreeSet::new();
319320

320321
// Run twice and compare hashes
@@ -328,7 +329,7 @@ mod tests {
328329
fn test_file_hashes_change_with_content() {
329330
let (temp, workspace, package) = create_test_workspace();
330331
let positive: std::collections::BTreeSet<Str> =
331-
["src/index.ts".into()].into_iter().collect();
332+
std::iter::once("src/index.ts".into()).collect();
332333
let negative = std::collections::BTreeSet::new();
333334

334335
// Get initial hash
@@ -352,7 +353,7 @@ mod tests {
352353
fn test_skips_directories() {
353354
let (_temp, workspace, package) = create_test_workspace();
354355
// This glob could match the `src/lib` directory if not filtered
355-
let positive: std::collections::BTreeSet<Str> = ["src/*".into()].into_iter().collect();
356+
let positive: std::collections::BTreeSet<Str> = std::iter::once("src/*".into()).collect();
356357
let negative = std::collections::BTreeSet::new();
357358

358359
let result = compute_globbed_inputs(&package, &workspace, &positive, &negative).unwrap();
@@ -368,7 +369,7 @@ mod tests {
368369
fn test_no_matching_files_returns_empty() {
369370
let (_temp, workspace, package) = create_test_workspace();
370371
let positive: std::collections::BTreeSet<Str> =
371-
["nonexistent/**/*.xyz".into()].into_iter().collect();
372+
std::iter::once("nonexistent/**/*.xyz".into()).collect();
372373
let negative = std::collections::BTreeSet::new();
373374

374375
let result = compute_globbed_inputs(&package, &workspace, &positive, &negative).unwrap();
@@ -382,7 +383,7 @@ mod tests {
382383
let positive: std::collections::BTreeSet<Str> =
383384
["src/**/*.ts".into(), "src/index.ts".into()].into_iter().collect();
384385
let negative: std::collections::BTreeSet<Str> =
385-
["**/*.test.ts".into()].into_iter().collect();
386+
std::iter::once("**/*.test.ts".into()).collect();
386387

387388
let result = compute_globbed_inputs(&package, &workspace, &positive, &negative).unwrap();
388389

crates/vite_task/src/session/execute/mod.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use super::{
2828
StdioSuggestion,
2929
},
3030
};
31-
use crate::Session;
31+
use crate::{Session, collections::HashMap};
3232

3333
/// Outcome of a spawned execution.
3434
///
@@ -311,16 +311,14 @@ pub async fn execute_spawn(
311311
// - std_outputs: always captured when caching is enabled (for cache replay)
312312
// - path_accesses: only tracked when includes_auto is true (fspy inference)
313313
let (mut std_outputs, mut path_accesses, cache_metadata_and_inputs) =
314-
if let Some(cache_metadata) = cache_metadata {
314+
cache_metadata.map_or((None, None, None), |cache_metadata| {
315315
let path_accesses = if cache_metadata.input_config.includes_auto {
316316
Some(TrackedPathAccesses::default())
317317
} else {
318318
None // Skip fspy when inference is disabled
319319
};
320320
(Some(Vec::new()), path_accesses, Some((cache_metadata, globbed_inputs)))
321-
} else {
322-
(None, None, None)
323-
};
321+
});
324322

325323
#[expect(
326324
clippy::large_futures,
@@ -356,9 +354,8 @@ pub async fn execute_spawn(
356354
{
357355
if result.exit_status.success() {
358356
// path_reads is empty when inference is disabled (path_accesses is None)
359-
let empty_path_reads = Default::default();
360-
let path_reads =
361-
path_accesses.as_ref().map(|pa| &pa.path_reads).unwrap_or(&empty_path_reads);
357+
let empty_path_reads = HashMap::default();
358+
let path_reads = path_accesses.as_ref().map_or(&empty_path_reads, |pa| &pa.path_reads);
362359

363360
// Execution succeeded — attempt to create fingerprint and update cache
364361
match PostRunFingerprint::create(

crates/vite_task/src/session/execute/spawn.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ pub struct SpawnResult {
4444
}
4545

4646
/// Tracked file accesses from fspy.
47-
/// Only populated when fspy tracking is enabled (includes_auto is true).
47+
/// Only populated when fspy tracking is enabled (`includes_auto` is true).
4848
#[derive(Default, Debug)]
4949
pub struct TrackedPathAccesses {
5050
/// Tracked path reads
@@ -77,7 +77,7 @@ pub async fn spawn_with_tracking(
7777
path_accesses: Option<&mut TrackedPathAccesses>,
7878
) -> anyhow::Result<SpawnResult> {
7979
/// The tracking state of the spawned process.
80-
/// Determined by whether path_accesses is Some (fspy enabled) or None (fspy disabled).
80+
/// Determined by whether `path_accesses` is `Some` (fspy enabled) or `None` (fspy disabled).
8181
enum TrackingState {
8282
/// fspy tracking is enabled
8383
FspyEnabled(fspy::TrackedChild),

crates/vite_task_graph/src/config/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ pub struct ResolvedInputConfig {
110110
impl ResolvedInputConfig {
111111
/// Default configuration: auto-inference enabled, no explicit patterns
112112
#[must_use]
113-
pub fn default_auto() -> Self {
113+
pub const fn default_auto() -> Self {
114114
Self {
115115
includes_auto: true,
116116
positive_globs: BTreeSet::new(),
@@ -123,6 +123,7 @@ impl ResolvedInputConfig {
123123
/// - `None`: defaults to auto-inference (`[{auto: true}]`)
124124
/// - `Some([])`: no inputs, inference disabled
125125
/// - `Some([...])`: explicit patterns
126+
#[must_use]
126127
pub fn from_user_config(user_inputs: Option<&UserInputsConfig>) -> Self {
127128
let Some(entries) = user_inputs else {
128129
// None means default to auto-inference
@@ -155,7 +156,7 @@ impl ResolvedInputConfig {
155156
/// Inference is disabled when `includes_auto` is false.
156157
#[inline]
157158
#[must_use]
158-
pub fn inference_disabled(&self) -> bool {
159+
pub const fn inference_disabled(&self) -> bool {
159160
!self.includes_auto
160161
}
161162
}

crates/vite_task_plan/src/plan.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,7 @@ fn strip_prefix_for_cache(
482482
clippy::needless_pass_by_value,
483483
reason = "program_path ownership is needed for Arc construction"
484484
)]
485+
#[expect(clippy::too_many_arguments, reason = "internal function with closely-related parameters")]
485486
fn plan_spawn_execution(
486487
workspace_path: &Arc<AbsolutePath>,
487488
execution_cache_key: Option<ExecutionCacheKey>,

0 commit comments

Comments
 (0)