Skip to content

armgit / jan

Public Imported from GitHub
0

Jan is an open source alternative to ChatGPT that runs 100% offline on your computer.

fix(rust): satisfy clippy -D warnings across utils and agent crates (#8650)

Akarshan Biswas3297b0127d50
diff --git a/.gitignore b/.gitignore
index 9064ea68d..221ddba0d 100644
--- a/.gitignore
+++ b/.gitignore
@@ -74,6 +74,7 @@ llm-docs
.claude/agents
.claude
CLAUDE.md
+JAN.md
## agent
.jan
diff --git a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/gate.rs b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/gate.rs
index 94ab39976..9d0d33d58 100644
--- a/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/gate.rs
+++ b/src-tauri/plugins/tauri-plugin-agent-tools/src/tools/gate.rs
@@ -672,6 +672,7 @@ mod tests {
}
#[test]
+ #[allow(clippy::join_absolute_paths)]
fn write_escaping_project_prompts_write_escape() {
let root = unique_root();
let perms = ToolPermissions::new(PermissionDefault::ReadOnly, &[], &[], &[]);
diff --git a/src-tauri/src/core/agent/global_config.rs b/src-tauri/src/core/agent/global_config.rs
index be8d45b29..161a042d4 100644
--- a/src-tauri/src/core/agent/global_config.rs
+++ b/src-tauri/src/core/agent/global_config.rs
@@ -487,7 +487,7 @@ models = ["gpt-4o"]
set_provider("openai", ProviderUpdate { api_key: Some("sk-1".into()), ..Default::default() }).unwrap();
assert!(remove_provider("openai").expect("remove"));
assert!(!remove_provider("openai").expect("remove again"));
- assert!(load_global_config().unwrap().get("openai").is_none());
+ assert!(!load_global_config().unwrap().contains_key("openai"));
});
}
diff --git a/src-tauri/src/core/agent/loop.rs b/src-tauri/src/core/agent/loop.rs
index 43ad62d3f..f63196233 100644
--- a/src-tauri/src/core/agent/loop.rs
+++ b/src-tauri/src/core/agent/loop.rs
@@ -2146,10 +2146,8 @@ mod tests {
saw_tool_call = true;
}
}
- StreamEvent::ToolResult { content, .. } => {
- if content == "MOCK_RESULT" {
- saw_tool_result = true;
- }
+ StreamEvent::ToolResult { content, .. } if content == "MOCK_RESULT" => {
+ saw_tool_result = true;
}
_ => {}
}
diff --git a/src-tauri/utils/src/crypto.rs b/src-tauri/utils/src/crypto.rs
index b5d4963f6..25d510abc 100644
--- a/src-tauri/utils/src/crypto.rs
+++ b/src-tauri/utils/src/crypto.rs
@@ -66,6 +66,9 @@ pub async fn compute_file_sha256_with_cancellation(
total_read += bytes_read as u64;
// Log progress for very large files (every 100MB)
+ // `% == 0` (not `is_multiple_of`) keeps the MSRV at the declared floor
+ // of 1.82; `is_multiple_of` is stable only since 1.87.
+ #[allow(clippy::manual_is_multiple_of)]
if total_read % (100 * 1024 * 1024) == 0 {
#[cfg(feature = "logging")]
log::debug!("Hash progress: {} MB processed", total_read / (1024 * 1024));
diff --git a/src-tauri/utils/src/math.rs b/src-tauri/utils/src/math.rs
index 05de74586..8b48365c8 100644
--- a/src-tauri/utils/src/math.rs
+++ b/src-tauri/utils/src/math.rs
@@ -31,22 +31,13 @@ pub fn calculate_exponential_backoff_delay(attempt: u32) -> u64 {
let hash = hasher.finish();
// Convert hash to jitter value in range [-jitter_range, +jitter_range]
- let jitter_offset = (hash % (jitter_range * 2)) as i64 - jitter_range as i64;
- jitter_offset
+ (hash % (jitter_range * 2)) as i64 - jitter_range as i64
} else {
0
};
// Apply jitter while ensuring delay stays positive and within bounds
- let final_delay = cmp::max(
- 100, // Minimum 100ms delay
- cmp::min(
- MCP_MAX_RESTART_DELAY_MS,
- (capped_delay as i64 + jitter) as u64,
- ),
- );
-
- final_delay
+ ((capped_delay as i64 + jitter) as u64).clamp(100, MCP_MAX_RESTART_DELAY_MS)
}
#[cfg(test)]
@@ -60,13 +51,13 @@ mod tests {
let delay3 = calculate_exponential_backoff_delay(3);
// First attempt should be around base delay (1000ms) ± jitter
- assert!(delay1 >= 100 && delay1 <= 2000);
+ assert!((100..=2000).contains(&delay1));
// Second attempt should be roughly double
- assert!(delay2 >= 1000 && delay2 <= 4000);
+ assert!((1000..=4000).contains(&delay2));
// Third attempt should be roughly quadruple
- assert!(delay3 >= 2000 && delay3 <= 6000);
+ assert!((2000..=6000).contains(&delay3));
// Generally increasing pattern
assert!(delay1 < delay3);
@@ -128,6 +119,6 @@ mod tests {
assert_eq!(MCP_BACKOFF_MULTIPLIER, 2.0);
// Max should be greater than base
- assert!(MCP_MAX_RESTART_DELAY_MS > MCP_BASE_RESTART_DELAY_MS);
+ const { assert!(MCP_MAX_RESTART_DELAY_MS > MCP_BASE_RESTART_DELAY_MS) };
}
}
diff --git a/src-tauri/utils/src/network.rs b/src-tauri/utils/src/network.rs
index 738a5fd48..3c5f96de8 100644
--- a/src-tauri/utils/src/network.rs
+++ b/src-tauri/utils/src/network.rs
@@ -125,8 +125,7 @@ pub fn should_bypass_proxy(url: &str, no_proxy: &[String]) -> bool {
}
// Simple wildcard matching
- if entry.starts_with("*.") {
- let domain = &entry[2..];
+ if let Some(domain) = entry.strip_prefix("*.") {
if host.ends_with(domain) {
return true;
}
@@ -203,7 +202,7 @@ fn find_process_using_port_unix(port: u16) -> Option<ProcessUsingPort> {
use std::process::Command;
let output = Command::new("lsof")
- .args(&["-i", &format!(":{}", port)])
+ .args(["-i", &format!(":{}", port)])
.output()
.ok()?;
@@ -289,7 +288,7 @@ fn get_process_command_line(pid: u32) -> Option<Vec<String>> {
use std::process::Command;
let output = Command::new("ps")
- .args(&["-p", &pid.to_string(), "-o", "command="])
+ .args(["-p", &pid.to_string(), "-o", "command="])
.output()
.ok()?;
@@ -369,7 +368,7 @@ fn get_process_info_by_pid_unix(pid: u32) -> Option<ProcessUsingPort> {
// Use ps to get process info by PID
let output = Command::new("ps")
- .args(&["-p", &pid.to_string(), "-o", "comm="])
+ .args(["-p", &pid.to_string(), "-o", "comm="])
.output()
.ok()?;
diff --git a/src-tauri/utils/src/string.rs b/src-tauri/utils/src/string.rs
index a31611c07..a444cae24 100644
--- a/src-tauri/utils/src/string.rs
+++ b/src-tauri/utils/src/string.rs
@@ -31,9 +31,9 @@ pub fn err_to_string<E: std::fmt::Display>(e: E) -> String {
pub fn find_memory_pattern(text: &str) -> Option<(usize, &str)> {
// Find the last parenthesis that contains the memory pattern
let mut last_match = None;
- let mut chars = text.char_indices().peekable();
+ let chars = text.char_indices();
- while let Some((start_idx, ch)) = chars.next() {
+ for (start_idx, ch) in chars {
if ch == '(' {
// Find the closing parenthesis
let remaining = &text[start_idx + 1..];
@@ -69,7 +69,7 @@ pub fn is_memory_pattern(content: &str) -> bool {
// Each part should start with a number and contain "MiB"
part.split_whitespace()
.next()
- .map_or(false, |first_word| first_word.parse::<i32>().is_ok())
+ .is_some_and(|first_word| first_word.parse::<i32>().is_ok())
&& part.contains("MiB")
})
}
@@ -129,7 +129,7 @@ mod tests {
let with_negative = [-1, b'A' as i8, b'B' as i8, 0];
let result = parse_c_string(&with_negative);
// Should convert negative to unsigned byte
- assert!(result.len() > 0);
+ assert!(!result.is_empty());
assert!(result.contains('A'));
assert!(result.contains('B'));
}
diff --git a/src-tauri/utils/src/system.rs b/src-tauri/utils/src/system.rs
index 33af47d81..21216c520 100644
--- a/src-tauri/utils/src/system.rs
+++ b/src-tauri/utils/src/system.rs
@@ -113,8 +113,8 @@ pub fn setup_library_path(
let mut all_dirs: Vec<String> = Vec::new();
if let Some(lib_path) = library_path {
let lib_str = lib_path.to_string_lossy();
- let normalized = if lib_str.starts_with(r"\\?\") {
- lib_str[4..].to_string()
+ let normalized = if let Some(stripped) = lib_str.strip_prefix(r"\\?\") {
+ stripped.to_string()
} else {
lib_str.to_string()
};