Skip to content

Commit 768e930

Browse files
runonthespotclaude
andcommitted
Fix all clippy warnings throughout codebase
- Use std::slice::from_ref instead of &[x.clone()] - Collapse nested if statements to use let-chain syntax - Remove redundant closures - Fix needless borrows - Remove unnecessary references - Use into_values() instead of into_iter().map(|(_, v)| v) - Fix integration test argument borrowing - Apply consistent formatting after clippy fixes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent e5a7653 commit 768e930

4 files changed

Lines changed: 70 additions & 74 deletions

File tree

ck-cli/src/main.rs

Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -576,29 +576,25 @@ async fn run_main() -> Result<()> {
576576
status.info(&format!(" Index size: {:.1} MB", index_size_mb));
577577

578578
use std::time::UNIX_EPOCH;
579-
if stats.index_created > 0 {
580-
if let Some(created) =
579+
if stats.index_created > 0
580+
&& let Some(created) =
581581
UNIX_EPOCH.checked_add(std::time::Duration::from_secs(stats.index_created))
582-
{
583-
if let Ok(datetime) = created.elapsed() {
584-
status.info(&format!(
585-
" Created: {:.1} hours ago",
586-
datetime.as_secs() as f64 / 3600.0
587-
));
588-
}
589-
}
582+
&& let Ok(datetime) = created.elapsed()
583+
{
584+
status.info(&format!(
585+
" Created: {:.1} hours ago",
586+
datetime.as_secs() as f64 / 3600.0
587+
));
590588
}
591-
if stats.index_updated > 0 {
592-
if let Some(updated) =
589+
if stats.index_updated > 0
590+
&& let Some(updated) =
593591
UNIX_EPOCH.checked_add(std::time::Duration::from_secs(stats.index_updated))
594-
{
595-
if let Ok(datetime) = updated.elapsed() {
596-
status.info(&format!(
597-
" Updated: {:.1} hours ago",
598-
datetime.as_secs() as f64 / 3600.0
599-
));
600-
}
601-
}
592+
&& let Ok(datetime) = updated.elapsed()
593+
{
594+
status.info(&format!(
595+
" Updated: {:.1} hours ago",
596+
datetime.as_secs() as f64 / 3600.0
597+
));
602598
}
603599

604600
// Show compression ratio

ck-cli/tests/integration_tests.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ fn get_ck_binary() -> PathBuf {
1313

1414
// Ensure binary exists by building it
1515
let output = Command::new("cargo")
16-
.args(&["build", "--bin", "ck"])
16+
.args(["build", "--bin", "ck"])
1717
.output()
1818
.expect("Failed to build ck binary");
1919

@@ -50,7 +50,7 @@ fn test_basic_grep_functionality() {
5050

5151
// Test basic regex search
5252
let output = Command::new(get_ck_binary())
53-
.args(&["rust", temp_dir.path().to_str().unwrap()])
53+
.args(["rust", temp_dir.path().to_str().unwrap()])
5454
.output()
5555
.expect("Failed to run ck");
5656

@@ -70,7 +70,7 @@ fn test_case_insensitive_search() {
7070
.unwrap();
7171

7272
let output = Command::new(get_ck_binary())
73-
.args(&["-i", "HELLO", temp_dir.path().to_str().unwrap()])
73+
.args(["-i", "HELLO", temp_dir.path().to_str().unwrap()])
7474
.output()
7575
.expect("Failed to run ck");
7676

@@ -92,7 +92,7 @@ fn test_recursive_search() {
9292
.unwrap();
9393

9494
let output = Command::new(get_ck_binary())
95-
.args(&["-r", "target", temp_dir.path().to_str().unwrap()])
95+
.args(["-r", "target", temp_dir.path().to_str().unwrap()])
9696
.output()
9797
.expect("Failed to run ck");
9898

@@ -108,7 +108,7 @@ fn test_json_output() {
108108
fs::write(temp_dir.path().join("test.txt"), "json test line").unwrap();
109109

110110
let output = Command::new(get_ck_binary())
111-
.args(&["--json", "json", temp_dir.path().to_str().unwrap()])
111+
.args(["--json", "json", temp_dir.path().to_str().unwrap()])
112112
.output()
113113
.expect("Failed to run ck");
114114

@@ -129,7 +129,7 @@ fn test_index_command() {
129129

130130
// Test index creation
131131
let output = Command::new(get_ck_binary())
132-
.args(&["--index", "."])
132+
.args(["--index", "."])
133133
.current_dir(temp_dir.path())
134134
.output()
135135
.expect("Failed to run ck index");
@@ -171,7 +171,7 @@ fn test_semantic_search() {
171171

172172
// First create an index
173173
let output = Command::new(get_ck_binary())
174-
.args(&["--index", "."])
174+
.args(["--index", "."])
175175
.current_dir(temp_dir.path())
176176
.output()
177177
.expect("Failed to run ck index");
@@ -180,7 +180,7 @@ fn test_semantic_search() {
180180

181181
// Test semantic search - should rank AI content higher for "neural networks"
182182
let output = Command::new(get_ck_binary())
183-
.args(&["--sem", "neural networks", "."])
183+
.args(["--sem", "neural networks", "."])
184184
.current_dir(temp_dir.path())
185185
.output()
186186
.expect("Failed to run ck semantic search");
@@ -217,7 +217,7 @@ fn test_lexical_search() {
217217

218218
// Create index
219219
let output = Command::new(get_ck_binary())
220-
.args(&["--index", "."])
220+
.args(["--index", "."])
221221
.current_dir(temp_dir.path())
222222
.output()
223223
.expect("Failed to run ck index");
@@ -226,7 +226,7 @@ fn test_lexical_search() {
226226

227227
// Test lexical search
228228
let output = Command::new(get_ck_binary())
229-
.args(&["--lex", "machine learning", "."])
229+
.args(["--lex", "machine learning", "."])
230230
.current_dir(temp_dir.path())
231231
.output()
232232
.expect("Failed to run ck lexical search");
@@ -248,7 +248,7 @@ fn test_hybrid_search() {
248248

249249
// Create index
250250
let output = Command::new(get_ck_binary())
251-
.args(&["--index", "."])
251+
.args(["--index", "."])
252252
.current_dir(temp_dir.path())
253253
.output()
254254
.expect("Failed to run ck index");
@@ -257,7 +257,7 @@ fn test_hybrid_search() {
257257

258258
// Test hybrid search
259259
let output = Command::new(get_ck_binary())
260-
.args(&["--hybrid", "Python", "."])
260+
.args(["--hybrid", "Python", "."])
261261
.current_dir(temp_dir.path())
262262
.output()
263263
.expect("Failed to run ck hybrid search");
@@ -278,7 +278,7 @@ fn test_context_lines() {
278278
.unwrap();
279279

280280
let output = Command::new(get_ck_binary())
281-
.args(&["-C", "1", "target", temp_dir.path().to_str().unwrap()])
281+
.args(["-C", "1", "target", temp_dir.path().to_str().unwrap()])
282282
.output()
283283
.expect("Failed to run ck with context");
284284

@@ -305,7 +305,7 @@ fn test_topk_limit() {
305305
}
306306

307307
let output = Command::new(get_ck_binary())
308-
.args(&["--topk", "5", "match", temp_dir.path().to_str().unwrap()])
308+
.args(["--topk", "5", "match", temp_dir.path().to_str().unwrap()])
309309
.output()
310310
.expect("Failed to run ck with topk");
311311

@@ -325,7 +325,7 @@ fn test_line_numbers() {
325325
.unwrap();
326326

327327
let output = Command::new(get_ck_binary())
328-
.args(&["-n", "matched", temp_dir.path().to_str().unwrap()])
328+
.args(["-n", "matched", temp_dir.path().to_str().unwrap()])
329329
.output()
330330
.expect("Failed to run ck with line numbers");
331331

@@ -343,7 +343,7 @@ fn test_clean_command() {
343343

344344
// Create index first
345345
let output = Command::new(get_ck_binary())
346-
.args(&["--index", "."])
346+
.args(["--index", "."])
347347
.current_dir(temp_dir.path())
348348
.output()
349349
.expect("Failed to run ck index");
@@ -360,7 +360,7 @@ fn test_clean_command() {
360360

361361
// Clean index
362362
let output = Command::new(get_ck_binary())
363-
.args(&["--clean", "."])
363+
.args(["--clean", "."])
364364
.current_dir(temp_dir.path())
365365
.output()
366366
.expect("Failed to run ck clean");
@@ -383,7 +383,7 @@ fn test_no_matches_stderr_message() {
383383

384384
// Search for pattern that won't match
385385
let output = Command::new(get_ck_binary())
386-
.args(&["nonexistent_pattern", temp_dir.path().to_str().unwrap()])
386+
.args(["nonexistent_pattern", temp_dir.path().to_str().unwrap()])
387387
.output()
388388
.expect("Failed to run ck");
389389

@@ -403,7 +403,7 @@ fn test_no_matches_stderr_message() {
403403
#[test]
404404
fn test_nonexistent_directory_error() {
405405
let output = Command::new(get_ck_binary())
406-
.args(&["--sem", "test", "/nonexistent/directory"])
406+
.args(["--sem", "test", "/nonexistent/directory"])
407407
.output()
408408
.expect("Failed to run ck");
409409

@@ -418,7 +418,7 @@ fn test_nonexistent_directory_error() {
418418
fn test_error_handling() {
419419
// Test with nonexistent directory
420420
let _output = Command::new(get_ck_binary())
421-
.args(&["test", "/nonexistent/directory"])
421+
.args(["test", "/nonexistent/directory"])
422422
.output()
423423
.expect("Failed to run ck");
424424

@@ -430,7 +430,7 @@ fn test_error_handling() {
430430
fs::write(temp_dir.path().join("test.txt"), "test content").unwrap();
431431

432432
let output = Command::new(get_ck_binary())
433-
.args(&["[invalid", temp_dir.path().to_str().unwrap()])
433+
.args(["[invalid", temp_dir.path().to_str().unwrap()])
434434
.output()
435435
.expect("Failed to run ck");
436436

ck-engine/src/lib.rs

Lines changed: 28 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ fn regex_search(options: &SearchOptions) -> Result<Vec<SearchResult>> {
101101
let regex = RegexBuilder::new(&pattern)
102102
.case_insensitive(options.case_insensitive)
103103
.build()
104-
.map_err(|e| CkError::Regex(e))?;
104+
.map_err(CkError::Regex)?;
105105

106106
// Default to recursive for directories (like grep) to maintain compatibility
107107
let should_recurse = options.path.is_dir() || options.recursive;
@@ -304,10 +304,10 @@ async fn lexical_search(options: &SearchOptions) -> Result<Vec<SearchResult>> {
304304
let normalized_score = raw_score / max_score;
305305

306306
// Apply threshold filtering with normalized score
307-
if let Some(threshold) = options.threshold {
308-
if normalized_score < threshold {
309-
continue;
310-
}
307+
if let Some(threshold) = options.threshold
308+
&& normalized_score < threshold
309+
{
310+
continue;
311311
}
312312

313313
result.score = normalized_score;
@@ -344,7 +344,7 @@ async fn build_tantivy_index(options: &SearchOptions) -> Result<Vec<SearchResult
344344
.writer(50_000_000)
345345
.map_err(|e| CkError::Index(format!("Failed to create index writer: {}", e)))?;
346346

347-
let files = collect_files(&index_root, true, &options.exclude_patterns)?;
347+
let files = collect_files(index_root, true, &options.exclude_patterns)?;
348348

349349
for file_path in &files {
350350
if let Ok(content) = fs::read_to_string(file_path) {
@@ -439,10 +439,10 @@ async fn build_tantivy_index(options: &SearchOptions) -> Result<Vec<SearchResult
439439
let normalized_score = raw_score / max_score;
440440

441441
// Apply threshold filtering with normalized score
442-
if let Some(threshold) = options.threshold {
443-
if normalized_score < threshold {
444-
continue;
445-
}
442+
if let Some(threshold) = options.threshold
443+
&& normalized_score < threshold
444+
{
445+
continue;
446446
}
447447

448448
result.score = normalized_score;
@@ -507,7 +507,7 @@ async fn semantic_search_with_progress(
507507
} else {
508508
ck_embed::create_embedder(Some("BAAI/bge-small-en-v1.5"))?
509509
};
510-
let query_embeddings = embedder.embed(&[options.query.clone()])?;
510+
let query_embeddings = embedder.embed(std::slice::from_ref(&options.query))?;
511511

512512
if query_embeddings.is_empty() {
513513
return Ok(Vec::new());
@@ -536,10 +536,10 @@ async fn semantic_search_with_progress(
536536

537537
for (doc_id, similarity) in similar_docs {
538538
// Apply threshold filtering
539-
if let Some(threshold) = options.threshold {
540-
if similarity < threshold {
541-
continue;
542-
}
539+
if let Some(threshold) = options.threshold
540+
&& similarity < threshold
541+
{
542+
continue;
543543
}
544544

545545
if let Some((file_path, content)) = file_embeddings.get(doc_id as usize) {
@@ -609,7 +609,7 @@ async fn build_semantic_index_with_progress(
609609
eprintln!("Building semantic index (no existing index found)...");
610610

611611
// Collect files and their content
612-
let files = collect_files(&index_root, true, &options.exclude_patterns)?;
612+
let files = collect_files(index_root, true, &options.exclude_patterns)?;
613613

614614
if let Some(ref callback) = progress_callback {
615615
callback(&format!("Found {} files to index", files.len()));
@@ -658,7 +658,7 @@ async fn build_semantic_index_with_progress(
658658
let chunks = ck_chunk::chunk_text(&content, detect_language(file_path).as_deref())?;
659659

660660
for chunk in chunks {
661-
let chunk_embeddings = embedder.embed(&[chunk.text.clone()])?;
661+
let chunk_embeddings = embedder.embed(std::slice::from_ref(&chunk.text))?;
662662
if !chunk_embeddings.is_empty() {
663663
embeddings.push(chunk_embeddings[0].clone());
664664
file_embeddings.push((file_path.clone(), chunk.text));
@@ -700,7 +700,7 @@ async fn build_semantic_index_with_progress(
700700

701701
// Create embedder and embed the query
702702
let mut embedder = ck_embed::create_embedder(Some("BAAI/bge-small-en-v1.5"))?;
703-
let query_embeddings = embedder.embed(&[options.query.clone()])?;
703+
let query_embeddings = embedder.embed(std::slice::from_ref(&options.query))?;
704704

705705
if query_embeddings.is_empty() {
706706
return Ok(Vec::new());
@@ -729,10 +729,10 @@ async fn build_semantic_index_with_progress(
729729

730730
for (doc_id, similarity) in similar_docs {
731731
// Apply threshold filtering
732-
if let Some(threshold) = options.threshold {
733-
if similarity < threshold {
734-
continue;
735-
}
732+
if let Some(threshold) = options.threshold
733+
&& similarity < threshold
734+
{
735+
continue;
736736
}
737737

738738
if let Some((file_path, content)) = file_embeddings.get(doc_id as usize) {
@@ -811,8 +811,8 @@ async fn hybrid_search_with_progress(
811811

812812
// Calculate RRF scores according to original paper: RRFscore(d) = Σ(r∈R) 1/(k + r(d))
813813
let mut rrf_results: Vec<SearchResult> = combined
814-
.into_iter()
815-
.map(|(_, ranks)| {
814+
.into_values()
815+
.map(|ranks| {
816816
let mut result = ranks[0].1.clone();
817817
let rrf_score = ranks
818818
.iter()
@@ -863,10 +863,10 @@ fn should_exclude_path(path: &Path, exclude_patterns: &[String]) -> bool {
863863
return true;
864864
}
865865
for component in path.components() {
866-
if let std::path::Component::Normal(name) = component {
867-
if globset.is_match(name) {
868-
return true;
869-
}
866+
if let std::path::Component::Normal(name) = component
867+
&& globset.is_match(name)
868+
{
869+
return true;
870870
}
871871
}
872872
false

ck-engine/src/semantic_v3.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ pub async fn semantic_search_v3_with_progress(
8080
}
8181

8282
let mut embedder = ck_embed::create_embedder(None)?;
83-
let query_embeddings = embedder.embed(&[options.query.clone()])?;
83+
let query_embeddings = embedder.embed(std::slice::from_ref(&options.query))?;
8484

8585
if query_embeddings.is_empty() {
8686
return Ok(Vec::new());
@@ -111,10 +111,10 @@ pub async fn semantic_search_v3_with_progress(
111111

112112
for (similarity, file_path, chunk) in similarities.into_iter().take(limit) {
113113
// Apply threshold filtering
114-
if let Some(threshold) = options.threshold {
115-
if similarity < threshold {
116-
continue;
117-
}
114+
if let Some(threshold) = options.threshold
115+
&& similarity < threshold
116+
{
117+
continue;
118118
}
119119

120120
// Check if we're filtering by a specific file or directory

0 commit comments

Comments
 (0)