fallow_config/config/flags.rs
1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3
4/// A custom SDK call pattern for feature flag detection.
5///
6/// Describes a function call that evaluates a feature flag, e.g.,
7/// `useFlag('new-checkout')` or `client.getFeatureValue('parser', false)`.
8#[derive(Debug, Clone, Deserialize, Serialize, JsonSchema)]
9#[serde(rename_all = "camelCase")]
10pub struct SdkPattern {
11 /// Function name to match (e.g., `"useFlag"`, `"variation"`).
12 pub function: String,
13 /// Zero-based index of the argument containing the flag name.
14 #[serde(default)]
15 pub name_arg: usize,
16 /// Optional SDK/provider label shown in output (e.g., `"LaunchDarkly"`).
17 #[serde(default, skip_serializing_if = "Option::is_none")]
18 pub provider: Option<String>,
19}
20
21/// Feature flag detection configuration.
22///
23/// Controls which patterns fallow uses to detect feature flags in source code.
24/// Configured via the `flags` section in `.fallowrc.json` or `fallow.toml`.
25///
26/// # Examples
27///
28/// ```json
29/// {
30/// "flags": {
31/// "sdkPatterns": [
32/// { "function": "useFlag", "nameArg": 0, "provider": "LaunchDarkly" }
33/// ],
34/// "envPrefixes": ["FEATURE_", "NEXT_PUBLIC_ENABLE_"],
35/// "configObjectHeuristics": false
36/// }
37/// }
38/// ```
39#[derive(Debug, Clone, Default, Deserialize, Serialize, JsonSchema)]
40#[serde(rename_all = "camelCase")]
41pub struct FlagsConfig {
42 /// Additional SDK call patterns to detect as feature flags.
43 /// These are merged with the built-in patterns (LaunchDarkly, Statsig, Unleash, GrowthBook).
44 #[serde(default, skip_serializing_if = "Vec::is_empty")]
45 pub sdk_patterns: Vec<SdkPattern>,
46
47 /// Environment variable prefixes that indicate feature flags.
48 /// Merged with built-in prefixes. Only `process.env.*` accesses matching
49 /// these prefixes are reported as feature flags.
50 #[serde(default, skip_serializing_if = "Vec::is_empty")]
51 pub env_prefixes: Vec<String>,
52
53 /// Enable config object heuristic detection.
54 /// When true, property accesses on objects whose name contains "feature",
55 /// "flag", or "toggle" are reported as low-confidence feature flags.
56 /// Default: false (opt-in due to higher false positive rate).
57 #[serde(default)]
58 pub config_object_heuristics: bool,
59}