tiger_lib/report/
suppress.rs1use std::borrow::Cow;
2use std::fs::read_to_string;
3use std::path::{Path, PathBuf};
4
5use anyhow::Result;
6use serde::Deserialize;
7
8use crate::helpers::TigerHashMap;
9use crate::report::errors::Errors;
10use crate::report::ErrorKey;
11
12#[derive(Debug, Clone, PartialEq, Eq, Hash)]
13pub struct SuppressionKey<'a> {
14 pub key: ErrorKey,
15 pub message: Cow<'a, str>,
16}
17
18pub type Suppression = Vec<SuppressionLocation>;
19
20#[derive(Debug, Clone, PartialEq, Eq, Hash, Deserialize)]
21pub struct SuppressionLocation {
22 pub path: PathBuf,
23 pub line: Option<String>,
24 pub tag: Option<String>,
25}
26
27#[derive(Deserialize)]
29struct JsonReport {
30 key: ErrorKey,
31 message: String,
32 locations: Vec<SuppressionLocation>,
33}
34
35pub fn suppress_from_json(fullpath: &Path) -> Result<()> {
36 let reports: Vec<JsonReport> = serde_json::from_str(&read_to_string(fullpath)?)?;
37 let mut suppress: TigerHashMap<SuppressionKey, Vec<Suppression>> = TigerHashMap::default();
38 for JsonReport { key, message, locations } in reports {
39 suppress
40 .entry(SuppressionKey { key, message: Cow::Owned(message) })
41 .or_default()
42 .push(locations);
43 }
44 Errors::get_mut().suppress = suppress;
45 Ok(())
46}