Skip to main content

Rule

Trait Rule 

Source
pub trait Rule:
    Send
    + Sync
    + Debug {
    // Required methods
    fn id(&self) -> &str;
    fn level(&self) -> Level;
    fn evaluate(&self, ctx: &Context<'_>) -> Result<Vec<Violation>>;

    // Provided methods
    fn policy_url(&self) -> Option<&str> { ... }
    fn wants_git_tracked(&self) -> bool { ... }
    fn wants_git_blame(&self) -> bool { ... }
    fn requires_full_index(&self) -> bool { ... }
    fn path_scope(&self) -> Option<&Scope> { ... }
    fn fixer(&self) -> Option<&dyn Fixer> { ... }
}
Expand description

Trait every built-in and plugin rule implements.

Required Methods§

Source

fn id(&self) -> &str

Source

fn level(&self) -> Level

Source

fn evaluate(&self, ctx: &Context<'_>) -> Result<Vec<Violation>>

Provided Methods§

Source

fn policy_url(&self) -> Option<&str>

Source

fn wants_git_tracked(&self) -> bool

Whether this rule needs the git-tracked-paths set on Context. Default false; rule kinds that support git_tracked_only override to return true only when the user actually opted in. The engine collects the set (via git ls-files) once per run when ANY rule returns true, so the cost is paid at most once even if many rules opt in.

Source

fn wants_git_blame(&self) -> bool

Whether this rule needs git blame output on Context. Default false; the git_blame_age rule kind overrides to return true. The engine builds the shared crate::git::BlameCache once per run when any rule opts in, so multiple blame-aware rules over overlapping paths: re-use the parsed result.

Source

fn requires_full_index(&self) -> bool

In --changed mode, return true to evaluate this rule against the full FileIndex rather than the changed-only filtered subset. Default false (per-file semantics — the rule sees only changed files in scope).

Cross-file rules (pair, for_each_dir, every_matching_has, unique_by, dir_contains, dir_only_contains) override to true because their inputs span the whole tree by definition — a verdict on the changed file depends on what’s still in the rest of the tree. Existence rules (file_exists, file_absent, dir_exists, dir_absent) likewise consult the whole tree to answer “is X present?” correctly.

Source

fn path_scope(&self) -> Option<&Scope>

In --changed mode, return the Scope this rule is scoped to (typically the rule’s paths: field). The engine intersects the scope with the changed-set; rules whose scope doesn’t intersect are skipped, which is the optimisation --changed exists for.

Default None (“no scope information”) means the rule is always evaluated. Cross-file rules deliberately leave this as None (they always evaluate per the roadmap contract). Per-file rules with a single Scope field should override to return Some(&self.scope).

Source

fn fixer(&self) -> Option<&dyn Fixer>

Optional automatic-fix strategy. Rules whose violations can be mechanically corrected (e.g. creating a missing file, removing a forbidden one, renaming to the correct case) return a Fixer here; the default implementation reports the rule as unfixable.

Implementors§