#![cfg_attr(coverage_nightly, coverage(off))]
use crate::models::defect_report::{Defect, DefectCategory, Severity};
use crate::models::tdg::{TDGScore, TDGSeverity};
use crate::services::{
big_o_analyzer::FunctionComplexity,
dead_code_analyzer::{DeadCodeItem, UnreachableBlock},
defect_analyzer::{AnalyzerConfig, DefectAnalyzer},
duplicate_detector::{CloneGroup, CloneType},
satd_detector::{DebtCategory, TechnicalDebt},
};
use anyhow::Result;
use async_trait::async_trait;
use std::collections::HashMap;
use std::path::{Path, PathBuf};
async fn discover_source_files(path: &Path) -> Result<Vec<PathBuf>> {
use walkdir::WalkDir;
let mut files = Vec::new();
let extensions = ["rs", "js", "ts", "py", "java", "cpp", "c", "go"];
for entry in WalkDir::new(path)
.follow_links(false)
.into_iter()
.filter_map(std::result::Result::ok)
.filter(|e| e.file_type().is_file())
{
let path = entry.path();
if let Some(ext) = path.extension().and_then(|e| e.to_str()) {
if extensions.contains(&ext) {
files.push(path.to_path_buf());
}
}
}
Ok(files)
}
pub struct ComplexityDefectAnalyzer;
#[derive(Clone)]
pub struct ComplexityConfig {
pub max_tdg_score: f64,
pub high_threshold: f64,
}
impl Default for ComplexityConfig {
fn default() -> Self {
Self {
max_tdg_score: 2.0,
high_threshold: 1.5,
}
}
}
impl AnalyzerConfig for ComplexityConfig {}
#[derive(Clone, Default)]
pub struct SATDConfig {
pub include_test_files: bool,
}
impl AnalyzerConfig for SATDConfig {}
pub struct SATDDefectAnalyzer {
detector: crate::services::satd_detector::SATDDetector,
}
pub struct DeadCodeDefectAnalyzer;
#[derive(Clone)]
pub struct DeadCodeConfig {
pub min_confidence: f64,
}
impl Default for DeadCodeConfig {
fn default() -> Self {
Self {
min_confidence: 0.7,
}
}
}
impl AnalyzerConfig for DeadCodeConfig {}
pub struct DuplicationDefectAnalyzer {
detector: crate::services::duplicate_detector::DuplicateDetectionEngine,
}
#[derive(Clone)]
pub struct DuplicationConfig {
pub min_similarity: f64,
}
impl Default for DuplicationConfig {
fn default() -> Self {
Self {
min_similarity: 0.8,
}
}
}
impl AnalyzerConfig for DuplicationConfig {}
pub struct PerformanceDefectAnalyzer {
analyzer: crate::services::big_o_analyzer::BigOAnalyzer,
}
#[derive(Clone, Default)]
pub struct PerformanceConfig {
pub include_nlogn: bool,
}
impl AnalyzerConfig for PerformanceConfig {}
pub struct ArchitectureDefectAnalyzer;
#[derive(Clone)]
pub struct ArchitectureConfig {
pub max_coupling: usize,
}
impl Default for ArchitectureConfig {
fn default() -> Self {
Self { max_coupling: 10 }
}
}
impl AnalyzerConfig for ArchitectureConfig {}
include!("defect_analyzers_complexity.rs");
include!("defect_analyzers_debt.rs");
include!("defect_analyzers_dead_code.rs");
include!("defect_analyzers_duplication.rs");
include!("defect_analyzers_performance.rs");
#[cfg(test)]
#[path = "defect_analyzers_tests.rs"]
mod tests;