Skip to main content

exspec_core/
hints.rs

1use serde::Serialize;
2
3use crate::rules::{Diagnostic, RuleId, Severity};
4
5const T001_HINT_THRESHOLD: usize = 10;
6
7#[derive(Debug, Clone, PartialEq, Eq, Serialize)]
8pub struct Hint {
9    pub rule: RuleId,
10    pub title: String,
11    pub message: String,
12}
13
14pub fn compute_hints(diagnostics: &[Diagnostic], custom_patterns_empty: bool) -> Vec<Hint> {
15    if !custom_patterns_empty {
16        return Vec::new();
17    }
18
19    let t001_block_count = diagnostics
20        .iter()
21        .filter(|d| d.rule.0 == "T001" && d.severity == Severity::Block)
22        .count();
23
24    if t001_block_count < T001_HINT_THRESHOLD {
25        return Vec::new();
26    }
27
28    vec![Hint {
29        rule: RuleId::new("T001"),
30        title: "Assertion helper patterns may be missing".to_string(),
31        message:
32            "Add `[assertions] custom_patterns = [\"my_helper\"]` to `.exspec.toml` when your tests assert through helper functions."
33                .to_string(),
34    }]
35}