use crate::diagnostic::Language;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Reference {
pub title: &'static str,
pub url: &'static str,
}
impl Reference {
pub const NAME_RESOLUTION: Self = Self {
title: "How Omni resolves names",
url: "https://github.com/Kajiih/omnicoach/blob/main/docs/name_resolution.md",
};
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Example {
pub language: Language,
pub flagged: &'static str,
pub flagged_span: &'static str,
pub fixed: &'static str,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct RuleDoc {
pub summary: &'static str,
pub what_it_does: &'static str,
pub why_is_this_bad: &'static str,
pub known_problems: Option<&'static str>,
pub references: &'static [Reference],
pub examples: &'static [Example],
}
impl RuleDoc {
pub const TODO: Self = Self {
summary: "Documentation pending.",
what_it_does: "Documentation pending.",
why_is_this_bad: "Documentation pending.",
known_problems: None,
references: &[],
examples: &[],
};
#[must_use]
pub fn is_placeholder(&self) -> bool {
*self == Self::TODO
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn name_resolution_reference_points_at_a_repository_file() {
let (_, path) = Reference::NAME_RESOLUTION
.url
.split_once("/blob/main/")
.expect("the URL must point into the repository's `main` branch");
assert!(
std::path::Path::new(env!("CARGO_MANIFEST_DIR"))
.join(path)
.is_file(),
"`{path}` does not exist"
);
}
}