Skip to main content

drft/rules/
mod.rs

1pub mod boundary_violation;
2pub mod custom;
3pub mod dangling_edge;
4pub mod directed_cycle;
5pub mod encapsulation_violation;
6pub mod fragmentation;
7pub mod orphan_node;
8pub mod schema_violation;
9pub mod stale;
10pub mod symlink_edge;
11pub mod untrackable_target;
12
13use crate::analyses::EnrichedGraph;
14use crate::diagnostic::Diagnostic;
15
16/// Context passed to every rule. Rules are pure functions over the
17/// enriched graph — no filesystem access, no config, no lockfile.
18///
19/// See [`docs/rules`](../../docs/rules/README.md) for details.
20pub struct RuleContext<'a> {
21    pub graph: &'a EnrichedGraph,
22    /// Per-rule options from `[rules.<name>.options]`. drft passes through, rules interpret.
23    pub options: Option<&'a toml::Value>,
24}
25
26pub trait Rule {
27    fn name(&self) -> &str;
28    fn evaluate(&self, ctx: &RuleContext) -> Vec<Diagnostic>;
29}
30
31pub fn all_rules() -> Vec<Box<dyn Rule>> {
32    vec![
33        Box::new(boundary_violation::BoundaryViolationRule),
34        Box::new(dangling_edge::DanglingEdgeRule),
35        Box::new(directed_cycle::DirectedCycleRule),
36        Box::new(encapsulation_violation::EncapsulationViolationRule),
37        Box::new(fragmentation::FragmentationRule),
38        Box::new(orphan_node::OrphanNodeRule),
39        Box::new(schema_violation::SchemaViolationRule),
40        Box::new(stale::StaleRule),
41        Box::new(symlink_edge::SymlinkEdgeRule),
42        Box::new(untrackable_target::UntrackableTargetRule),
43    ]
44}