Skip to main content

ailint_core/rules/structural/
empty_file.rs

1//! AIL002 `instructions-file-empty` — file is empty or whitespace only.
2//!
3//! See: `docs/rules/structural/AIL002.md`
4
5use crate::parser::ParsedDocument;
6use crate::rules::structural::AIL002;
7use crate::rules::{Rule, RuleContext, RuleId, Severity, Violation};
8
9/// AIL002 instructions-file-empty: guidance file has no content.
10#[derive(Debug, Default)]
11pub struct EmptyFileRule;
12
13impl Rule for EmptyFileRule {
14    fn id(&self) -> RuleId {
15        AIL002
16    }
17
18    fn default_severity(&self) -> Severity {
19        Severity::Warning
20    }
21
22    fn run(&self, doc: &ParsedDocument, _ctx: &RuleContext<'_>) -> Vec<Violation> {
23        if !doc.raw.trim().is_empty() {
24            return Vec::new();
25        }
26        vec![Violation::new(
27            AIL002,
28            self.default_severity(),
29            doc.path.clone(),
30            "file is empty or contains only whitespace",
31        )
32        .at(1, 1)]
33    }
34}