Skip to main content

mago_analyzer/plugin/hook/
filter.rs

1//! Issue filter hook for suppressing issues at the end of analysis.
2
3use mago_database::file::File;
4use mago_reporting::Issue;
5
6use crate::plugin::hook::HookResult;
7use crate::plugin::provider::Provider;
8
9/// Decision for an issue filter.
10#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
11pub enum IssueFilterDecision {
12    /// Keep the issue (include in output).
13    #[default]
14    Keep,
15    /// Remove the issue (suppress from output).
16    Remove,
17}
18
19/// Hook for filtering issues at the end of analysis.
20///
21/// Called for each issue after analysis is complete.
22/// This allows plugins to suppress issues based on various criteria:
23///
24/// - Suppress "unused parameter" for methods with `#[Override]`
25/// - Suppress issues in generated code
26/// - Framework-specific suppression rules
27pub trait IssueFilterHook: Provider {
28    /// Filter an issue.
29    ///
30    /// Called for each issue after analysis is complete.
31    /// The issue contains the code as a string in `issue.code`.
32    /// Return `IssueFilterDecision::Keep` to keep it,
33    /// `IssueFilterDecision::Remove` to suppress it.
34    fn filter_issue(&self, file: &File, issue: &Issue) -> HookResult<IssueFilterDecision>;
35}