Skip to main content

Check

Trait Check 

Source
pub trait Check: Sync {
    // Required methods
    fn name(&self) -> &str;
    fn stage(&self) -> Stage;
    fn scope(&self) -> Scope;
    fn severity(&self) -> Severity;
    fn run(&self, ctx: &Ctx<'_>) -> Outcome;

    // Provided methods
    fn pairing_name(&self) -> &str { ... }
    fn fix(&self) -> Fix { ... }
    fn reach(&self) -> Reach { ... }
    fn weight(&self) -> Weight { ... }
    fn would_judge(&self, staged: &[String], tracked: Option<&[String]>) -> bool { ... }
}
Expand description

One check, whether compiled in or declared by the repository.

Sync because pre-commit hands every check to its own thread. Both implementations satisfy it for free, and requiring it here is what lets the dispatcher hold &'static dyn Check without caring which kind it has.

Required Methods§

Source

fn name(&self) -> &str

Source

fn stage(&self) -> Stage

Source

fn scope(&self) -> Scope

Source

fn severity(&self) -> Severity

Source

fn run(&self, ctx: &Ctx<'_>) -> Outcome

Provided Methods§

Source

fn pairing_name(&self) -> &str

The name a commit-time declaration must use to pair with this gate.

Deliberately the SHORT name, and deliberately not the id: pairing is cross-stage by definition — test declared at pre-commit pairs with test at pre-push — so the id, which encodes the stage, is the one key that cannot work. pre-push-cargo-test would be compared against a GateDecl.script of cargo-test and never match, and the failure would be silence rather than an error: the gate simply never pairs and nobody is told why.

This is the single place where comparing short names is correct, which is why it is a named method rather than a short_name() call at the comparison site — that function’s own documentation says never to compare against it, and it is right everywhere else.

Source

fn fix(&self) -> Fix

Whether this check can repair what it finds. None for almost all.

Source

fn reach(&self) -> Reach

How far the check reaches when amont.conventions is declared — see Reach. Externals default to Convention, which costs them nothing: a declared check only exists where an amont.conf does, and that is exactly the declaration the mode asks for.

Source

fn weight(&self) -> Weight

Whether the check takes a host slot (ADR-0009, ADR-0013). Built-ins are Heavy by name; a declared check answers for itself.

Source

fn would_judge(&self, staged: &[String], tracked: Option<&[String]>) -> bool

Would this check judge something for this change, were it run? The change touches its scope and the repository opted in: the two questions every scoped check asks before it does anything. A Heavy check the pre-commit waves hold back is Skipped when this says yes and Inert when it says no (ADR-0020). tracked: None (git would not list the index) answers yes: a skip is said, never hidden.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§