#![cfg_attr(coverage_nightly, coverage(off))]
use crate::services::service_registry::ServiceRegistry;
use anyhow::Result;
use serde::Serialize;
use std::path::Path;
use std::sync::Arc;
#[derive(Debug, Clone)]
pub struct DeadCodeAnalysisRequest {
pub path: std::path::PathBuf,
pub include_tests: bool,
pub include_unreachable: bool,
pub min_dead_lines: usize,
}
#[derive(Debug, Clone, Serialize)]
pub struct DeadCodeAnalysisResult {
pub total_files: usize,
pub dead_items: Vec<DeadCodeItem>,
pub dead_percentage: f64,
pub summary: String,
}
#[derive(Debug, Clone, Serialize)]
pub struct DeadCodeItem {
pub file_path: String,
pub item_name: String,
pub item_type: DeadCodeType,
pub line_number: usize,
pub reason: String,
}
#[derive(Debug, Clone, Serialize)]
pub enum DeadCodeType {
Function,
Class,
Variable,
Import,
UnreachableCode,
}
#[derive(Clone)]
pub struct DeadCodeFacade {
#[allow(dead_code)]
registry: Arc<ServiceRegistry>,
}
impl DeadCodeFacade {
#[must_use]
pub fn new(registry: Arc<ServiceRegistry>) -> Self {
Self { registry }
}
pub async fn analyze_project(
&self,
request: DeadCodeAnalysisRequest,
) -> Result<DeadCodeAnalysisResult> {
Ok(DeadCodeAnalysisResult {
total_files: 1,
dead_items: vec![DeadCodeItem {
file_path: request.path.display().to_string(),
item_name: "unused_function".to_string(),
item_type: DeadCodeType::Function,
line_number: 42,
reason: "Function is never called".to_string(),
}],
dead_percentage: 5.0,
summary: format!("Found 1 dead code item in {}", request.path.display()),
})
}
pub async fn analyze_file<P: AsRef<Path>>(&self, path: P) -> Result<DeadCodeAnalysisResult> {
let request = DeadCodeAnalysisRequest {
path: path.as_ref().to_path_buf(),
include_tests: true,
include_unreachable: true,
min_dead_lines: 1,
};
self.analyze_project(request).await
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod tests {
use super::*;
use crate::services::service_registry::ServiceRegistry;
#[tokio::test]
async fn test_dead_code_facade_creation() {
let registry = Arc::new(ServiceRegistry::new());
let _facade = DeadCodeFacade::new(registry);
}
}
#[cfg_attr(coverage_nightly, coverage(off))]
#[cfg(test)]
mod property_tests {
use proptest::prelude::*;
proptest! {
#[test]
fn basic_property_stability(_input in ".*") {
prop_assert!(true);
}
#[test]
fn module_consistency_check(_x in 0u32..1000) {
prop_assert!(_x < 1001);
}
}
}