Refactor and simplify code in index.rs, scan.rs, and database.rs

- Removed unnecessary references and improved clarity in `Indexer` method calls.
- Reorganized conditionals and eliminated redundant variable assignments in `scan.rs`.
- Simplified database initialization handling by removing unused commented-out code and improving formatting in `database.rs`.
This commit is contained in:
elipeter 2025-06-23 17:49:15 +02:00
parent 8bc16ac940
commit 952e83453a
3 changed files with 9 additions and 18 deletions

View file

@ -53,7 +53,7 @@ pub fn build_index(
let pool = Indexer::init(db_path)?;
{
let idx = Indexer::from_pool(&project_name, &pool).unwrap();
let idx = Indexer::from_pool(project_name, &pool).unwrap();
idx.clear()?;
}
@ -83,7 +83,7 @@ pub fn build_index(
}).unwrap();
{
let idx = Indexer::from_pool(&project_name, &pool)?;
let idx = Indexer::from_pool(project_name, &pool)?;
idx.vacuum()?;
}

View file

@ -35,10 +35,9 @@ pub fn handle(
) -> Result<(), Box<dyn std::error::Error>> {
let scan_path = Path::new(path).canonicalize()?;
let (project_name, db_path) = get_project_info(&scan_path, database_dir)?;
let diags: Vec<Diag>;
if no_index {
diags = scan_filesystem(&scan_path, config).unwrap();
let diags: Vec<Diag> = if no_index {
scan_filesystem(&scan_path, config).unwrap()
} else {
if rebuild_index || !db_path.exists() {
tracing::debug!("Scanning filesystem index filesystem");
@ -46,12 +45,12 @@ pub fn handle(
}
let pool = Indexer::init(&db_path)?;
diags = scan_with_index_parallel(&project_name, pool, config)?;
}
scan_with_index_parallel(&project_name, pool, config)?
};
tracing::debug!("Found {:?} issues.", diags.len());
if format == "console" || (format == "" && config.output.default_format == "console") {
if format == "console" || (format.is_empty() && config.output.default_format == "console") {
tracing::debug!("Printing to console");
for d in &diags {
let sev_str = match d.severity {