mod diagnostics;
mod rules;
#[cfg(test)]
mod tests;
pub use diagnostics::{Diagnostic, FuseBlown};
pub use rules::{GhostNetRule, MalformedElementRule, UnconnectedNetRule};
use crate::parser::Circuit;
pub trait Rule {
fn name(&self) -> &'static str;
fn check(&self, circuit: &Circuit) -> Vec<Diagnostic>;
}
pub struct Linter {
rules: Vec<Box<dyn Rule>>,
}
impl Linter {
pub fn new() -> Self {
Self { rules: Vec::new() }
}
pub fn with_rule(mut self, rule: impl Rule + 'static) -> Self {
self.rules.push(Box::new(rule));
self
}
pub fn run(&self, circuit: &Circuit) -> Vec<Diagnostic> {
self.rules
.iter()
.flat_map(|rule| rule.check(circuit))
.collect()
}
}
impl Default for Linter {
fn default() -> Self {
Self::new()
.with_rule(UnconnectedNetRule)
.with_rule(MalformedElementRule)
.with_rule(GhostNetRule)
}
}