repotoire 0.7.1

Graph-powered code analysis CLI. 110 detectors for security, architecture, bus factor, and code quality.
Documentation
//! Declarative macros that consolidate constructor boilerplate for
//! architecture detectors.
//!
//! Most architecture detectors share three near-identical constructors:
//!   - `pub fn new() -> Self` — defaults
//!   - `pub fn with_config(DetectorConfig) -> Self` — reads thresholds via
//!     `config.get_option_or(key, default)`
//!   - `impl Default for X { fn default() -> Self { Self::new() } }`
//!
//! The [`detector_constructors!`] macro generates all three from a single
//! declarative invocation. Detectors retain their own struct definitions so
//! that field types remain explicit at use sites (e.g., inside the `Detector`
//! trait impl).
//!
//! # Examples
//!
//! Config-only detector:
//!
//! ```ignore
//! pub struct ShotgunSurgeryDetector { config: DetectorConfig }
//!
//! detector_constructors! {
//!     ShotgunSurgeryDetector { }
//! }
//! ```
//!
//! Detector with one or more numeric threshold fields:
//!
//! ```ignore
//! pub struct MutualRecursionDetector {
//!     config: DetectorConfig,
//!     max_cycle_size: usize,
//! }
//!
//! detector_constructors! {
//!     MutualRecursionDetector {
//!         max_cycle_size: usize = config_opt("max_cycle_size", 50),
//!     }
//! }
//! ```
//!
//! Detectors with bespoke construction logic (e.g., calibrate-aware
//! multipliers in `architectural_bottleneck.rs` and `degree_centrality.rs`)
//! intentionally do not use this macro.

/// Generate `new()`, `with_config(DetectorConfig)`, and `Default` for an
/// architecture detector with a `config` field plus zero or more numeric
/// threshold fields, each backed by a config option.
///
/// See the module docs for usage.
macro_rules! detector_constructors {
    (
        $name:ident {
            $( $field:ident : $ty:ty = config_opt( $key:expr, $default:expr ) ),* $(,)?
        }
    ) => {
        impl $name {
            /// Create with default config.
            pub fn new() -> Self {
                Self {
                    config: $crate::detectors::base::DetectorConfig::new(),
                    $( $field: $default, )*
                }
            }

            /// Create with custom config.
            #[allow(dead_code)]
            pub fn with_config(
                config: $crate::detectors::base::DetectorConfig,
            ) -> Self {
                $( let $field = config.get_option_or($key, $default); )*
                Self {
                    config,
                    $( $field, )*
                }
            }
        }

        impl Default for $name {
            fn default() -> Self {
                Self::new()
            }
        }
    };
}

pub(crate) use detector_constructors;