cartulary 0.3.0-alpha.1

The knowledge layer of your project — decisions, issues, docs, all in one place.
Documentation
//! One finding produced by an issue rule: the violation to report
//! plus, when the repair is well-defined, the atomic edit that
//! resolves it. Pure data — the rule trait that produces these lives
//! in `domain/usecases/check/`.

use crate::domain::model::check::CheckViolation;
use crate::domain::model::issue::IssueEdit;

#[derive(Debug, Clone, PartialEq, Eq)]
pub struct IssueFinding {
    pub violation: CheckViolation,
    pub fix: Option<IssueEdit>,
}

impl IssueFinding {
    /// Wrap a `CheckViolation` as a finding with no auto-fix. Used by
    /// non-fixable rules to feed the `find()` return shape.
    pub fn report(violation: CheckViolation) -> Self {
        Self {
            violation,
            fix: None,
        }
    }
}

#[cfg(test)]
pub mod strategy {
    use super::IssueFinding;
    use crate::domain::model::check::check_violation::strategy::check_violation;
    use crate::domain::model::issue::edit::strategy::issue_edit;
    use proptest::prelude::*;

    prop_compose! {
        pub fn issue_finding()(
            violation in check_violation(),
            fix in proptest::option::of(issue_edit()),
        ) -> IssueFinding {
            IssueFinding { violation, fix }
        }
    }
}

#[cfg(test)]
mod tests {
    use super::*;
    use proptest::prelude::*;

    proptest! {
        #[test]
        fn report_carries_no_fix(v in crate::domain::model::check::check_violation::strategy::check_violation()) {
            prop_assert!(IssueFinding::report(v).fix.is_none());
        }
    }
}