Skip to content

Commit 70321d6

Browse files
Copilot0xrinegade
andcommitted
Fix cargo fmt and clippy issues - format code according to style guidelines
Co-authored-by: 0xrinegade <[email protected]>
1 parent cbfb588 commit 70321d6

File tree

10 files changed

+48
-38
lines changed

10 files changed

+48
-38
lines changed

src/main.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,11 @@
44
use {
55
crate::config::Config,
66
crate::utils::diagnostics::DiagnosticCoordinator,
7-
crate::utils::{dashboard, ebpf_deploy, examples, nodes, ssh_deploy, svm_info},
87
crate::utils::markdown_renderer::MarkdownRenderer,
8+
crate::utils::{dashboard, ebpf_deploy, examples, nodes, ssh_deploy, svm_info},
99
clparse::parse_command_line,
1010
solana_client::rpc_client::RpcClient,
11-
solana_sdk::{
12-
native_token::Sol,
13-
pubkey::Pubkey,
14-
signature::Signer
15-
},
11+
solana_sdk::{native_token::Sol, pubkey::Pubkey, signature::Signer},
1612
std::{process::exit, str::FromStr},
1713
};
1814

@@ -64,18 +60,18 @@ async fn handle_ai_query(
6460
// For external subcommands, clap collects additional arguments in subcommand_value
6561
// This is the proper way to handle external subcommands with clap
6662
let mut query_parts = vec![sub_command.to_string()];
67-
63+
6864
// Get additional arguments from clap's external subcommand handling
6965
// External subcommands store arguments as OsString, not String
7066
if let Some(external_args) = sub_matches.get_many::<std::ffi::OsString>("") {
7167
query_parts.extend(external_args.map(|os_str| os_str.to_string_lossy().to_string()));
7268
}
73-
69+
7470
// If clap doesn't provide args (fallback), parse from environment
7571
// This maintains compatibility while documenting the limitation
7672
if query_parts.len() == 1 {
7773
let args: Vec<String> = std::env::args().collect();
78-
74+
7975
// Collect non-flag arguments starting from the subcommand
8076
let mut found_subcommand = false;
8177
for arg in args.iter().skip(1) {

src/services/ai_service.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,9 @@ impl AiService {
108108
let mut template_manager = PromptTemplateManager::new();
109109

110110
// Initialize template manager
111-
if let Err(e) = template_manager.load_from_directory_with_debug("./templates/ai_prompts", debug_mode) {
111+
if let Err(e) =
112+
template_manager.load_from_directory_with_debug("./templates/ai_prompts", debug_mode)
113+
{
112114
if debug_mode {
113115
println!("⚠️ Failed to load AI prompt templates: {}", e);
114116
}

src/utils/ast_analyzer.rs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -294,8 +294,9 @@ impl AstAnalyzer {
294294
let after_let = &content[start + 4..];
295295
if let Some(equals_pos) = after_let.find(" = ") {
296296
let var_name = after_let[..equals_pos].trim();
297-
if content.contains(&format!("{}.balance", var_name)) ||
298-
content.contains(&format!("{}.", var_name)) {
297+
if content.contains(&format!("{}.balance", var_name))
298+
|| content.contains(&format!("{}.", var_name))
299+
{
299300
return Some(var_name.to_string());
300301
}
301302
}
@@ -309,7 +310,9 @@ impl AstAnalyzer {
309310

310311
match finding.category.as_str() {
311312
"Authentication & Authorization" => {
312-
if !content.contains("is_signer") && (content.contains("AccountInfo") || content.contains("ctx.accounts")) {
313+
if !content.contains("is_signer")
314+
&& (content.contains("AccountInfo") || content.contains("ctx.accounts"))
315+
{
313316
// Extract account variable name from the content
314317
if let Some(account_var) = self.extract_account_variable_name(content) {
315318
fixed_content = format!(
@@ -419,8 +422,9 @@ impl SolanaSecurityVisitor {
419422

420423
// Check for missing signer validation
421424
// Token stream format: "ctx . accounts" instead of "ctx.accounts"
422-
if (func_str.contains("ctx . accounts") || func_str.contains("ctx.accounts")) &&
423-
!func_str.contains("is_signer") {
425+
if (func_str.contains("ctx . accounts") || func_str.contains("ctx.accounts"))
426+
&& !func_str.contains("is_signer")
427+
{
424428
self.context.security_issues.push(SecurityIssue {
425429
issue_type: SecurityIssueType::MissingSignerCheck,
426430
location: CodeLocation {

src/utils/audit_modular.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1423,7 +1423,7 @@ mod tests {
14231423
let findings_hardcoded = check
14241424
.check_content(code_with_hardcoded_key, "test.rs")
14251425
.unwrap();
1426-
1426+
14271427
let hardcoded_findings: Vec<_> = findings_hardcoded
14281428
.iter()
14291429
.filter(|f| f.title.contains("hardcoded Solana public key"))

src/utils/audit_parser.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,11 +322,11 @@ impl SecurityVisitor {
322322
fn analyze_field_access(&mut self, expr: &Expr, field_expr: &syn::ExprField) {
323323
let field_name = field_expr.member.to_token_stream().to_string();
324324
let receiver_str = quote::quote!(#expr).to_string();
325-
325+
326326
// Look for Solana account field access patterns
327327
if receiver_str.contains("account") {
328328
let line_num = self.get_line_number_for_pattern(&format!(".{}", field_name));
329-
329+
330330
match field_name.as_str() {
331331
"owner" => {
332332
let mut solana_op = SolanaOperation {

src/utils/audit_tests.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ mod tests {
7575

7676
// With empty API key, this should succeed and use internal OSVM AI service
7777
match AuditService::validate_environment(&request) {
78-
Ok(()) => true, // Success expected when using internal service
78+
Ok(()) => true, // Success expected when using internal service
7979
Err(_) => false,
8080
}
8181
});
@@ -119,7 +119,7 @@ mod tests {
119119

120120
// With whitespace API key, this should succeed and use internal OSVM AI service
121121
match AuditService::validate_environment(&request) {
122-
Ok(()) => true, // Success expected when using internal service
122+
Ok(()) => true, // Success expected when using internal service
123123
Err(_) => false,
124124
}
125125
});

src/utils/code_extractor.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,9 @@ impl CodeExtractor {
215215

216216
match finding.category.as_str() {
217217
"Authentication & Authorization" => {
218-
if !content.contains("is_signer") && (content.contains("AccountInfo") || content.contains("ctx.accounts")) {
218+
if !content.contains("is_signer")
219+
&& (content.contains("AccountInfo") || content.contains("ctx.accounts"))
220+
{
219221
fixed_content = fixed_content.replace(
220222
"let user_account = &ctx.accounts.user_account;",
221223
"let user_account = &ctx.accounts.user_account;\n require!(user_account.is_signer, ErrorCode::MissingSignature);"

src/utils/markdown_renderer.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use termimad::{MadSkin};
1+
use termimad::MadSkin;
22

33
/// A markdown renderer for CLI output
44
#[derive(Debug, Clone)]
@@ -65,4 +65,4 @@ mod tests {
6565
let result = renderer.render_to_string("# Themed Test");
6666
assert!(result.contains("Themed Test"));
6767
}
68-
}
68+
}

src/utils/prompt_templates.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,11 @@ impl PromptTemplateManager {
138138
self.load_from_directory_with_debug(dir_path, true)
139139
}
140140

141-
pub fn load_from_directory_with_debug(&mut self, dir_path: &str, debug_mode: bool) -> Result<usize> {
141+
pub fn load_from_directory_with_debug(
142+
&mut self,
143+
dir_path: &str,
144+
debug_mode: bool,
145+
) -> Result<usize> {
142146
self.template_dirs.push(dir_path.to_string());
143147

144148
let dir = Path::new(dir_path);
@@ -579,7 +583,7 @@ mod tests {
579583
fn test_template_loading() {
580584
let temp_dir = TempDir::new().unwrap();
581585
let temp_path = temp_dir.path();
582-
586+
583587
// Create a simple template file for testing
584588
let template_content = r#"id: test_template
585589
name: Test Template
@@ -603,10 +607,10 @@ version: 1.0.0
603607
enabled: true
604608
metadata: {}
605609
"#;
606-
610+
607611
let template_file = temp_path.join("test_template.yaml");
608612
std::fs::write(&template_file, template_content).unwrap();
609-
613+
610614
let mut manager = PromptTemplateManager::new();
611615

612616
let loaded = manager
@@ -621,16 +625,16 @@ metadata: {}
621625
#[test]
622626
fn test_template_rendering() {
623627
let mut manager = PromptTemplateManager::new();
624-
628+
625629
// Load from the actual templates directory
626630
let templates_dir = "templates/ai_prompts";
627631
let loaded = manager.load_from_directory(templates_dir).unwrap_or(0);
628-
632+
629633
// If no templates in the actual directory, create a test template
630634
if loaded == 0 {
631635
let temp_dir = TempDir::new().unwrap();
632636
let temp_path = temp_dir.path();
633-
637+
634638
// Create the specific template the test expects
635639
let template_content = r#"id: deeplogic_economic_exploit
636640
name: DeepLogic Economic Exploit Analysis
@@ -659,11 +663,13 @@ version: 1.0.0
659663
enabled: true
660664
metadata: {}
661665
"#;
662-
666+
663667
let template_file = temp_path.join("deeplogic_economic_exploit.yaml");
664668
std::fs::write(&template_file, template_content).unwrap();
665-
666-
manager.load_from_directory(temp_dir.path().to_str().unwrap()).unwrap();
669+
670+
manager
671+
.load_from_directory(temp_dir.path().to_str().unwrap())
672+
.unwrap();
667673
}
668674

669675
let mut variables = HashMap::new();

tests/debug_flag_tests.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ fn test_ai_query_without_debug_flag() {
99
.expect("Failed to execute command");
1010

1111
let stdout = String::from_utf8_lossy(&output.stdout);
12-
12+
1313
// Should not contain debug information
1414
assert!(!stdout.contains("🔍 Interpreting as AI query"));
1515
assert!(!stdout.contains("✅ Loaded"));
1616
assert!(!stdout.contains("📤 OSVM AI Request"));
1717
assert!(!stdout.contains("📥 OSVM AI Response"));
1818
assert!(!stdout.contains("🔍 AI Response received"));
1919
assert!(!stdout.contains("🤖 AI Response:"));
20-
20+
2121
// Should contain the actual response (without debug prefix)
2222
assert!(!stdout.is_empty());
2323
}
@@ -30,7 +30,7 @@ fn test_ai_query_with_debug_flag() {
3030
.expect("Failed to execute command");
3131

3232
let stdout = String::from_utf8_lossy(&output.stdout);
33-
33+
3434
// Should contain debug information
3535
assert!(stdout.contains("🔍 Interpreting as AI query"));
3636
assert!(stdout.contains("✅ Loaded"));
@@ -48,8 +48,8 @@ fn test_debug_flag_appears_in_help() {
4848
.expect("Failed to execute command");
4949

5050
let stdout = String::from_utf8_lossy(&output.stdout);
51-
51+
5252
// Should contain debug flag in help
5353
assert!(stdout.contains("--debug"));
5454
assert!(stdout.contains("Show debug information"));
55-
}
55+
}

0 commit comments

Comments
 (0)