Expand description
directiva — a tiny, paste-friendly directive mini-language.
One directive fits on one line, in a CLI flag, in a CI config, or in a code comment:
ACTION : [<KIND>] NAME [@PATH] [=NOTE]Each field carries its own sigil (: <> @ =), so parsing is an unambiguous,
context-free cascade — no grammar file, no dependencies. The crate knows nothing about any
specific domain: you bring a Target (the thing a directive matches against) and an
Action vocabulary; directiva brings the parser, the glob matcher, the
matching rules, and the severity Ladder algebra.
§The shape
- ACTION — required. An opaque token; the crate ships no built-in actions. A caller
resolves it to its own
AviaAction::from_token; the defaultA = Stringaccepts any token (open set, e.g. plain markup). <KIND>— optional category filter, angle-bracketed so it never collides with the[...]glob char-class.<*>or omitted = any kind. Exact match againstTarget::qualifier.- NAME — required, non-empty. A glob (
Pattern) matched against the target’s names. @PATH— optional. A glob matched against the target’s scopes.=NOTE— optional. Free text — the why — that travels with the rule.
§Example
use directiva::{parse, Target, Pattern};
struct Item { kind: &'static str, name: &'static str, file: &'static str }
impl Target for Item {
fn qualifier(&self) -> Option<&str> { Some(self.kind) }
fn matches_name(&self, p: &Pattern) -> bool { p.matches(self.name) }
fn matches_scope(&self, p: &Pattern) -> bool { p.matches(self.file) }
}
let d = parse("de-escalate:<function>get_*@*/tests/*=test fixtures").unwrap();
assert_eq!(d.action, "de-escalate"); // open-set String default
let hit = Item { kind: "function", name: "get_user", file: "src/tests/api.rs" };
let miss = Item { kind: "function", name: "get_user", file: "src/api.rs" };
assert!(d.matches(&hit));
assert!(!d.matches(&miss)); // @PATH glob doesn't matchRe-exports§
pub use crate::core::parse;pub use crate::core::parse_as;pub use crate::core::Action;pub use crate::core::Directive;pub use crate::core::Ladder;pub use crate::core::ParseError;pub use crate::core::Pattern;pub use crate::core::Target;
Modules§
- core
- The domain-agnostic engine: glob matching, directive types, the parser, the
Targettrait, and the decoupled severityLadder. Always available; knows nothing about any domain. - lint
- A ready-made “batteries” pack for the classic lint use case: a concrete
LintActionvocabulary (suppress / de-escalate / escalate / note / set), aSeverityladder, and afoldcombine policy. - source
- Ingestion: turn
-Dflag values (inline directives or@filereferences) and directive files into parsed directives, tagged with where they came from. Pure concatenation, no dedup — duplicates are the caller’s responsibility.