use std::path::Path;
use crate::project::{ResolvedCitations, ResolvedLabels};
use crate::semantic::SemanticModel;
use crate::syntax::{SyntaxElement, SyntaxKind, SyntaxNode};
use super::diagnostic::{Diagnostic, Severity};
pub mod deprecated_command;
pub mod dollar_display_math;
pub mod duplicate_label;
pub mod mismatched_delimiter;
pub mod obsolete_environment;
pub mod undefined_citation;
pub mod undefined_ref;
pub use deprecated_command::DeprecatedCommand;
pub use dollar_display_math::DollarDisplayMath;
pub use duplicate_label::DuplicateLabel;
pub use mismatched_delimiter::MismatchedDelimiter;
pub use obsolete_environment::ObsoleteEnvironment;
pub use undefined_citation::UndefinedCitation;
pub use undefined_ref::UndefinedRef;
pub struct RuleContext<'a> {
pub path: &'a Path,
pub root: &'a SyntaxNode,
pub model: &'a SemanticModel,
pub resolution: Option<&'a ResolvedLabels>,
pub citations: Option<&'a ResolvedCitations>,
}
pub trait Rule: Send + Sync {
fn id(&self) -> &'static str;
fn default_severity(&self) -> Severity {
Severity::Warning
}
fn interests(&self) -> &'static [SyntaxKind] {
&[]
}
fn check(&self, el: &SyntaxElement, ctx: &RuleContext<'_>, sink: &mut Vec<Diagnostic>) {
let _ = (el, ctx, sink);
}
fn check_file(&self, ctx: &RuleContext<'_>, sink: &mut Vec<Diagnostic>) {
let _ = (ctx, sink);
}
}
pub fn all_rules() -> Vec<Box<dyn Rule>> {
vec![
Box::new(DuplicateLabel),
Box::new(DeprecatedCommand),
Box::new(ObsoleteEnvironment),
Box::new(DollarDisplayMath),
Box::new(MismatchedDelimiter),
Box::new(UndefinedRef),
Box::new(UndefinedCitation),
]
}
pub const ALL_RULE_IDS: &[&str] = &[
"duplicate-label",
"deprecated-command",
"obsolete-environment",
"dollar-display-math",
"mismatched-delimiter",
"undefined-ref",
"undefined-citation",
];
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn registry_and_id_list_agree() {
let ids: Vec<&str> = all_rules().iter().map(|r| r.id()).collect();
assert_eq!(ids, ALL_RULE_IDS);
}
}