Skip to main content

crap4rust/
project_report.rs

1// Copyright 2025 Umberto Gotti <umberto.gotti@umbertogotti.dev>
2// Licensed under the MIT License
3// SPDX-License-Identifier: MIT
4
5use std::process::ExitCode;
6
7use serde::Serialize;
8
9use crate::config::Config;
10use crate::function_report::FunctionReport;
11use crate::verdict::Verdict;
12
13#[derive(Debug, Clone, Serialize)]
14pub struct ProjectReport {
15    pub scope_name: String,
16    pub total_functions: usize,
17    pub crappy_functions: usize,
18    pub crappy_percent: f64,
19    pub verdict: Verdict,
20    pub functions: Vec<FunctionReport>,
21}
22
23impl ProjectReport {
24    #[must_use]
25    pub fn exit_code(&self, config: &Config) -> ExitCode {
26        if config.warn_only {
27            return ExitCode::SUCCESS;
28        }
29        if config.fails(self.crappy_functions, self.crappy_percent) {
30            ExitCode::from(1)
31        } else {
32            ExitCode::SUCCESS
33        }
34    }
35}