Skip to content

Commit 4615b3f

Browse files
committed
Fix clippy warnings
1 parent 7ab95a5 commit 4615b3f

File tree

10 files changed

+81
-113
lines changed

10 files changed

+81
-113
lines changed

src/adapters/llm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub fn create_adapter(config: &ModelConfig) -> Result<Box<dyn LLMAdapter>> {
7878
if config
7979
.base_url
8080
.as_ref()
81-
.map_or(false, |u| u.contains("11434")) =>
81+
.is_some_and(|u| u.contains("11434")) =>
8282
{
8383
Ok(Box::new(crate::adapters::OllamaAdapter::new(
8484
config.clone(),

src/config.rs

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use serde::{Deserialize, Serialize};
33
use std::collections::HashMap;
4-
use std::path::PathBuf;
4+
use std::path::{Path, PathBuf};
55

66
#[derive(Debug, Clone, Serialize, Deserialize)]
77
pub struct Config {
@@ -76,7 +76,7 @@ pub struct Config {
7676
pub paths: HashMap<String, PathConfig>,
7777
}
7878

79-
#[derive(Debug, Clone, Serialize, Deserialize)]
79+
#[derive(Debug, Clone, Serialize, Deserialize, Default)]
8080
pub struct PathConfig {
8181
#[serde(default)]
8282
pub focus: Vec<String>,
@@ -107,19 +107,6 @@ pub struct PluginConfig {
107107
pub duplicate_filter: bool,
108108
}
109109

110-
impl Default for PathConfig {
111-
fn default() -> Self {
112-
Self {
113-
focus: Vec::new(),
114-
ignore_patterns: Vec::new(),
115-
extra_context: Vec::new(),
116-
system_prompt: None,
117-
review_instructions: None,
118-
severity_overrides: HashMap::new(),
119-
}
120-
}
121-
}
122-
123110
impl Default for Config {
124111
fn default() -> Self {
125112
Self {
@@ -257,7 +244,7 @@ impl Config {
257244
}
258245
}
259246

260-
pub fn get_path_config(&self, file_path: &PathBuf) -> Option<&PathConfig> {
247+
pub fn get_path_config(&self, file_path: &Path) -> Option<&PathConfig> {
261248
let file_path_str = file_path.to_string_lossy();
262249

263250
// Find the most specific matching path
@@ -275,7 +262,7 @@ impl Config {
275262
best_match.map(|(_, config)| config)
276263
}
277264

278-
pub fn should_exclude(&self, file_path: &PathBuf) -> bool {
265+
pub fn should_exclude(&self, file_path: &Path) -> bool {
279266
let file_path_str = file_path.to_string_lossy();
280267

281268
// Check global exclude patterns

src/core/changelog.rs

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,6 @@ impl ChangelogGenerator {
173173
ChangeType::Fix
174174
} else if first_line.to_lowercase().contains("add") {
175175
ChangeType::Feature
176-
} else if first_line.to_lowercase().contains("update") {
177-
ChangeType::Chore
178176
} else {
179177
ChangeType::Chore
180178
};
@@ -231,7 +229,7 @@ impl ChangelogGenerator {
231229
for entry in &breaking_changes {
232230
output.push_str(&format!("* {}\n", entry.message));
233231
}
234-
output.push_str("\n");
232+
output.push('\n');
235233
}
236234

237235
// Then by category
@@ -270,7 +268,7 @@ impl ChangelogGenerator {
270268
));
271269
}
272270
}
273-
output.push_str("\n");
271+
output.push('\n');
274272
}
275273
}
276274
}
@@ -306,7 +304,7 @@ impl ChangelogGenerator {
306304
if breaking > 0 {
307305
output.push_str(&format!("- ⚠️ **Breaking Changes**: {}\n", breaking));
308306
}
309-
output.push_str("\n");
307+
output.push('\n');
310308

311309
// Highlights (features and breaking changes)
312310
let feature_entries: Vec<_> = entries
@@ -319,7 +317,7 @@ impl ChangelogGenerator {
319317
for entry in feature_entries.iter().take(5) {
320318
output.push_str(&format!("- {}\n", entry.message));
321319
}
322-
output.push_str("\n");
320+
output.push('\n');
323321
}
324322

325323
// Breaking changes
@@ -330,7 +328,7 @@ impl ChangelogGenerator {
330328
for entry in &breaking_entries {
331329
output.push_str(&format!("- {}\n", entry.message));
332330
}
333-
output.push_str("\n");
331+
output.push('\n');
334332
}
335333

336334
// Bug fixes
@@ -344,7 +342,7 @@ impl ChangelogGenerator {
344342
for entry in fix_entries.iter().take(10) {
345343
output.push_str(&format!("- {}\n", entry.message));
346344
}
347-
output.push_str("\n");
345+
output.push('\n');
348346
}
349347

350348
// Contributors

src/core/comment.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use anyhow::Result;
22
use serde::{Deserialize, Serialize};
33
use std::collections::HashMap;
4-
use std::path::PathBuf;
4+
use std::path::{Path, PathBuf};
55

66
#[derive(Debug, Clone, Serialize, Deserialize)]
77
pub struct Comment {
@@ -130,7 +130,7 @@ impl CommentSynthesizer {
130130
let confidence = raw
131131
.confidence
132132
.unwrap_or_else(|| Self::calculate_confidence(&raw.content, &severity, &category));
133-
let confidence = confidence.max(0.0).min(1.0);
133+
let confidence = confidence.clamp(0.0, 1.0);
134134
let tags = if raw.tags.is_empty() {
135135
Self::extract_tags(&raw.content, &category)
136136
} else {
@@ -158,7 +158,7 @@ impl CommentSynthesizer {
158158
}))
159159
}
160160

161-
fn generate_comment_id(file_path: &PathBuf, content: &str, category: &Category) -> String {
161+
fn generate_comment_id(file_path: &Path, content: &str, category: &Category) -> String {
162162
compute_comment_id(file_path, content, category)
163163
}
164164

@@ -233,7 +233,7 @@ impl CommentSynthesizer {
233233
}
234234

235235
// Ensure confidence stays in bounds
236-
confidence.min(1.0).max(0.1)
236+
confidence.clamp(0.1, 1.0)
237237
}
238238

239239
fn extract_tags(content: &str, category: &Category) -> Vec<String> {
@@ -345,7 +345,7 @@ impl CommentSynthesizer {
345345
score -= penalty;
346346
}
347347

348-
score.max(0.0).min(10.0)
348+
score.clamp(0.0, 10.0)
349349
}
350350

351351
fn generate_recommendations(comments: &[Comment]) -> Vec<String> {
@@ -395,7 +395,7 @@ impl CommentSynthesizer {
395395
});
396396
}
397397

398-
fn sort_by_priority(comments: &mut Vec<Comment>) {
398+
fn sort_by_priority(comments: &mut [Comment]) {
399399
comments.sort_by_key(|c| {
400400
let severity_priority = match c.severity {
401401
Severity::Error => 0,
@@ -424,7 +424,7 @@ impl CommentSynthesizer {
424424
}
425425
}
426426

427-
pub fn compute_comment_id(file_path: &PathBuf, content: &str, category: &Category) -> String {
427+
pub fn compute_comment_id(file_path: &Path, content: &str, category: &Category) -> String {
428428
let normalized = normalize_content(content);
429429
let key = format!("{}|{:?}|{}", file_path.display(), category, normalized);
430430
let hash = fnv1a64(key.as_bytes());

src/core/context.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,9 @@ impl ContextFetcher {
8989
};
9090

9191
if let Ok(entries) = glob(&pattern_path) {
92-
for entry in entries {
93-
if let Ok(path) = entry {
94-
if path.is_file() {
95-
matched_paths.insert(path);
96-
}
92+
for path in entries.flatten() {
93+
if path.is_file() {
94+
matched_paths.insert(path);
9795
}
9896
}
9997
}

src/core/interactive.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ impl InteractiveCommand {
5858

5959
pub async fn execute(
6060
&self,
61-
adapter: &Box<dyn LLMAdapter>,
61+
adapter: &dyn LLMAdapter,
6262
diff_content: Option<&str>,
6363
) -> Result<String> {
6464
match &self.command {
@@ -73,7 +73,7 @@ impl InteractiveCommand {
7373

7474
async fn execute_review(
7575
&self,
76-
adapter: &Box<dyn LLMAdapter>,
76+
adapter: &dyn LLMAdapter,
7777
diff_content: Option<&str>,
7878
) -> Result<String> {
7979
if let Some(diff) = diff_content {
@@ -116,7 +116,7 @@ impl InteractiveCommand {
116116

117117
async fn execute_explain(
118118
&self,
119-
adapter: &Box<dyn LLMAdapter>,
119+
adapter: &dyn LLMAdapter,
120120
diff_content: Option<&str>,
121121
) -> Result<String> {
122122
let context = if self.args.is_empty() {
@@ -143,7 +143,7 @@ impl InteractiveCommand {
143143
Ok(format!("## 💡 Explanation\n\n{}", response.content))
144144
}
145145

146-
async fn execute_generate(&self, adapter: &Box<dyn LLMAdapter>) -> Result<String> {
146+
async fn execute_generate(&self, adapter: &dyn LLMAdapter) -> Result<String> {
147147
if self.args.is_empty() {
148148
return Ok(
149149
"Please specify what to generate (e.g., @diffscope generate tests)".to_string(),

src/core/pr_summary.rs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,33 +4,25 @@ use anyhow::Result;
44

55
pub struct PRSummaryGenerator;
66

7-
#[derive(Debug, Clone)]
7+
#[derive(Debug, Clone, Default)]
88
pub struct SummaryOptions {
99
pub include_diagram: bool,
1010
}
1111

12-
impl Default for SummaryOptions {
13-
fn default() -> Self {
14-
Self {
15-
include_diagram: false,
16-
}
17-
}
18-
}
19-
2012
impl PRSummaryGenerator {
2113
#[allow(dead_code)]
2214
pub async fn generate_summary(
2315
diffs: &[UnifiedDiff],
2416
git: &GitIntegration,
25-
adapter: &Box<dyn LLMAdapter>,
17+
adapter: &dyn LLMAdapter,
2618
) -> Result<PRSummary> {
2719
Self::generate_summary_with_options(diffs, git, adapter, SummaryOptions::default()).await
2820
}
2921

3022
pub async fn generate_summary_with_options(
3123
diffs: &[UnifiedDiff],
3224
git: &GitIntegration,
33-
adapter: &Box<dyn LLMAdapter>,
25+
adapter: &dyn LLMAdapter,
3426
options: SummaryOptions,
3527
) -> Result<PRSummary> {
3628
// Get commit messages for context
@@ -57,7 +49,7 @@ impl PRSummaryGenerator {
5749

5850
pub async fn generate_change_diagram(
5951
diffs: &[UnifiedDiff],
60-
adapter: &Box<dyn LLMAdapter>,
52+
adapter: &dyn LLMAdapter,
6153
) -> Result<Option<String>> {
6254
let stats = Self::calculate_stats(diffs);
6355
let prompt = Self::build_diagram_prompt(diffs, &stats);
@@ -133,7 +125,7 @@ impl PRSummaryGenerator {
133125
prompt.push_str("Generate a comprehensive PR summary based on the following changes:\n\n");
134126

135127
// Add statistics
136-
prompt.push_str(&format!("## Statistics\n"));
128+
prompt.push_str("## Statistics\n");
137129
prompt.push_str(&format!("- Files changed: {}\n", stats.files_changed));
138130
prompt.push_str(&format!("- Lines added: {}\n", stats.lines_added));
139131
prompt.push_str(&format!("- Lines removed: {}\n", stats.lines_removed));
@@ -147,7 +139,7 @@ impl PRSummaryGenerator {
147139
for commit in commits.iter().take(5) {
148140
prompt.push_str(&format!("- {}\n", commit));
149141
}
150-
prompt.push_str("\n");
142+
prompt.push('\n');
151143
}
152144

153145
// Add file changes summary
@@ -376,7 +368,7 @@ impl PRSummary {
376368
for change in &self.key_changes {
377369
output.push_str(&format!("- {}\n", change));
378370
}
379-
output.push_str("\n");
371+
output.push('\n');
380372
}
381373

382374
// Statistics
@@ -406,7 +398,7 @@ impl PRSummary {
406398
self.stats.doc_files
407399
));
408400
}
409-
output.push_str("\n");
401+
output.push('\n');
410402

411403
// Breaking changes
412404
if let Some(breaking) = &self.breaking_changes {
@@ -444,15 +436,15 @@ fn extract_mermaid_diagram(content: &str) -> Option<String> {
444436
}
445437

446438
// Seek to mermaid block
447-
while let Some(next_line) = lines.next() {
439+
for next_line in lines.by_ref() {
448440
let next_trimmed = next_line.trim();
449441
if next_trimmed.starts_with("```") && next_trimmed.contains("mermaid") {
450442
break;
451443
}
452444
}
453445

454446
let mut diagram_lines = Vec::new();
455-
while let Some(block_line) = lines.next() {
447+
for block_line in lines.by_ref() {
456448
let block_trimmed = block_line.trim();
457449
if block_trimmed.starts_with("```") {
458450
break;

src/core/smart_review_prompt.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,9 @@ TAGS: [comma-separated relevant tags]
106106
for chunk in context_chunks {
107107
let (start_line, end_line) = chunk.line_range.unwrap_or((1, 1));
108108
let description = format!(
109-
"{} - {}",
109+
"{} - {:?}",
110110
chunk.file_path.display(),
111-
format!("{:?}", chunk.context_type)
111+
chunk.context_type
112112
);
113113
let block = format!(
114114
"**{}** (lines {}-{}):\n```\n{}\n```\n\n",

0 commit comments

Comments
 (0)