1use std::path::PathBuf;
6
7use serde::Serialize;
8
9use crate::cli::OutputFormat;
10
11#[derive(Debug, Clone)]
12pub struct Config {
13 pub coverage_path: Option<PathBuf>,
14 pub manifest_path: Option<PathBuf>,
15 pub packages: Vec<String>,
16 pub features: Option<String>,
17 pub all_features: bool,
18 pub no_default_features: bool,
19 pub include_test_targets: bool,
20 pub exclude_paths: Vec<String>,
21 pub threshold: f64,
22 pub warn_threshold: f64,
23 pub project_threshold: f64,
24 pub strict: bool,
25 pub warn_only: bool,
26 pub output_format: OutputFormat,
27}
28
29#[derive(Debug, Clone)]
30pub struct PackageContext {
31 pub name: String,
32 pub manifest_dir: PathBuf,
33 pub workspace_root: PathBuf,
34 pub source_roots: Vec<PathBuf>,
35 pub include_test_targets: bool,
36 pub exclude_paths: Vec<String>,
37}
38
39#[derive(Debug, Clone)]
40pub struct SourceFunction {
41 pub package_name: String,
42 pub name: String,
43 pub path_key: String,
44 pub relative_file: String,
45 pub line: usize,
46 pub end_line: usize,
47 pub complexity: u32,
48}
49
50#[derive(Debug, Clone)]
51pub struct CoverageRecord {
52 pub path_key: String,
53 pub line: usize,
54 pub covered_regions: u32,
55 pub total_regions: u32,
56}
57
58impl CoverageRecord {
59 pub fn coverage_ratio(&self) -> f64 {
60 if self.total_regions == 0 {
61 0.0
62 } else {
63 f64::from(self.covered_regions) / f64::from(self.total_regions)
64 }
65 }
66}
67
68#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize)]
69pub enum Verdict {
70 Clean,
71 Warn,
72 Crappy,
73}
74
75impl Verdict {
76 pub fn as_str(self) -> &'static str {
77 match self {
78 Self::Clean => "clean",
79 Self::Warn => "warn",
80 Self::Crappy => "crappy",
81 }
82 }
83}
84
85#[derive(Debug, Clone, Serialize)]
86pub struct FunctionReport {
87 pub package_name: String,
88 pub name: String,
89 pub relative_file: String,
90 pub line: usize,
91 pub complexity: u32,
92 pub coverage: f64,
93 pub crap_score: f64,
94 pub verdict: Verdict,
95}
96
97#[derive(Debug, Clone, Serialize)]
98pub struct ProjectReport {
99 pub scope_name: String,
100 pub total_functions: usize,
101 pub crappy_functions: usize,
102 pub crappy_percent: f64,
103 pub verdict: Verdict,
104 pub functions: Vec<FunctionReport>,
105}