use std::collections::BTreeMap;
use std::sync::{Arc, LazyLock};
use serde::Deserialize;
use super::gate::GateConfig;
use super::naming::{NamingCheck, NamingOverride};
use super::pattern::{PatternCheck, PatternOverride};
use super::string_list::deserialize_arc_str_slice;
#[derive(Debug, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct ItemVisibilityRule {
pub path: Box<str>,
pub kind: Box<str>,
pub name: Box<str>,
pub visibility: Box<str>,
}
#[derive(Debug, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct FeatureBoundaryRule {
pub package: Box<str>,
pub feature: Box<str>,
pub rule: Box<str>,
}
#[derive(Debug, Deserialize, Clone)]
#[serde(deny_unknown_fields)]
pub struct FlatModuleFamily {
pub parent: Box<str>,
pub package_root: Box<str>,
pub prefix: Box<str>,
}
#[derive(Debug, Deserialize, Default)]
#[serde(deny_unknown_fields)]
pub struct ConfigFile {
#[serde(default)]
pub gate: GateConfig,
#[serde(default = "default_max_depth")]
pub max_depth: usize,
#[serde(default = "default_else_chain_threshold")]
pub else_chain_threshold: usize,
#[serde(default = "default_max_params")]
pub max_params: usize,
#[serde(default = "default_max_function_body_lines")]
pub max_function_body_lines: usize,
#[serde(
default = "default_module_root_files",
deserialize_with = "deserialize_arc_str_slice"
)]
pub module_root_files: Arc<[Arc<str>]>,
#[serde(default = "default_source_file_warn_lines")]
pub source_file_warn_lines: usize,
#[serde(default = "default_source_file_deny_lines")]
pub source_file_deny_lines: usize,
#[serde(default = "default_max_methods")]
pub max_methods: usize,
#[serde(default)]
pub forbid_attributes: PatternCheck,
#[serde(default)]
pub forbid_types: PatternCheck,
#[serde(default)]
pub forbid_calls: PatternCheck,
#[serde(default)]
pub forbid_macros: PatternCheck,
#[serde(default)]
pub check_naming: NamingCheck,
#[serde(default = "default_true")]
pub check_nested_if: bool,
#[serde(default = "default_true")]
pub check_if_in_match: bool,
#[serde(default = "default_true")]
pub check_nested_match: bool,
#[serde(default = "default_true")]
pub check_match_in_if: bool,
#[serde(default = "default_true")]
pub check_else_chain: bool,
#[serde(default)]
pub forbid_else: bool,
#[serde(default = "default_true")]
pub forbid_unsafe: bool,
#[serde(default)]
pub check_dyn_return: bool,
#[serde(default)]
pub check_dyn_param: bool,
#[serde(default)]
pub check_vec_box_dyn: bool,
#[serde(default)]
pub check_dyn_field: bool,
#[serde(default)]
pub check_clone_in_loop: bool,
#[serde(default)]
pub check_default_hasher: bool,
#[serde(default)]
pub check_mixed_concerns: bool,
#[serde(default)]
pub check_inline_tests: bool,
#[serde(default)]
pub check_let_underscore_result: bool,
#[serde(default)]
pub check_high_param_count: bool,
#[serde(default)]
pub check_long_function_body: bool,
#[serde(default)]
pub check_module_root_definitions: bool,
#[serde(default)]
pub check_large_source_file: bool,
#[serde(default)]
pub check_high_method_count: bool,
#[serde(default)]
pub count_forwarders: bool,
#[serde(default = "default_true")]
pub check_item_visibility_policy: bool,
#[serde(default)]
pub item_visibility_policy: Vec<ItemVisibilityRule>,
#[serde(default)]
pub check_ungated_test_api: bool,
#[serde(default)]
pub check_conflicting_module_root: bool,
#[serde(
default = "default_test_api_patterns",
deserialize_with = "deserialize_arc_str_slice"
)]
pub test_api_patterns: Arc<[Arc<str>]>,
#[serde(default = "default_test_support_feature")]
pub test_support_feature: Box<str>,
#[serde(default = "default_true")]
pub check_flat_module_family: bool,
#[serde(default)]
pub flat_module_families: Vec<FlatModuleFamily>,
#[serde(default = "default_true")]
pub check_feature_boundary: bool,
#[serde(default)]
pub feature_boundaries: Vec<FeatureBoundaryRule>,
#[serde(default)]
pub check_scattered_inherent_impl: bool,
#[serde(default)]
pub overrides: BTreeMap<Box<str>, PathOverride>,
}
#[derive(Debug, Deserialize, Default)]
#[serde(deny_unknown_fields)]
pub struct PathOverride {
pub enabled: Option<bool>,
pub max_depth: Option<usize>,
pub max_params: Option<usize>,
pub max_function_body_lines: Option<usize>,
pub source_file_warn_lines: Option<usize>,
pub source_file_deny_lines: Option<usize>,
pub max_methods: Option<usize>,
pub forbid_attributes: Option<PatternOverride>,
pub forbid_types: Option<PatternOverride>,
pub forbid_calls: Option<PatternOverride>,
pub forbid_macros: Option<PatternOverride>,
pub check_naming: Option<NamingOverride>,
pub check_nested_if: Option<bool>,
pub check_if_in_match: Option<bool>,
pub check_nested_match: Option<bool>,
pub check_match_in_if: Option<bool>,
pub check_else_chain: Option<bool>,
pub forbid_else: Option<bool>,
pub forbid_unsafe: Option<bool>,
pub check_dyn_return: Option<bool>,
pub check_dyn_param: Option<bool>,
pub check_vec_box_dyn: Option<bool>,
pub check_dyn_field: Option<bool>,
pub check_clone_in_loop: Option<bool>,
pub check_default_hasher: Option<bool>,
pub check_mixed_concerns: Option<bool>,
pub check_inline_tests: Option<bool>,
pub check_let_underscore_result: Option<bool>,
pub check_high_param_count: Option<bool>,
pub check_long_function_body: Option<bool>,
pub check_module_root_definitions: Option<bool>,
pub check_large_source_file: Option<bool>,
pub check_high_method_count: Option<bool>,
pub count_forwarders: Option<bool>,
pub check_item_visibility_policy: Option<bool>,
pub check_ungated_test_api: Option<bool>,
pub check_conflicting_module_root: Option<bool>,
pub check_flat_module_family: Option<bool>,
pub check_feature_boundary: Option<bool>,
pub check_scattered_inherent_impl: Option<bool>,
}
pub(super) fn default_max_depth() -> usize {
3
}
pub(super) fn default_else_chain_threshold() -> usize {
3
}
pub(super) fn default_max_params() -> usize {
5
}
pub(super) fn default_max_function_body_lines() -> usize {
120
}
static MODULE_ROOT_FILES_ARC: LazyLock<Arc<[Arc<str>]>> =
LazyLock::new(|| [Arc::from("mod.rs"), Arc::from("lib.rs")].into());
pub(super) fn default_module_root_files() -> Arc<[Arc<str>]> {
Arc::clone(&MODULE_ROOT_FILES_ARC)
}
pub(super) fn default_source_file_warn_lines() -> usize {
500
}
pub(super) fn default_source_file_deny_lines() -> usize {
1000
}
pub(super) fn default_max_methods() -> usize {
40
}
static TEST_API_PATTERNS_ARC: LazyLock<Arc<[Arc<str>]>> =
LazyLock::new(|| [Arc::from("*_for_tests")].into());
pub(super) fn default_test_api_patterns() -> Arc<[Arc<str>]> {
Arc::clone(&TEST_API_PATTERNS_ARC)
}
pub(super) fn default_test_support_feature() -> Box<str> {
"test-support".into()
}
fn default_true() -> bool {
true
}