#![deny(
clippy::panic,
clippy::unwrap_used,
clippy::expect_used,
clippy::pedantic
)]
use serde::{Deserialize, Serialize};
use std::path::PathBuf;
pub mod analyzer;
pub mod config;
pub mod errors;
pub mod languages;
pub mod report;
pub use config::Config;
pub use config::thresholds::{PartialThresholds, Thresholds, ThresholdsConfig};
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct FileReport {
pub path: PathBuf,
pub lines: usize,
pub imports: usize,
pub max_depth: usize,
pub repetition: f64,
pub is_sweet: bool,
pub issues: Vec<String>,
pub config: Option<Config>,
pub duplicates: Vec<RepetitionDetail>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct RepetitionDetail {
pub content: String,
pub line: usize,
pub occurrences: Vec<(PathBuf, usize)>,
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_config_overrides() {
let mut config = Config::default();
config.thresholds.overrides.java = Some(PartialThresholds {
max_imports: Some(100),
..Default::default()
});
let t = config.get_thresholds("java");
assert_eq!(t.max_imports, 100);
assert_eq!(t.max_lines, 250);
}
#[test]
fn test_is_supported_file() {
assert!(Config::is_supported_file(std::path::Path::new("test.rs")));
assert!(!Config::is_supported_file(std::path::Path::new("test.txt")));
}
#[cfg(feature = "schema")]
#[test]
fn generate_schema() -> miette::Result<()> {
use schemars::schema_for;
use std::fs;
let schema = schema_for!(Config);
let schema_json = serde_json::to_string_pretty(&schema)
.map_err(|e| miette::miette!("Failed to serialize schema: {}", e))?;
fs::write("schema.json", schema_json)
.map_err(|e| miette::miette!("Failed to write schema.json: {}", e))?;
Ok(())
}
}