dart-decimate 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (188) hide show
  1. package/Cargo.lock +572 -0
  2. package/Cargo.toml +41 -0
  3. package/LICENSE +21 -0
  4. package/README.md +617 -0
  5. package/assets/dart-decimate-banner.png +0 -0
  6. package/npm/bin/dart-decimate-mcp.js +48 -0
  7. package/npm/bin/dart-decimate.js +48 -0
  8. package/npm/scripts/postinstall.js +46 -0
  9. package/npm/scripts/test-npx-local.js +54 -0
  10. package/npm/scripts/test-npx-mcp-local.js +56 -0
  11. package/package.json +45 -0
  12. package/src/baseline.rs +643 -0
  13. package/src/bin/dart-decimate-mcp.rs +11 -0
  14. package/src/boundaries/tests.rs +60 -0
  15. package/src/boundaries.rs +317 -0
  16. package/src/changed_scope.rs +117 -0
  17. package/src/ci_template.rs +399 -0
  18. package/src/cli/analyze.rs +462 -0
  19. package/src/cli/analyzer_options.rs +82 -0
  20. package/src/cli/audit_run.rs +327 -0
  21. package/src/cli/boundary_args.rs +44 -0
  22. package/src/cli/ci_template_run.rs +196 -0
  23. package/src/cli/command_name.rs +20 -0
  24. package/src/cli/common_args.rs +167 -0
  25. package/src/cli/config_run.rs +78 -0
  26. package/src/cli/coverage_run.rs +393 -0
  27. package/src/cli/decision_surface_run.rs +99 -0
  28. package/src/cli/default_command.rs +69 -0
  29. package/src/cli/dupes_args.rs +150 -0
  30. package/src/cli/entry_points.rs +121 -0
  31. package/src/cli/error.rs +149 -0
  32. package/src/cli/error_output.rs +68 -0
  33. package/src/cli/explain_run.rs +72 -0
  34. package/src/cli/fix_run.rs +162 -0
  35. package/src/cli/flags_args.rs +23 -0
  36. package/src/cli/health_args.rs +200 -0
  37. package/src/cli/hooks_run.rs +191 -0
  38. package/src/cli/impact_run.rs +95 -0
  39. package/src/cli/init_run.rs +49 -0
  40. package/src/cli/inspect_args.rs +20 -0
  41. package/src/cli/inspect_run.rs +66 -0
  42. package/src/cli/issue_filter_args.rs +240 -0
  43. package/src/cli/list_run.rs +311 -0
  44. package/src/cli/mode_args.rs +72 -0
  45. package/src/cli/output_format.rs +62 -0
  46. package/src/cli/regression_args.rs +156 -0
  47. package/src/cli/request_args.rs +175 -0
  48. package/src/cli/schema_commands.rs +72 -0
  49. package/src/cli/scope_args.rs +174 -0
  50. package/src/cli/security_args.rs +175 -0
  51. package/src/cli/security_gate_run.rs +66 -0
  52. package/src/cli/security_summary_run.rs +43 -0
  53. package/src/cli/summary_args.rs +12 -0
  54. package/src/cli/tests.rs +516 -0
  55. package/src/cli/trace_args.rs +67 -0
  56. package/src/cli/trace_run.rs +131 -0
  57. package/src/cli/trace_tests.rs +235 -0
  58. package/src/cli/unsupported_run.rs +116 -0
  59. package/src/cli/watch_run.rs +153 -0
  60. package/src/cli.rs +603 -0
  61. package/src/config/boundary_config.rs +235 -0
  62. package/src/config/cache.rs +25 -0
  63. package/src/config/dependencies.rs +114 -0
  64. package/src/config/health.rs +237 -0
  65. package/src/config/jsonc.rs +66 -0
  66. package/src/config/policy.rs +91 -0
  67. package/src/config/rule_aliases.rs +487 -0
  68. package/src/config/rules.rs +339 -0
  69. package/src/config.rs +635 -0
  70. package/src/coverage.rs +469 -0
  71. package/src/dart_parser.rs +673 -0
  72. package/src/decision_surface.rs +405 -0
  73. package/src/dependencies/analyze.rs +218 -0
  74. package/src/dependencies/codegen.rs +118 -0
  75. package/src/dependencies/discovery.rs +60 -0
  76. package/src/dependencies/overrides.rs +76 -0
  77. package/src/dependencies/private_src_imports.rs +32 -0
  78. package/src/dependencies/pubspec_document.rs +86 -0
  79. package/src/dependencies/pubspec_entry.rs +96 -0
  80. package/src/dependencies/tests.rs +544 -0
  81. package/src/dependencies/usage.rs +33 -0
  82. package/src/dependencies.rs +553 -0
  83. package/src/dependency_scripts.rs +91 -0
  84. package/src/dupes/lex.rs +236 -0
  85. package/src/dupes/tests.rs +119 -0
  86. package/src/dupes.rs +625 -0
  87. package/src/explain.rs +692 -0
  88. package/src/extract/directives.rs +252 -0
  89. package/src/extract/error_tests.rs +25 -0
  90. package/src/extract/members.rs +210 -0
  91. package/src/extract/primary_constructors.rs +421 -0
  92. package/src/extract/references.rs +151 -0
  93. package/src/extract/routes.rs +691 -0
  94. package/src/extract/signatures.rs +266 -0
  95. package/src/extract/string_tests.rs +18 -0
  96. package/src/extract/strings.rs +107 -0
  97. package/src/extract/tests.rs +697 -0
  98. package/src/extract.rs +680 -0
  99. package/src/feature_flags/tests.rs +76 -0
  100. package/src/feature_flags.rs +453 -0
  101. package/src/finding_identity.rs +60 -0
  102. package/src/fix.rs +551 -0
  103. package/src/generated.rs +53 -0
  104. package/src/graph/augment_tests.rs +212 -0
  105. package/src/graph/conditionals.rs +74 -0
  106. package/src/graph/package_config_tests.rs +100 -0
  107. package/src/graph/parts.rs +248 -0
  108. package/src/graph/pubspec_tests.rs +119 -0
  109. package/src/graph/tests.rs +837 -0
  110. package/src/graph/uri_tests.rs +102 -0
  111. package/src/graph.rs +644 -0
  112. package/src/health/coverage.rs +309 -0
  113. package/src/health/ownership.rs +175 -0
  114. package/src/health/runtime_coverage.rs +616 -0
  115. package/src/health/runtime_intelligence.rs +511 -0
  116. package/src/health/scores.rs +296 -0
  117. package/src/health/tests.rs +240 -0
  118. package/src/health/threshold_types.rs +163 -0
  119. package/src/health/thresholds.rs +229 -0
  120. package/src/health/types.rs +636 -0
  121. package/src/health.rs +597 -0
  122. package/src/hooks/agent_settings.rs +175 -0
  123. package/src/hooks/templates.rs +51 -0
  124. package/src/hooks.rs +569 -0
  125. package/src/impact.rs +287 -0
  126. package/src/init.rs +237 -0
  127. package/src/inspect.rs +142 -0
  128. package/src/intelligence/tests.rs +232 -0
  129. package/src/intelligence.rs +305 -0
  130. package/src/lib.rs +198 -0
  131. package/src/main.rs +5 -0
  132. package/src/manifest/mcp.rs +565 -0
  133. package/src/manifest.rs +552 -0
  134. package/src/mcp/cli_args/value_args.rs +175 -0
  135. package/src/mcp/cli_args.rs +658 -0
  136. package/src/mcp/cli_args_tests.rs +522 -0
  137. package/src/mcp/code_execute.rs +671 -0
  138. package/src/mcp/tools.rs +660 -0
  139. package/src/mcp.rs +325 -0
  140. package/src/output/audit_risk.rs +135 -0
  141. package/src/output/dependency_findings.rs +327 -0
  142. package/src/output/duplication_findings.rs +114 -0
  143. package/src/output/feature_flag_findings.rs +122 -0
  144. package/src/output/format.rs +31 -0
  145. package/src/output/graph_findings.rs +461 -0
  146. package/src/output/health_findings.rs +612 -0
  147. package/src/output/human.rs +27 -0
  148. package/src/output/next_steps.rs +92 -0
  149. package/src/output/route_findings.rs +76 -0
  150. package/src/output/runtime_coverage.rs +515 -0
  151. package/src/output/scope.rs +183 -0
  152. package/src/output/security_findings.rs +390 -0
  153. package/src/output/security_sarif.rs +150 -0
  154. package/src/output/suppressions.rs +323 -0
  155. package/src/output/symbol_findings.rs +257 -0
  156. package/src/output/tests.rs +114 -0
  157. package/src/output/types.rs +604 -0
  158. package/src/output/widget_findings.rs +213 -0
  159. package/src/output.rs +682 -0
  160. package/src/package_map.rs +495 -0
  161. package/src/policy/packs.rs +232 -0
  162. package/src/policy/tests.rs +134 -0
  163. package/src/policy.rs +640 -0
  164. package/src/project_list.rs +376 -0
  165. package/src/report_schema/inventory.rs +418 -0
  166. package/src/report_schema.rs +488 -0
  167. package/src/routes.rs +354 -0
  168. package/src/scan/tests.rs +250 -0
  169. package/src/scan.rs +275 -0
  170. package/src/security/detect.rs +639 -0
  171. package/src/security/tests.rs +178 -0
  172. package/src/security.rs +373 -0
  173. package/src/security_gate.rs +555 -0
  174. package/src/symbols/path_filters.rs +27 -0
  175. package/src/symbols/private_type_leaks.rs +125 -0
  176. package/src/symbols/riverpod.rs +113 -0
  177. package/src/symbols/tests.rs +692 -0
  178. package/src/symbols.rs +693 -0
  179. package/src/trace/tests.rs +225 -0
  180. package/src/trace.rs +690 -0
  181. package/src/unsupported.rs +47 -0
  182. package/src/widgets/lifecycle.rs +484 -0
  183. package/src/widgets/params.rs +236 -0
  184. package/src/widgets/tests.rs +430 -0
  185. package/src/widgets/top_level.rs +110 -0
  186. package/src/widgets/unrendered.rs +374 -0
  187. package/src/widgets.rs +590 -0
  188. package/src/workspace_scope.rs +358 -0
