Skip to content

Commit a92ef8a

Browse files
Brooooooklynclaude
andcommitted
style: fix clippy::items_after_statements in test code
Move item declarations (struct, use statements) to the beginning of test functions to comply with clippy::items_after_statements lint. Changes: - vite_package_manager/src/request.rs: Move struct and use statements to the beginning of test functions - vite_task/src/fingerprint.rs: Move use statements to the beginning of test functions and remove duplicate imports All tests pass and clippy is clean with -D clippy::items_after_statements. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 9c27181 commit a92ef8a

2 files changed

Lines changed: 30 additions & 35 deletions

File tree

crates/vite_package_manager/src/request.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -416,6 +416,13 @@ mod tests {
416416

417417
#[tokio::test]
418418
async fn test_http_client_get_json() {
419+
#[derive(serde::Deserialize, Debug, PartialEq)]
420+
struct PackageInfo {
421+
name: String,
422+
version: String,
423+
description: String,
424+
}
425+
419426
let server = MockServer::start();
420427

421428
// Create mock JSON response
@@ -435,13 +442,6 @@ mod tests {
435442
let client = HttpClient::new();
436443
let url = format!("{}/api/package.json", server.base_url());
437444

438-
#[derive(serde::Deserialize, Debug, PartialEq)]
439-
struct PackageInfo {
440-
name: String,
441-
version: String,
442-
description: String,
443-
}
444-
445445
let result: Result<PackageInfo, _> = client.get_json(&url).await;
446446
assert!(result.is_ok());
447447

@@ -523,6 +523,8 @@ mod tests {
523523

524524
#[tokio::test]
525525
async fn test_verify_file_hash_sha1() {
526+
use sha1::Sha1;
527+
use sha2::Digest;
526528
use tokio::io::AsyncWriteExt;
527529

528530
let temp_dir = TempDir::new().unwrap();
@@ -534,8 +536,6 @@ mod tests {
534536
file.write_all(content).await.unwrap();
535537

536538
// Calculate expected SHA1
537-
use sha1::Sha1;
538-
use sha2::Digest;
539539
let mut hasher = Sha1::new();
540540
hasher.update(content);
541541
let expected_hash = format!("sha1.{:x}", hasher.finalize());
@@ -552,6 +552,7 @@ mod tests {
552552

553553
#[tokio::test]
554554
async fn test_verify_file_hash_sha224() {
555+
use sha2::{Digest, Sha224};
555556
use tokio::io::AsyncWriteExt;
556557

557558
let temp_dir = TempDir::new().unwrap();
@@ -563,7 +564,6 @@ mod tests {
563564
file.write_all(content).await.unwrap();
564565

565566
// Calculate expected SHA224
566-
use sha2::{Digest, Sha224};
567567
let mut hasher = Sha224::new();
568568
hasher.update(content);
569569
let expected_hash = format!("sha224.{:x}", hasher.finalize());
@@ -603,6 +603,11 @@ mod tests {
603603

604604
#[tokio::test]
605605
async fn test_http_client_json_with_invalid_response() {
606+
#[derive(serde::Deserialize)]
607+
struct TestData {
608+
_field: String,
609+
}
610+
606611
let server = MockServer::start();
607612

608613
// Mock response with invalid JSON
@@ -614,11 +619,6 @@ mod tests {
614619
let client = HttpClient::new();
615620
let url = format!("{}/invalid.json", server.base_url());
616621

617-
#[derive(serde::Deserialize)]
618-
struct TestData {
619-
_field: String,
620-
}
621-
622622
let result: Result<TestData, _> = client.get_json(&url).await;
623623
assert!(result.is_err(), "Expected JSON parsing to fail");
624624
}

crates/vite_task/src/fingerprint.rs

Lines changed: 15 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ mod tests {
132132

133133
#[test]
134134
fn test_command_fingerprint_stable_with_multiple_envs() {
135+
use bincode::{decode_from_slice, encode_to_vec};
136+
135137
// Test that CommandFingerprint with TaskCommand::Parsed maintains stable ordering
136138
let parsed_cmd = TaskParsedCommand {
137139
envs: [
@@ -173,7 +175,6 @@ mod tests {
173175
};
174176

175177
// Serialize both fingerprints
176-
use bincode::{decode_from_slice, encode_to_vec};
177178
let config = bincode::config::standard();
178179

179180
let bytes1 = encode_to_vec(&fingerprint1, config).unwrap();
@@ -193,6 +194,13 @@ mod tests {
193194

194195
#[test]
195196
fn test_fingerprint_stability_across_runs() {
197+
use std::{
198+
collections::hash_map::DefaultHasher,
199+
hash::{Hash, Hasher},
200+
};
201+
202+
use bincode::encode_to_vec;
203+
196204
// This test simulates what happens when the same task is fingerprinted
197205
// multiple times across different program runs
198206

@@ -222,16 +230,10 @@ mod tests {
222230
};
223231

224232
// Serialize the fingerprint
225-
use bincode::encode_to_vec;
226233
let config = bincode::config::standard();
227234
let bytes = encode_to_vec(&fingerprint, config).unwrap();
228235

229236
// Create a hash of the serialized bytes to verify stability
230-
use std::{
231-
collections::hash_map::DefaultHasher,
232-
hash::{Hash, Hasher},
233-
};
234-
235237
let mut hasher = DefaultHasher::new();
236238
bytes.hash(&mut hasher);
237239
let hash = hasher.finish();
@@ -245,6 +247,8 @@ mod tests {
245247

246248
#[test]
247249
fn test_task_config_with_sorted_envs() {
250+
use bincode::encode_to_vec;
251+
248252
// Test that TaskConfig produces stable fingerprints even with HashSet envs
249253
let mut envs = HashSet::new();
250254
envs.insert("VAR_3".into());
@@ -265,7 +269,6 @@ mod tests {
265269
let resolved = ResolvedTaskConfig { config_dir: RelativePathBuf::default(), config };
266270

267271
// Serialize multiple times
268-
use bincode::encode_to_vec;
269272
let bincode_config = bincode::config::standard();
270273

271274
let bytes1 = encode_to_vec(&resolved, bincode_config).unwrap();
@@ -675,12 +678,9 @@ mod tests {
675678

676679
#[test]
677680
fn test_command_fingerprint_with_fingerprint_ignores() {
678-
// Test that CommandFingerprint includes fingerprint_ignores
679-
use crate::{
680-
cmd::TaskParsedCommand,
681-
config::{CommandFingerprint, TaskCommand},
682-
};
681+
use bincode::encode_to_vec;
683682

683+
// Test that CommandFingerprint includes fingerprint_ignores
684684
let parsed_cmd = TaskParsedCommand {
685685
envs: [].into(),
686686
program: "pnpm".into(),
@@ -710,7 +710,6 @@ mod tests {
710710
assert_ne!(fingerprint_with_ignores, fingerprint_without_ignores);
711711

712712
// Serialize to verify they produce different cache keys
713-
use bincode::encode_to_vec;
714713
let config = bincode::config::standard();
715714

716715
let bytes_with = encode_to_vec(&fingerprint_with_ignores, config).unwrap();
@@ -724,12 +723,9 @@ mod tests {
724723

725724
#[test]
726725
fn test_command_fingerprint_ignores_order_matters() {
727-
// Test that the order of fingerprint_ignores patterns matters
728-
use crate::{
729-
cmd::TaskParsedCommand,
730-
config::{CommandFingerprint, TaskCommand},
731-
};
726+
use bincode::encode_to_vec;
732727

728+
// Test that the order of fingerprint_ignores patterns matters
733729
let parsed_cmd =
734730
TaskParsedCommand { envs: [].into(), program: "build".into(), args: vec![] };
735731

@@ -753,7 +749,6 @@ mod tests {
753749
// (because last-match-wins means different semantics)
754750
assert_ne!(fingerprint1, fingerprint2);
755751

756-
use bincode::encode_to_vec;
757752
let config = bincode::config::standard();
758753

759754
let bytes1 = encode_to_vec(&fingerprint1, config).unwrap();

0 commit comments

Comments
 (0)