Skip to main content

drft/rules/
mod.rs

1pub mod broken_link;
2pub mod containment;
3pub mod cycle;
4pub mod directory_link;
5pub mod encapsulation;
6pub mod fragility;
7pub mod fragmentation;
8pub mod indirect_link;
9pub mod layer_violation;
10pub mod orphan;
11pub mod redundant_edge;
12pub mod script;
13pub mod stale;
14
15use crate::config::Config;
16use crate::diagnostic::Diagnostic;
17use crate::graph::Graph;
18use crate::lockfile::Lockfile;
19use std::path::Path;
20
21/// Context passed to every rule, providing access to the graph,
22/// filesystem root, config, and optional lockfile.
23///
24/// See [`docs/rules`](../../docs/rules/README.md) for details.
25pub struct RuleContext<'a> {
26    pub graph: &'a Graph,
27    pub root: &'a Path,
28    pub config: &'a Config,
29    pub lockfile: Option<&'a Lockfile>,
30}
31
32pub trait Rule {
33    fn name(&self) -> &str;
34    fn evaluate(&self, ctx: &RuleContext) -> Vec<Diagnostic>;
35}
36
37pub fn all_rules() -> Vec<Box<dyn Rule>> {
38    vec![
39        Box::new(broken_link::BrokenLinkRule),
40        Box::new(containment::ContainmentRule),
41        Box::new(cycle::CycleRule),
42        Box::new(directory_link::DirectoryLinkRule),
43        Box::new(encapsulation::EncapsulationRule),
44        Box::new(fragility::FragilityRule),
45        Box::new(fragmentation::FragmentationRule),
46        Box::new(indirect_link::IndirectLinkRule),
47        Box::new(layer_violation::LayerViolationRule),
48        Box::new(orphan::OrphanRule),
49        Box::new(redundant_edge::RedundantEdgeRule),
50        Box::new(stale::StaleRule),
51    ]
52}