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.
- package/Cargo.lock +572 -0
- package/Cargo.toml +41 -0
- package/LICENSE +21 -0
- package/README.md +617 -0
- package/assets/dart-decimate-banner.png +0 -0
- package/npm/bin/dart-decimate-mcp.js +48 -0
- package/npm/bin/dart-decimate.js +48 -0
- package/npm/scripts/postinstall.js +46 -0
- package/npm/scripts/test-npx-local.js +54 -0
- package/npm/scripts/test-npx-mcp-local.js +56 -0
- package/package.json +45 -0
- package/src/baseline.rs +643 -0
- package/src/bin/dart-decimate-mcp.rs +11 -0
- package/src/boundaries/tests.rs +60 -0
- package/src/boundaries.rs +317 -0
- package/src/changed_scope.rs +117 -0
- package/src/ci_template.rs +399 -0
- package/src/cli/analyze.rs +462 -0
- package/src/cli/analyzer_options.rs +82 -0
- package/src/cli/audit_run.rs +327 -0
- package/src/cli/boundary_args.rs +44 -0
- package/src/cli/ci_template_run.rs +196 -0
- package/src/cli/command_name.rs +20 -0
- package/src/cli/common_args.rs +167 -0
- package/src/cli/config_run.rs +78 -0
- package/src/cli/coverage_run.rs +393 -0
- package/src/cli/decision_surface_run.rs +99 -0
- package/src/cli/default_command.rs +69 -0
- package/src/cli/dupes_args.rs +150 -0
- package/src/cli/entry_points.rs +121 -0
- package/src/cli/error.rs +149 -0
- package/src/cli/error_output.rs +68 -0
- package/src/cli/explain_run.rs +72 -0
- package/src/cli/fix_run.rs +162 -0
- package/src/cli/flags_args.rs +23 -0
- package/src/cli/health_args.rs +200 -0
- package/src/cli/hooks_run.rs +191 -0
- package/src/cli/impact_run.rs +95 -0
- package/src/cli/init_run.rs +49 -0
- package/src/cli/inspect_args.rs +20 -0
- package/src/cli/inspect_run.rs +66 -0
- package/src/cli/issue_filter_args.rs +240 -0
- package/src/cli/list_run.rs +311 -0
- package/src/cli/mode_args.rs +72 -0
- package/src/cli/output_format.rs +62 -0
- package/src/cli/regression_args.rs +156 -0
- package/src/cli/request_args.rs +175 -0
- package/src/cli/schema_commands.rs +72 -0
- package/src/cli/scope_args.rs +174 -0
- package/src/cli/security_args.rs +175 -0
- package/src/cli/security_gate_run.rs +66 -0
- package/src/cli/security_summary_run.rs +43 -0
- package/src/cli/summary_args.rs +12 -0
- package/src/cli/tests.rs +516 -0
- package/src/cli/trace_args.rs +67 -0
- package/src/cli/trace_run.rs +131 -0
- package/src/cli/trace_tests.rs +235 -0
- package/src/cli/unsupported_run.rs +116 -0
- package/src/cli/watch_run.rs +153 -0
- package/src/cli.rs +603 -0
- package/src/config/boundary_config.rs +235 -0
- package/src/config/cache.rs +25 -0
- package/src/config/dependencies.rs +114 -0
- package/src/config/health.rs +237 -0
- package/src/config/jsonc.rs +66 -0
- package/src/config/policy.rs +91 -0
- package/src/config/rule_aliases.rs +487 -0
- package/src/config/rules.rs +339 -0
- package/src/config.rs +635 -0
- package/src/coverage.rs +469 -0
- package/src/dart_parser.rs +673 -0
- package/src/decision_surface.rs +405 -0
- package/src/dependencies/analyze.rs +218 -0
- package/src/dependencies/codegen.rs +118 -0
- package/src/dependencies/discovery.rs +60 -0
- package/src/dependencies/overrides.rs +76 -0
- package/src/dependencies/private_src_imports.rs +32 -0
- package/src/dependencies/pubspec_document.rs +86 -0
- package/src/dependencies/pubspec_entry.rs +96 -0
- package/src/dependencies/tests.rs +544 -0
- package/src/dependencies/usage.rs +33 -0
- package/src/dependencies.rs +553 -0
- package/src/dependency_scripts.rs +91 -0
- package/src/dupes/lex.rs +236 -0
- package/src/dupes/tests.rs +119 -0
- package/src/dupes.rs +625 -0
- package/src/explain.rs +692 -0
- package/src/extract/directives.rs +252 -0
- package/src/extract/error_tests.rs +25 -0
- package/src/extract/members.rs +210 -0
- package/src/extract/primary_constructors.rs +421 -0
- package/src/extract/references.rs +151 -0
- package/src/extract/routes.rs +691 -0
- package/src/extract/signatures.rs +266 -0
- package/src/extract/string_tests.rs +18 -0
- package/src/extract/strings.rs +107 -0
- package/src/extract/tests.rs +697 -0
- package/src/extract.rs +680 -0
- package/src/feature_flags/tests.rs +76 -0
- package/src/feature_flags.rs +453 -0
- package/src/finding_identity.rs +60 -0
- package/src/fix.rs +551 -0
- package/src/generated.rs +53 -0
- package/src/graph/augment_tests.rs +212 -0
- package/src/graph/conditionals.rs +74 -0
- package/src/graph/package_config_tests.rs +100 -0
- package/src/graph/parts.rs +248 -0
- package/src/graph/pubspec_tests.rs +119 -0
- package/src/graph/tests.rs +837 -0
- package/src/graph/uri_tests.rs +102 -0
- package/src/graph.rs +644 -0
- package/src/health/coverage.rs +309 -0
- package/src/health/ownership.rs +175 -0
- package/src/health/runtime_coverage.rs +616 -0
- package/src/health/runtime_intelligence.rs +511 -0
- package/src/health/scores.rs +296 -0
- package/src/health/tests.rs +240 -0
- package/src/health/threshold_types.rs +163 -0
- package/src/health/thresholds.rs +229 -0
- package/src/health/types.rs +636 -0
- package/src/health.rs +597 -0
- package/src/hooks/agent_settings.rs +175 -0
- package/src/hooks/templates.rs +51 -0
- package/src/hooks.rs +569 -0
- package/src/impact.rs +287 -0
- package/src/init.rs +237 -0
- package/src/inspect.rs +142 -0
- package/src/intelligence/tests.rs +232 -0
- package/src/intelligence.rs +305 -0
- package/src/lib.rs +198 -0
- package/src/main.rs +5 -0
- package/src/manifest/mcp.rs +565 -0
- package/src/manifest.rs +552 -0
- package/src/mcp/cli_args/value_args.rs +175 -0
- package/src/mcp/cli_args.rs +658 -0
- package/src/mcp/cli_args_tests.rs +522 -0
- package/src/mcp/code_execute.rs +671 -0
- package/src/mcp/tools.rs +660 -0
- package/src/mcp.rs +325 -0
- package/src/output/audit_risk.rs +135 -0
- package/src/output/dependency_findings.rs +327 -0
- package/src/output/duplication_findings.rs +114 -0
- package/src/output/feature_flag_findings.rs +122 -0
- package/src/output/format.rs +31 -0
- package/src/output/graph_findings.rs +461 -0
- package/src/output/health_findings.rs +612 -0
- package/src/output/human.rs +27 -0
- package/src/output/next_steps.rs +92 -0
- package/src/output/route_findings.rs +76 -0
- package/src/output/runtime_coverage.rs +515 -0
- package/src/output/scope.rs +183 -0
- package/src/output/security_findings.rs +390 -0
- package/src/output/security_sarif.rs +150 -0
- package/src/output/suppressions.rs +323 -0
- package/src/output/symbol_findings.rs +257 -0
- package/src/output/tests.rs +114 -0
- package/src/output/types.rs +604 -0
- package/src/output/widget_findings.rs +213 -0
- package/src/output.rs +682 -0
- package/src/package_map.rs +495 -0
- package/src/policy/packs.rs +232 -0
- package/src/policy/tests.rs +134 -0
- package/src/policy.rs +640 -0
- package/src/project_list.rs +376 -0
- package/src/report_schema/inventory.rs +418 -0
- package/src/report_schema.rs +488 -0
- package/src/routes.rs +354 -0
- package/src/scan/tests.rs +250 -0
- package/src/scan.rs +275 -0
- package/src/security/detect.rs +639 -0
- package/src/security/tests.rs +178 -0
- package/src/security.rs +373 -0
- package/src/security_gate.rs +555 -0
- package/src/symbols/path_filters.rs +27 -0
- package/src/symbols/private_type_leaks.rs +125 -0
- package/src/symbols/riverpod.rs +113 -0
- package/src/symbols/tests.rs +692 -0
- package/src/symbols.rs +693 -0
- package/src/trace/tests.rs +225 -0
- package/src/trace.rs +690 -0
- package/src/unsupported.rs +47 -0
- package/src/widgets/lifecycle.rs +484 -0
- package/src/widgets/params.rs +236 -0
- package/src/widgets/tests.rs +430 -0
- package/src/widgets/top_level.rs +110 -0
- package/src/widgets/unrendered.rs +374 -0
- package/src/widgets.rs +590 -0
- package/src/workspace_scope.rs +358 -0
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
use std::collections::BTreeSet;
|
|
2
|
+
use std::path::{Path, PathBuf};
|
|
3
|
+
|
|
4
|
+
use glob::Pattern;
|
|
5
|
+
|
|
6
|
+
use super::FunctionMetrics;
|
|
7
|
+
use super::threshold_types::{
|
|
8
|
+
AppliedThresholds, EffectiveThresholds, HealthThresholdOverride, HealthThresholdOverrideReport,
|
|
9
|
+
HealthThresholdOverrideStatus, ThresholdSource, function_label, override_report,
|
|
10
|
+
};
|
|
11
|
+
use super::types::HealthOptions;
|
|
12
|
+
|
|
13
|
+
#[derive(Debug, Clone)]
|
|
14
|
+
pub(super) struct ThresholdContext {
|
|
15
|
+
root: PathBuf,
|
|
16
|
+
max_cyclomatic: usize,
|
|
17
|
+
max_cognitive: usize,
|
|
18
|
+
max_crap: Option<usize>,
|
|
19
|
+
overrides: Vec<CompiledOverride>,
|
|
20
|
+
states: Vec<OverrideState>,
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
impl ThresholdContext {
|
|
24
|
+
pub(super) fn new(root: &Path, options: &HealthOptions) -> Self {
|
|
25
|
+
let overrides = options
|
|
26
|
+
.threshold_overrides
|
|
27
|
+
.iter()
|
|
28
|
+
.map(CompiledOverride::new)
|
|
29
|
+
.collect::<Vec<_>>();
|
|
30
|
+
Self {
|
|
31
|
+
root: root.to_path_buf(),
|
|
32
|
+
max_cyclomatic: options.max_cyclomatic,
|
|
33
|
+
max_cognitive: options.max_cognitive,
|
|
34
|
+
max_crap: options.max_crap,
|
|
35
|
+
states: vec![OverrideState::default(); overrides.len()],
|
|
36
|
+
overrides,
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
pub(super) fn static_thresholds(&mut self, function: &FunctionMetrics) -> AppliedThresholds {
|
|
41
|
+
let global = AppliedThresholds::default_static(self.max_cyclomatic, self.max_cognitive);
|
|
42
|
+
let mut applied = None;
|
|
43
|
+
|
|
44
|
+
for index in self.static_matches(function) {
|
|
45
|
+
let rule = &self.overrides[index].rule;
|
|
46
|
+
let max_cyclomatic = rule.max_cyclomatic.unwrap_or(self.max_cyclomatic);
|
|
47
|
+
let max_cognitive = rule.max_cognitive.unwrap_or(self.max_cognitive);
|
|
48
|
+
let reason = rule.reason.clone();
|
|
49
|
+
self.mark_matched(index, function);
|
|
50
|
+
let thresholds = AppliedThresholds {
|
|
51
|
+
source: Some(ThresholdSource::Override),
|
|
52
|
+
reason,
|
|
53
|
+
effective: EffectiveThresholds {
|
|
54
|
+
max_cyclomatic: Some(max_cyclomatic),
|
|
55
|
+
max_cognitive: Some(max_cognitive),
|
|
56
|
+
max_crap: None,
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
if self.static_active(function, &thresholds) {
|
|
60
|
+
self.states[index].active = true;
|
|
61
|
+
}
|
|
62
|
+
if applied.is_none() {
|
|
63
|
+
applied = Some(thresholds);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
applied.unwrap_or(global)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
pub(super) fn crap_thresholds(
|
|
71
|
+
&mut self,
|
|
72
|
+
function: &FunctionMetrics,
|
|
73
|
+
crap_score: usize,
|
|
74
|
+
) -> Option<AppliedThresholds> {
|
|
75
|
+
let mut applied = self.max_crap.map(AppliedThresholds::default_crap);
|
|
76
|
+
|
|
77
|
+
for index in self.crap_matches(function) {
|
|
78
|
+
let rule = &self.overrides[index].rule;
|
|
79
|
+
let max_crap = rule.max_crap;
|
|
80
|
+
let reason = rule.reason.clone();
|
|
81
|
+
self.mark_matched(index, function);
|
|
82
|
+
let Some(max_crap) = max_crap else {
|
|
83
|
+
continue;
|
|
84
|
+
};
|
|
85
|
+
let thresholds = AppliedThresholds {
|
|
86
|
+
source: Some(ThresholdSource::Override),
|
|
87
|
+
reason,
|
|
88
|
+
effective: EffectiveThresholds {
|
|
89
|
+
max_cyclomatic: None,
|
|
90
|
+
max_cognitive: None,
|
|
91
|
+
max_crap: Some(max_crap),
|
|
92
|
+
},
|
|
93
|
+
};
|
|
94
|
+
if self.crap_active(crap_score, max_crap) {
|
|
95
|
+
self.states[index].active = true;
|
|
96
|
+
}
|
|
97
|
+
if applied
|
|
98
|
+
.as_ref()
|
|
99
|
+
.is_none_or(|current| current.source.is_none())
|
|
100
|
+
{
|
|
101
|
+
applied = Some(thresholds);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
applied
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
pub(super) fn reports(&self) -> Vec<HealthThresholdOverrideReport> {
|
|
109
|
+
self.overrides
|
|
110
|
+
.iter()
|
|
111
|
+
.zip(&self.states)
|
|
112
|
+
.enumerate()
|
|
113
|
+
.map(|(index, (compiled, state))| {
|
|
114
|
+
override_report(
|
|
115
|
+
index,
|
|
116
|
+
&compiled.rule,
|
|
117
|
+
state.status(),
|
|
118
|
+
state.matched_functions.iter().cloned().collect(),
|
|
119
|
+
)
|
|
120
|
+
})
|
|
121
|
+
.collect()
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
fn static_matches(&self, function: &FunctionMetrics) -> Vec<usize> {
|
|
125
|
+
self.overrides
|
|
126
|
+
.iter()
|
|
127
|
+
.enumerate()
|
|
128
|
+
.filter(|(_, compiled)| {
|
|
129
|
+
compiled.rule.has_static_threshold() && compiled.matches(&self.root, function)
|
|
130
|
+
})
|
|
131
|
+
.map(|(index, _)| index)
|
|
132
|
+
.collect()
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
fn crap_matches(&self, function: &FunctionMetrics) -> Vec<usize> {
|
|
136
|
+
self.overrides
|
|
137
|
+
.iter()
|
|
138
|
+
.enumerate()
|
|
139
|
+
.filter(|(_, compiled)| {
|
|
140
|
+
compiled.rule.has_crap_threshold() && compiled.matches(&self.root, function)
|
|
141
|
+
})
|
|
142
|
+
.map(|(index, _)| index)
|
|
143
|
+
.collect()
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
fn static_active(&self, function: &FunctionMetrics, thresholds: &AppliedThresholds) -> bool {
|
|
147
|
+
let max_cyclomatic = thresholds
|
|
148
|
+
.effective
|
|
149
|
+
.max_cyclomatic
|
|
150
|
+
.unwrap_or(self.max_cyclomatic);
|
|
151
|
+
let max_cognitive = thresholds
|
|
152
|
+
.effective
|
|
153
|
+
.max_cognitive
|
|
154
|
+
.unwrap_or(self.max_cognitive);
|
|
155
|
+
function.cyclomatic > self.max_cyclomatic
|
|
156
|
+
|| function.cognitive > self.max_cognitive
|
|
157
|
+
|| function.cyclomatic > max_cyclomatic
|
|
158
|
+
|| function.cognitive > max_cognitive
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
fn crap_active(&self, crap_score: usize, max_crap: usize) -> bool {
|
|
162
|
+
self.max_crap.is_some_and(|global| crap_score > global) || crap_score > max_crap
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
fn mark_matched(&mut self, index: usize, function: &FunctionMetrics) {
|
|
166
|
+
self.states[index].matched_functions.insert(function_label(
|
|
167
|
+
&self.root,
|
|
168
|
+
&function.path,
|
|
169
|
+
&function.symbol,
|
|
170
|
+
));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
#[derive(Debug, Clone)]
|
|
175
|
+
struct CompiledOverride {
|
|
176
|
+
rule: HealthThresholdOverride,
|
|
177
|
+
file_patterns: Vec<Pattern>,
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
impl CompiledOverride {
|
|
181
|
+
fn new(rule: &HealthThresholdOverride) -> Self {
|
|
182
|
+
Self {
|
|
183
|
+
file_patterns: rule
|
|
184
|
+
.files
|
|
185
|
+
.iter()
|
|
186
|
+
.filter_map(|pattern| Pattern::new(pattern).ok())
|
|
187
|
+
.collect(),
|
|
188
|
+
rule: rule.clone(),
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
fn matches(&self, root: &Path, function: &FunctionMetrics) -> bool {
|
|
193
|
+
let relative = function
|
|
194
|
+
.path
|
|
195
|
+
.strip_prefix(root)
|
|
196
|
+
.unwrap_or(&function.path)
|
|
197
|
+
.components()
|
|
198
|
+
.filter_map(|component| component.as_os_str().to_str())
|
|
199
|
+
.collect::<Vec<_>>()
|
|
200
|
+
.join("/");
|
|
201
|
+
self.file_patterns
|
|
202
|
+
.iter()
|
|
203
|
+
.any(|pattern| pattern.matches(&relative))
|
|
204
|
+
&& (self.rule.functions.is_empty()
|
|
205
|
+
|| self
|
|
206
|
+
.rule
|
|
207
|
+
.functions
|
|
208
|
+
.iter()
|
|
209
|
+
.any(|name| name == &function.symbol))
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
#[derive(Debug, Clone, Default)]
|
|
214
|
+
struct OverrideState {
|
|
215
|
+
active: bool,
|
|
216
|
+
matched_functions: BTreeSet<String>,
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
impl OverrideState {
|
|
220
|
+
fn status(&self) -> HealthThresholdOverrideStatus {
|
|
221
|
+
if self.matched_functions.is_empty() {
|
|
222
|
+
HealthThresholdOverrideStatus::NoMatch
|
|
223
|
+
} else if self.active {
|
|
224
|
+
HealthThresholdOverrideStatus::Active
|
|
225
|
+
} else {
|
|
226
|
+
HealthThresholdOverrideStatus::Stale
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
}
|