Skip to main content

ktrs_compose/ktlint/
composable_nesting_depth_check.rs

1//! Port of `ktlint/ComposableNestingDepthCheck.kt`: opt-in through `compose_composable_nesting_depth_enabled`.
2
3use ktrs_ast::Ast;
4use ktrs_ast::psi::KtFunction;
5
6use crate::core::compose_kt_config::ComposeKtConfig;
7use crate::core::compose_kt_visitor::ComposeKtVisitor;
8use crate::core::emitter::Emitter;
9use crate::ktlint::editor_config_properties::{
10    COMPOSABLE_NESTING_DEPTH_ENABLED, COMPOSABLE_NESTING_DEPTH_THRESHOLD, CONTENT_EMITTERS_DENYLIST,
11    CONTENT_EMITTERS_PROPERTY, ComposeProperty,
12};
13use crate::ktlint::ktlint_rule::KtlintRule;
14use crate::rules::composable_nesting_depth::ComposableNestingDepth;
15
16pub struct ComposableNestingDepthCheck {
17    visitor: ComposableNestingDepth,
18}
19
20impl ComposeKtVisitor for ComposableNestingDepthCheck {
21    fn visit_composable(&self, ast: &mut Ast, function: KtFunction, emitter: &mut dyn Emitter, config: &dyn ComposeKtConfig) {
22        if config.get_boolean("composableNestingDepthEnabled", false) {
23            self.visitor.visit_composable(ast, function, emitter, config);
24        }
25    }
26}
27
28pub const CHECK: Option<fn() -> KtlintRule> = Some(composable_nesting_depth_check);
29
30pub fn composable_nesting_depth_check() -> KtlintRule {
31    KtlintRule::new(
32        "compose:composable-nesting-depth-check",
33        vec![
34            ComposeProperty::Boolean(&COMPOSABLE_NESTING_DEPTH_ENABLED),
35            ComposeProperty::Int(&COMPOSABLE_NESTING_DEPTH_THRESHOLD),
36            ComposeProperty::String(&CONTENT_EMITTERS_PROPERTY),
37            ComposeProperty::String(&CONTENT_EMITTERS_DENYLIST),
38        ],
39        Box::new(ComposableNestingDepthCheck { visitor: ComposableNestingDepth }),
40    )
41}