Skip to main content

drft/rules/
mod.rs

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