Skip to main content

dk_runner/steps/semantic/
checks.rs

1use dk_core::types::{CallEdge, Dependency, Symbol};
2
3use crate::findings::Finding;
4
5/// A file that has changed in the current changeset.
6#[derive(Debug, Clone)]
7pub struct ChangedFile {
8    /// Relative path within the repository.
9    pub path: String,
10    /// File content after the change (None if the file was deleted).
11    pub content: Option<String>,
12}
13
14/// Contextual data gathered from the Engine's graph stores and the changeset,
15/// providing both before (DB) and after (parsed) snapshots for comparison.
16pub struct CheckContext {
17    /// Symbols from the database for the changed files (before state).
18    pub before_symbols: Vec<Symbol>,
19    /// Symbols parsed from the materialized changeset files (after state).
20    pub after_symbols: Vec<Symbol>,
21    /// Call graph edges from the database (before state).
22    pub before_call_graph: Vec<CallEdge>,
23    /// Call graph edges derived from the parsed changeset (after state).
24    pub after_call_graph: Vec<CallEdge>,
25    /// Dependencies from the database (before state).
26    pub before_deps: Vec<Dependency>,
27    /// Dependencies from the changeset (after state — currently mirrors before).
28    pub after_deps: Vec<Dependency>,
29    /// The set of files that changed.
30    pub changed_files: Vec<ChangedFile>,
31}
32
33/// Trait that every semantic check must implement.
34///
35/// Checks are stateless: all mutable context is supplied via `CheckContext`.
36pub trait SemanticCheck: Send + Sync {
37    /// A unique, kebab-case name for the check (e.g. "no-unsafe-added").
38    fn name(&self) -> &str;
39
40    /// Execute the check against the provided context and return any findings.
41    fn run(&self, ctx: &CheckContext) -> Vec<Finding>;
42}