@@ -0,0 +1,235 @@
1
+ use std::collections::BTreeSet;
2
+ use std::path::PathBuf;
3
+
4
+ use serde::Deserialize;
5
+ use serde_json::{Value, json};
6
+
7
+ use crate::{BoundaryPreset, BoundaryRule, boundary_preset_rules};
8
+
9
+ use super::ConfigError;
10
+
11
+ #[derive(Debug, Clone, Default, PartialEq, Eq)]
12
+ pub(crate) struct ParsedBoundarySettings {
13
+ pub(crate) rules: Vec<BoundaryRule>,
14
+ pub(crate) presets: Vec<BoundaryPreset>,
15
+ pub(crate) allow_unmatched: Vec<String>,
16
+ pub(crate) require_all_files: Option<bool>,
17
+ }
18
+
19
+ impl ParsedBoundarySettings {
20
+ pub(crate) fn merge(&mut self, other: Self) {
21
+ self.rules.extend(other.rules);
22
+ self.presets.extend(other.presets);
23
+ self.allow_unmatched.extend(other.allow_unmatched);
24
+ self.require_all_files = other.require_all_files.or(self.require_all_files);
25
+ }
26
+
27
+ pub(crate) fn finish(mut self) -> (Vec<BoundaryRule>, Vec<BoundaryPreset>, Vec<String>) {
28
+ self.presets = dedup_presets(self.presets);
29
+ self.rules.extend(boundary_preset_rules(&self.presets));
30
+ (
31
+ dedup_rules(self.rules),
32
+ self.presets,
33
+ dedup_strings(self.allow_unmatched),
34
+ )
35
+ }
36
+ }
37
+
38
+ #[derive(Debug, Clone, Deserialize)]
39
+ #[serde(untagged)]
40
+ pub(crate) enum RawBoundaries {
41
+ List(Vec<RawBoundary>),
42
+ Object(RawBoundarySettings),
43
+ }
44
+
45
+ impl Default for RawBoundaries {
46
+ fn default() -> Self {
47
+ Self::List(Vec::new())
48
+ }
49
+ }
50
+
51
+ impl RawBoundaries {
52
+ pub(crate) fn into_settings(self) -> Result<ParsedBoundarySettings, ConfigError> {
53
+ match self {
54
+ Self::List(rules) => Ok(ParsedBoundarySettings {
55
+ rules: parse_boundaries(rules)?,
56
+ ..ParsedBoundarySettings::default()
57
+ }),
58
+ Self::Object(settings) => settings.into_settings(),
59
+ }
60
+ }
61
+ }
62
+
63
+ #[derive(Debug, Clone, Default, Deserialize)]
64
+ #[serde(default, deny_unknown_fields)]
65
+ pub(crate) struct RawBoundarySettings {
66
+ #[serde(alias = "rule", alias = "boundary")]
67
+ rules: Vec<RawBoundary>,
68
+ preset: Option<BoundaryPreset>,
69
+ presets: Vec<BoundaryPreset>,
70
+ #[serde(alias = "allowUnmatched")]
71
+ allow_unmatched: Vec<String>,
72
+ coverage: RawBoundaryCoverage,
73
+ }
74
+
75
+ impl RawBoundarySettings {
76
+ fn into_settings(self) -> Result<ParsedBoundarySettings, ConfigError> {
77
+ let mut presets = self.presets;
78
+ if let Some(preset) = self.preset {
79
+ presets.push(preset);
80
+ }
81
+ let mut allow_unmatched = self.allow_unmatched;
82
+ allow_unmatched.extend(self.coverage.allow_unmatched);
83
+ Ok(ParsedBoundarySettings {
84
+ rules: parse_boundaries(self.rules)?,
85
+ presets,
86
+ allow_unmatched,
87
+ require_all_files: self.coverage.require_all_files,
88
+ })
89
+ }
90
+ }
91
+
92
+ #[derive(Debug, Clone, Default, Deserialize)]
93
+ #[serde(default, deny_unknown_fields)]
94
+ struct RawBoundaryCoverage {
95
+ #[serde(alias = "requireAllFiles")]
96
+ require_all_files: Option<bool>,
97
+ #[serde(alias = "allowUnmatched")]
98
+ allow_unmatched: Vec<String>,
99
+ }
100
+
101
+ #[derive(Debug, Clone, Deserialize)]
102
+ #[serde(untagged)]
103
+ pub(crate) enum RawBoundary {
104
+ String(String),
105
+ Object(RawBoundaryObject),
106
+ }
107
+
108
+ #[derive(Debug, Clone, Deserialize)]
109
+ #[serde(deny_unknown_fields)]
110
+ pub(crate) struct RawBoundaryObject {
111
+ from: PathBuf,
112
+ disallow: PathBuf,
113
+ }
114
+
115
+ fn parse_boundaries(raw: Vec<RawBoundary>) -> Result<Vec<BoundaryRule>, ConfigError> {
116
+ raw.into_iter().map(parse_boundary).collect()
117
+ }
118
+
119
+ fn parse_boundary(raw: RawBoundary) -> Result<BoundaryRule, ConfigError> {
120
+ match raw {
121
+ RawBoundary::String(value) => parse_boundary_string(&value),
122
+ RawBoundary::Object(object) => {
123
+ if object.from.as_os_str().is_empty() || object.disallow.as_os_str().is_empty() {
124
+ return Err(ConfigError::BoundaryRule {
125
+ value: format!("{object:?}"),
126
+ });
127
+ }
128
+ Ok(BoundaryRule::new(object.from, object.disallow))
129
+ }
130
+ }
131
+ }
132
+
133
+ fn parse_boundary_string(value: &str) -> Result<BoundaryRule, ConfigError> {
134
+ let Some((from, disallow)) = value.split_once(':') else {
135
+ return Err(ConfigError::BoundaryRule {
136
+ value: value.to_owned(),
137
+ });
138
+ };
139
+ if from.is_empty() || disallow.is_empty() {
140
+ return Err(ConfigError::BoundaryRule {
141
+ value: value.to_owned(),
142
+ });
143
+ }
144
+ Ok(BoundaryRule::new(from, disallow))
145
+ }
146
+
147
+ fn dedup_rules(rules: Vec<BoundaryRule>) -> Vec<BoundaryRule> {
148
+ let mut seen = BTreeSet::new();
149
+ rules
150
+ .into_iter()
151
+ .filter(|rule| seen.insert((rule.from.clone(), rule.disallow.clone())))
152
+ .collect()
153
+ }
154
+
155
+ fn dedup_presets(presets: Vec<BoundaryPreset>) -> Vec<BoundaryPreset> {
156
+ presets
157
+ .into_iter()
158
+ .collect::<BTreeSet<_>>()
159
+ .into_iter()
160
+ .collect()
161
+ }
162
+
163
+ fn dedup_strings(values: Vec<String>) -> Vec<String> {
164
+ values
165
+ .into_iter()
166
+ .filter(|value| !value.trim().is_empty())
167
+ .collect::<BTreeSet<_>>()
168
+ .into_iter()
169
+ .collect()
170
+ }
171
+
172
+ pub(crate) fn boundary_schema() -> Value {
173
+ json!({
174
+ "oneOf": [
175
+ boundary_rule_list_schema(),
176
+ {
177
+ "type": "object",
178
+ "additionalProperties": false,
179
+ "properties": {
180
+ "rule": boundary_rule_list_schema(),
181
+ "rules": boundary_rule_list_schema(),
182
+ "boundary": boundary_rule_list_schema(),
183
+ "preset": preset_schema(),
184
+ "presets": {
185
+ "type": "array",
186
+ "items": preset_schema()
187
+ },
188
+ "allow_unmatched": string_list_schema(),
189
+ "allowUnmatched": string_list_schema(),
190
+ "coverage": {
191
+ "type": "object",
192
+ "additionalProperties": false,
193
+ "properties": {
194
+ "require_all_files": { "type": "boolean" },
195
+ "requireAllFiles": { "type": "boolean" },
196
+ "allow_unmatched": string_list_schema(),
197
+ "allowUnmatched": string_list_schema()
198
+ }
199
+ }
200
+ }
201
+ }
202
+ ]
203
+ })
204
+ }
205
+
206
+ fn boundary_rule_list_schema() -> Value {
207
+ json!({
208
+ "type": "array",
209
+ "items": {
210
+ "oneOf": [
211
+ { "type": "string", "pattern": "^.+:.+$" },
212
+ {
213
+ "type": "object",
214
+ "additionalProperties": false,
215
+ "required": ["from", "disallow"],
216
+ "properties": {
217
+ "from": { "type": "string" },
218
+ "disallow": { "type": "string" }
219
+ }
220
+ }
221
+ ]
222
+ }
223
+ })
224
+ }
225
+
226
+ fn preset_schema() -> Value {
227
+ json!({
228
+ "type": "string",
229
+ "enum": ["layered", "hexagonal", "feature-sliced", "bulletproof"]
230
+ })
231
+ }
232
+
233
+ fn string_list_schema() -> Value {
234
+ json!({ "type": "array", "items": { "type": "string" } })
235
+ }
@@ -0,0 +1,25 @@
1
+ use std::path::PathBuf;
2
+
3
+ use serde::{Deserialize, Serialize};
4
+ use serde_json::{Value, json};
5
+
6
+ /// Cache configuration metadata.
7
+ #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
8
+ #[serde(default, deny_unknown_fields)]
9
+ pub struct CacheConfig {
10
+ /// Whether Dart Decimate-owned caches are enabled.
11
+ pub enabled: Option<bool>,
12
+ /// Local cache directory, relative to the project root unless absolute.
13
+ pub path: Option<PathBuf>,
14
+ }
15
+
16
+ pub(super) fn cache_schema() -> Value {
17
+ json!({
18
+ "type": "object",
19
+ "additionalProperties": false,
20
+ "properties": {
21
+ "enabled": { "type": "boolean" },
22
+ "path": { "type": "string" }
23
+ }
24
+ })
25
+ }
@@ -0,0 +1,114 @@
1
+ use std::path::Path;
2
+
3
+ use serde::{Deserialize, Serialize};
4
+ use serde_json::{Value, json};
5
+
6
+ use crate::{
7
+ DependencyHygieneReport, DependencySection, MisconfiguredDependencyOverride, PrivateSrcImport,
8
+ UnlistedPackageDependency, UnusedPackageDependency,
9
+ };
10
+
11
+ /// Config rule for suppressing known intentional dependency overrides.
12
+ #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
13
+ #[serde(deny_unknown_fields)]
14
+ pub struct IgnoreDependencyOverrideRule {
15
+ /// Override package name or raw override key.
16
+ pub package: String,
17
+ /// Optional source file name, such as `pubspec.yaml`.
18
+ #[serde(default)]
19
+ pub source: Option<String>,
20
+ }
21
+
22
+ pub(super) fn ignore_dependency_overrides_schema() -> Value {
23
+ json!({
24
+ "type": "array",
25
+ "items": {
26
+ "type": "object",
27
+ "additionalProperties": false,
28
+ "required": ["package"],
29
+ "properties": {
30
+ "package": { "type": "string" },
31
+ "source": { "type": ["string", "null"] }
32
+ }
33
+ }
34
+ })
35
+ }
36
+
37
+ pub(crate) fn filter_ignored_dependency_overrides(
38
+ report: &mut DependencyHygieneReport,
39
+ rules: &[IgnoreDependencyOverrideRule],
40
+ ) {
41
+ if rules.is_empty() {
42
+ return;
43
+ }
44
+
45
+ report
46
+ .unused_dependencies
47
+ .retain(|dependency| !unused_override_matches(dependency, rules));
48
+ report
49
+ .misconfigured_dependency_overrides
50
+ .retain(|dependency| !misconfigured_override_matches(dependency, rules));
51
+ }
52
+
53
+ pub(crate) fn filter_ignored_dependencies(
54
+ report: &mut DependencyHygieneReport,
55
+ ignored: &[String],
56
+ ) {
57
+ if ignored.is_empty() {
58
+ return;
59
+ }
60
+
61
+ report
62
+ .unused_dependencies
63
+ .retain(|dependency| !ignored_dependency_matches(&dependency.dependency, ignored));
64
+ report
65
+ .unlisted_dependencies
66
+ .retain(|dependency| !unlisted_dependency_matches(dependency, ignored));
67
+ report
68
+ .private_src_imports
69
+ .retain(|dependency| !private_src_import_matches(dependency, ignored));
70
+ }
71
+
72
+ fn unlisted_dependency_matches(dependency: &UnlistedPackageDependency, ignored: &[String]) -> bool {
73
+ ignored_dependency_matches(&dependency.dependency, ignored)
74
+ }
75
+
76
+ fn private_src_import_matches(dependency: &PrivateSrcImport, ignored: &[String]) -> bool {
77
+ ignored_dependency_matches(&dependency.dependency, ignored)
78
+ }
79
+
80
+ fn ignored_dependency_matches(dependency: &str, ignored: &[String]) -> bool {
81
+ ignored.iter().any(|ignored| ignored == dependency)
82
+ }
83
+
84
+ fn unused_override_matches(
85
+ dependency: &UnusedPackageDependency,
86
+ rules: &[IgnoreDependencyOverrideRule],
87
+ ) -> bool {
88
+ dependency.section == DependencySection::DependencyOverrides
89
+ && rules
90
+ .iter()
91
+ .any(|rule| rule.matches(&dependency.dependency, &dependency.pubspec_path))
92
+ }
93
+
94
+ fn misconfigured_override_matches(
95
+ dependency: &MisconfiguredDependencyOverride,
96
+ rules: &[IgnoreDependencyOverrideRule],
97
+ ) -> bool {
98
+ let package = dependency
99
+ .dependency
100
+ .as_deref()
101
+ .unwrap_or(&dependency.raw_key);
102
+ rules
103
+ .iter()
104
+ .any(|rule| rule.matches(package, &dependency.pubspec_path))
105
+ }
106
+
107
+ impl IgnoreDependencyOverrideRule {
108
+ fn matches(&self, package: &str, path: &Path) -> bool {
109
+ self.package == package
110
+ && self.source.as_deref().is_none_or(|source| {
111
+ path.file_name().and_then(|name| name.to_str()) == Some(source)
112
+ })
113
+ }
114
+ }
@@ -0,0 +1,237 @@
1
+ use std::path::PathBuf;
2
+
3
+ use serde::{Deserialize, Serialize};
4
+ use serde_json::{Value, json};
5
+
6
+ use crate::{HealthOptions, HealthThresholdOverride, LowTrafficThreshold};
7
+
8
+ use super::ConfigError;
9
+
10
+ /// Health analyzer config defaults.
11
+ #[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
12
+ #[serde(deny_unknown_fields)]
13
+ pub struct HealthConfig {
14
+ /// Maximum cyclomatic complexity before reporting.
15
+ #[serde(default, alias = "maxCyclomatic")]
16
+ pub max_cyclomatic: Option<usize>,
17
+ /// Maximum cognitive complexity before reporting.
18
+ #[serde(default, alias = "maxCognitive")]
19
+ pub max_cognitive: Option<usize>,
20
+ /// Limit output to the N highest complexity findings.
21
+ #[serde(default)]
22
+ pub top: Option<usize>,
23
+ /// Include per-decision-point complexity contributions.
24
+ #[serde(default, alias = "complexityBreakdown")]
25
+ pub complexity_breakdown: Option<bool>,
26
+ /// LCOV file for coverage-aware health checks.
27
+ #[serde(default, alias = "coveragePath")]
28
+ pub coverage_path: Option<PathBuf>,
29
+ /// Report Dart files with no covered executable lines.
30
+ #[serde(default, alias = "coverageGaps")]
31
+ pub coverage_gaps: Option<bool>,
32
+ /// Maximum CRAP score before reporting.
33
+ #[serde(default, alias = "maxCrap")]
34
+ pub max_crap: Option<usize>,
35
+ /// Runtime coverage JSON file or directory.
36
+ #[serde(default, alias = "runtimeCoverage")]
37
+ pub runtime_coverage: Option<PathBuf>,
38
+ /// Minimum runtime invocations before a file is a hot path.
39
+ #[serde(default, alias = "minInvocationsHot")]
40
+ pub min_invocations_hot: Option<usize>,
41
+ /// Minimum runtime observations for high-confidence signals.
42
+ #[serde(default, alias = "minObservationVolume")]
43
+ pub min_observation_volume: Option<usize>,
44
+ /// Fraction of runtime traffic considered low traffic.
45
+ #[serde(default, alias = "lowTrafficThreshold")]
46
+ pub low_traffic_threshold: Option<LowTrafficThreshold>,
47
+ /// Include per-file health scores.
48
+ #[serde(default, alias = "fileScores")]
49
+ pub file_scores: Option<bool>,
50
+ /// Report low-scoring complexity hotspots.
51
+ #[serde(default)]
52
+ pub hotspots: Option<bool>,
53
+ /// Report prioritized refactoring targets.
54
+ #[serde(default)]
55
+ pub targets: Option<bool>,
56
+ /// Attach CODEOWNERS ownership metadata to health output.
57
+ #[serde(default)]
58
+ pub ownership: Option<bool>,
59
+ /// Minimum file health score before hotspot reporting.
60
+ #[serde(default, alias = "minScore")]
61
+ pub min_score: Option<usize>,
62
+ /// Per-file/function local complexity ceilings.
63
+ #[serde(default, alias = "thresholdOverrides")]
64
+ pub threshold_overrides: Vec<HealthThresholdOverride>,
65
+ }
66
+
67
+ impl HealthConfig {
68
+ pub(super) fn validate(&self) -> Result<(), ConfigError> {
69
+ for (index, rule) in self.threshold_overrides.iter().enumerate() {
70
+ if rule.files.is_empty() {
71
+ return Err(ConfigError::HealthThresholdOverride {
72
+ index,
73
+ message: "files must contain at least one glob".to_owned(),
74
+ });
75
+ }
76
+ if !rule.has_threshold() {
77
+ return Err(ConfigError::HealthThresholdOverride {
78
+ index,
79
+ message: "set maxCyclomatic, maxCognitive, or maxCrap".to_owned(),
80
+ });
81
+ }
82
+ for pattern in &rule.files {
83
+ if let Err(error) = glob::Pattern::new(pattern) {
84
+ return Err(ConfigError::HealthThresholdOverride {
85
+ index,
86
+ message: format!("invalid files glob {pattern:?}: {error}"),
87
+ });
88
+ }
89
+ }
90
+ }
91
+ Ok(())
92
+ }
93
+
94
+ pub(super) fn apply_to(&self, options: &mut HealthOptions) {
95
+ if let Some(max_cyclomatic) = self.max_cyclomatic {
96
+ options.max_cyclomatic = max_cyclomatic;
97
+ }
98
+ if let Some(max_cognitive) = self.max_cognitive {
99
+ options.max_cognitive = max_cognitive;
100
+ }
101
+ if self.top.is_some() {
102
+ options.top = self.top;
103
+ }
104
+ if let Some(complexity_breakdown) = self.complexity_breakdown {
105
+ options.complexity_breakdown = complexity_breakdown.into();
106
+ }
107
+ if self.coverage_path.is_some() {
108
+ options.coverage_path.clone_from(&self.coverage_path);
109
+ }
110
+ if let Some(coverage_gaps) = self.coverage_gaps {
111
+ options.coverage_gaps = coverage_gaps.into();
112
+ }
113
+ if self.max_crap.is_some() {
114
+ options.max_crap = self.max_crap;
115
+ }
116
+ if self.runtime_coverage.is_some() {
117
+ options
118
+ .runtime_coverage_path
119
+ .clone_from(&self.runtime_coverage);
120
+ }
121
+ if let Some(min_invocations_hot) = self.min_invocations_hot {
122
+ options.min_invocations_hot = min_invocations_hot.max(1);
123
+ }
124
+ if let Some(min_observation_volume) = self.min_observation_volume {
125
+ options.min_observation_volume = min_observation_volume.max(1);
126
+ }
127
+ if let Some(low_traffic_threshold) = self.low_traffic_threshold {
128
+ options.low_traffic_threshold = low_traffic_threshold;
129
+ }
130
+ if let Some(file_scores) = self.file_scores {
131
+ options.file_scores = file_scores.into();
132
+ }
133
+ if let Some(hotspots) = self.hotspots {
134
+ options.hotspots = hotspots.into();
135
+ }
136
+ if let Some(targets) = self.targets {
137
+ options.targets = targets.into();
138
+ }
139
+ if let Some(ownership) = self.ownership {
140
+ options.ownership = ownership.into();
141
+ }
142
+ if let Some(min_score) = self.min_score {
143
+ options.min_score = min_score.min(100);
144
+ }
145
+ options
146
+ .threshold_overrides
147
+ .clone_from(&self.threshold_overrides);
148
+ }
149
+ }
150
+
151
+ pub(super) fn health_schema() -> Value {
152
+ json!({
153
+ "type": "object",
154
+ "additionalProperties": false,
155
+ "properties": {
156
+ "max_cyclomatic": positive_integer_schema(),
157
+ "maxCyclomatic": positive_integer_schema(),
158
+ "max_cognitive": positive_integer_schema(),
159
+ "maxCognitive": positive_integer_schema(),
160
+ "top": positive_integer_schema(),
161
+ "complexity_breakdown": { "type": "boolean" },
162
+ "complexityBreakdown": { "type": "boolean" },
163
+ "coverage_path": { "type": "string" },
164
+ "coveragePath": { "type": "string" },
165
+ "coverage_gaps": { "type": "boolean" },
166
+ "coverageGaps": { "type": "boolean" },
167
+ "max_crap": positive_integer_schema(),
168
+ "maxCrap": positive_integer_schema(),
169
+ "runtime_coverage": { "type": "string" },
170
+ "runtimeCoverage": { "type": "string" },
171
+ "min_invocations_hot": positive_integer_schema(),
172
+ "minInvocationsHot": positive_integer_schema(),
173
+ "min_observation_volume": positive_integer_schema(),
174
+ "minObservationVolume": positive_integer_schema(),
175
+ "low_traffic_threshold": threshold_schema(),
176
+ "lowTrafficThreshold": threshold_schema(),
177
+ "file_scores": { "type": "boolean" },
178
+ "fileScores": { "type": "boolean" },
179
+ "hotspots": { "type": "boolean" },
180
+ "targets": { "type": "boolean" },
181
+ "ownership": { "type": "boolean" },
182
+ "min_score": score_schema(),
183
+ "minScore": score_schema(),
184
+ "threshold_overrides": threshold_overrides_schema(),
185
+ "thresholdOverrides": threshold_overrides_schema()
186
+ }
187
+ })
188
+ }
189
+
190
+ fn positive_integer_schema() -> Value {
191
+ json!({ "type": "integer", "minimum": 1 })
192
+ }
193
+
194
+ fn score_schema() -> Value {
195
+ json!({ "type": "integer", "minimum": 0, "maximum": 100 })
196
+ }
197
+
198
+ fn threshold_schema() -> Value {
199
+ json!({ "type": "number", "minimum": 0, "maximum": 1 })
200
+ }
201
+
202
+ fn threshold_overrides_schema() -> Value {
203
+ json!({
204
+ "type": "array",
205
+ "items": {
206
+ "type": "object",
207
+ "additionalProperties": false,
208
+ "required": ["files"],
209
+ "anyOf": [
210
+ { "required": ["max_cyclomatic"] },
211
+ { "required": ["maxCyclomatic"] },
212
+ { "required": ["max_cognitive"] },
213
+ { "required": ["maxCognitive"] },
214
+ { "required": ["max_crap"] },
215
+ { "required": ["maxCrap"] }
216
+ ],
217
+ "properties": {
218
+ "files": {
219
+ "type": "array",
220
+ "minItems": 1,
221
+ "items": { "type": "string" }
222
+ },
223
+ "functions": {
224
+ "type": "array",
225
+ "items": { "type": "string" }
226
+ },
227
+ "max_cyclomatic": positive_integer_schema(),
228
+ "maxCyclomatic": positive_integer_schema(),
229
+ "max_cognitive": positive_integer_schema(),
230
+ "maxCognitive": positive_integer_schema(),
231
+ "max_crap": positive_integer_schema(),
232
+ "maxCrap": positive_integer_schema(),
233
+ "reason": { "type": ["string", "null"] }
234
+ }
235
+ }
236
+ })
237
+ }
@@ -0,0 +1,66 @@
1
+ pub(super) fn strip_json_comments(source: &str) -> String {
2
+ let mut output = String::with_capacity(source.len());
3
+ let mut chars = source.chars().peekable();
4
+ let mut in_string = false;
5
+ let mut escaped = false;
6
+
7
+ while let Some(ch) = chars.next() {
8
+ if in_string {
9
+ output.push(ch);
10
+ if escaped {
11
+ escaped = false;
12
+ } else if ch == '\\' {
13
+ escaped = true;
14
+ } else if ch == '"' {
15
+ in_string = false;
16
+ }
17
+ continue;
18
+ }
19
+
20
+ match ch {
21
+ '"' => {
22
+ in_string = true;
23
+ output.push(ch);
24
+ }
25
+ '/' if chars.peek() == Some(&'/') => {
26
+ let _ = chars.next();
27
+ skip_line_comment(&mut chars, &mut output);
28
+ }
29
+ '/' if chars.peek() == Some(&'*') => {
30
+ let _ = chars.next();
31
+ skip_block_comment(&mut chars, &mut output);
32
+ }
33
+ _ => output.push(ch),
34
+ }
35
+ }
36
+
37
+ output
38
+ }
39
+
40
+ fn skip_line_comment<I>(chars: &mut std::iter::Peekable<I>, output: &mut String)
41
+ where
42
+ I: Iterator<Item = char>,
43
+ {
44
+ for ch in chars.by_ref() {
45
+ if ch == '\n' {
46
+ output.push('\n');
47
+ break;
48
+ }
49
+ }
50
+ }
51
+
52
+ fn skip_block_comment<I>(chars: &mut std::iter::Peekable<I>, output: &mut String)
53
+ where
54
+ I: Iterator<Item = char>,
55
+ {
56
+ let mut previous = '\0';
57
+ for ch in chars.by_ref() {
58
+ if ch == '\n' {
59
+ output.push('\n');
60
+ }
61
+ if previous == '*' && ch == '/' {
62
+ break;
63
+ }
64
+ previous = ch;
65
+ }
66
+ }