architecture_component!(Architecture);
use strum::{AsRefStr, Display, EnumString, VariantArray};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct ComponentDefinition {
pub component: ArchitectureComponent,
pub depends_on: &'static [ArchitectureComponent],
}
macro_rules! define_architecture {
($(
$(#[$meta:meta])*
$node:ident => [ $( $dep:ident ),* $(,)? ]
),* $(,)?) => {
#[derive(
Debug,
Clone,
Copy,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
Display,
EnumString,
AsRefStr,
VariantArray,
)]
pub enum ArchitectureComponent {
$(
$(#[$meta])*
$node,
)*
}
pub const ARCHITECTURE_GRAPH: &[ComponentDefinition] = &[
$(
ComponentDefinition {
component: ArchitectureComponent::$node,
depends_on: &[ $( ArchitectureComponent::$dep ),* ],
},
)*
];
const _: () = {
$(
$(
assert!(
(ArchitectureComponent::$dep as usize) < (ArchitectureComponent::$node as usize),
concat!(
"ArchitectureComponent::",
stringify!($node),
" cannot depend on ArchitectureComponent::",
stringify!($dep),
": dependencies must be declared before their dependents in define_architecture! to guarantee acyclicity",
),
);
)*
)*
};
};
}
define_architecture! {
Architecture => [],
Diagnostic => [],
Diff => [],
RuleDeclaration => [Diagnostic],
Config => [Diagnostic, RuleDeclaration],
CodeLintAst => [Diagnostic],
CodeLintSemantic => [CodeLintAst],
CodeLintContract => [CodeLintSemantic, CodeLintAst, RuleDeclaration],
CodeLintSuppression => [CodeLintContract, CodeLintSemantic, RuleDeclaration, Config],
CodeLintPolicy => [CodeLintAst],
CodeLintRules => [CodeLintContract, CodeLintPolicy, RuleDeclaration],
CodeLintRunner => [CodeLintRules, CodeLintSuppression, Diff],
CommandLintVcs => [],
CommandLintCommand => [],
CommandLintContract => [CommandLintCommand, CommandLintVcs, RuleDeclaration],
CommandLintRules => [CommandLintContract, RuleDeclaration],
CommandLintRunner => [CommandLintRules, Config],
RuleSelection => [RuleDeclaration, CodeLintRules, CodeLintSuppression, CommandLintRules, Config],
RuleCatalog => [RuleSelection, RuleDeclaration],
TestUtils => [CodeLintContract, CodeLintPolicy, CommandLintContract],
Bin => [CodeLintRunner, CommandLintRunner, RuleSelection, RuleCatalog],
}