dart-decimate 0.0.43 → 0.0.45

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.
@@ -33,6 +33,7 @@ const BASELINE_KEYS: &[&str] = &[
33
33
  "fail_on_regression",
34
34
  "tolerance",
35
35
  ];
36
+ const REPORT_GATE_KEYS: &[&str] = &["strict"];
36
37
  const SYMBOL_KEYS: &[&str] = &["include_entry_exports", "private_type_leaks"];
37
38
  const BOUNDARY_KEYS: &[&str] = &[
38
39
  "boundary",
@@ -161,12 +162,14 @@ fn extend_analyze_allowed(allowed: &mut Vec<&'static str>) {
161
162
  allowed.extend(BOUNDARY_KEYS);
162
163
  allowed.extend(DUPLICATE_KEYS);
163
164
  allowed.extend(HEALTH_KEYS);
165
+ allowed.extend(REPORT_GATE_KEYS);
164
166
  }
165
167
 
166
168
  fn extend_check_changed_allowed(allowed: &mut Vec<&'static str>) {
167
169
  allowed.extend(["since", "changed_since", "compare"]);
168
170
  allowed.extend(BASELINE_KEYS);
169
171
  allowed.extend(["dart_platform", "production"]);
172
+ allowed.extend(REPORT_GATE_KEYS);
170
173
  }
171
174
 
172
175
  fn extend_project_info_allowed(allowed: &mut Vec<&'static str>) {
@@ -184,6 +187,7 @@ fn extend_dupes_allowed(allowed: &mut Vec<&'static str>) {
184
187
  allowed.extend(REPORT_SCOPE_KEYS);
185
188
  allowed.extend(BASELINE_KEYS);
186
189
  allowed.extend(DUPLICATE_KEYS);
190
+ allowed.extend(REPORT_GATE_KEYS);
187
191
  }
188
192
 
189
193
  fn extend_trace_clone_allowed(allowed: &mut Vec<&'static str>) {
@@ -195,6 +199,7 @@ fn extend_health_allowed(allowed: &mut Vec<&'static str>) {
195
199
  allowed.extend(REPORT_SCOPE_KEYS);
196
200
  allowed.extend(BASELINE_KEYS);
197
201
  allowed.extend(HEALTH_KEYS);
202
+ allowed.extend(REPORT_GATE_KEYS);
198
203
  }
199
204
 
200
205
  fn extend_runtime_allowed(allowed: &mut Vec<&'static str>) {
@@ -221,12 +226,14 @@ fn extend_security_allowed(allowed: &mut Vec<&'static str>) {
221
226
  "fail_on_issues",
222
227
  "summary",
223
228
  ]);
229
+ allowed.extend(REPORT_GATE_KEYS);
224
230
  }
225
231
 
226
232
  fn extend_flags_allowed(allowed: &mut Vec<&'static str>) {
227
233
  allowed.extend(REPORT_SCOPE_KEYS);
228
234
  allowed.extend(BASELINE_KEYS);
229
235
  allowed.extend(["top"]);
236
+ allowed.extend(REPORT_GATE_KEYS);
230
237
  }
231
238
 
232
239
  fn extend_fix_allowed(allowed: &mut Vec<&'static str>) {
@@ -254,6 +261,7 @@ fn extend_audit_allowed(allowed: &mut Vec<&'static str>) {
254
261
  "dupes_baseline",
255
262
  "max_decisions",
256
263
  ]);
264
+ allowed.extend(REPORT_GATE_KEYS);
257
265
  }
258
266
 
259
267
  fn report_args<F>(
@@ -285,6 +293,7 @@ fn analyze_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(),
285
293
  push_boundary_args(cli, args)?;
286
294
  push_duplicate_args(cli, args)?;
287
295
  push_health_args(cli, args)?;
296
+ push_report_gate_args(cli, args)?;
288
297
  if let Some(issue_types) = args.get("issue_types") {
289
298
  for issue_type in array_strings(issue_types, "issue_types")? {
290
299
  cli.push(issue_filter_flag(issue_type)?);
@@ -301,7 +310,8 @@ fn check_changed_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Resul
301
310
  cli.extend(["--changed-since".to_owned(), since]);
302
311
  push_baseline_args(cli, args)?;
303
312
  push_string_flag(cli, args, "dart_platform", "--dart-platform")?;
304
- push_bool_mode(cli, args, "production", "--production", "--no-production")
313
+ push_bool_mode(cli, args, "production", "--production", "--no-production")?;
314
+ push_report_gate_args(cli, args)
305
315
  }
306
316
 
307
317
  fn project_info_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
@@ -403,7 +413,8 @@ fn trace_clone_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<
403
413
  fn dupes_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
404
414
  push_report_scope_args(cli, args)?;
405
415
  push_baseline_args(cli, args)?;
406
- push_duplicate_args(cli, args)
416
+ push_duplicate_args(cli, args)?;
417
+ push_report_gate_args(cli, args)
407
418
  }
408
419
 
409
420
  fn push_duplicate_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
@@ -429,7 +440,8 @@ fn push_duplicate_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Resu
429
440
  fn health_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
430
441
  push_report_scope_args(cli, args)?;
431
442
  push_baseline_args(cli, args)?;
432
- push_health_args(cli, args)
443
+ push_health_args(cli, args)?;
444
+ push_report_gate_args(cli, args)
433
445
  }
434
446
 
435
447
  fn coverage_analyze_args(args: &Map<String, Value>) -> Result<Vec<String>, String> {
@@ -509,14 +521,14 @@ fn security_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(),
509
521
  ] {
510
522
  push_bool_flag(cli, args, key, flag)?;
511
523
  }
512
- Ok(())
524
+ push_report_gate_args(cli, args)
513
525
  }
514
526
 
515
527
  fn flags_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
516
528
  push_report_scope_args(cli, args)?;
517
529
  push_baseline_args(cli, args)?;
518
530
  push_number_flag(cli, args, "top", "--top")?;
519
- Ok(())
531
+ push_report_gate_args(cli, args)
520
532
  }
521
533
 
522
534
  fn impact_args(args: &Map<String, Value>) -> Result<Vec<String>, String> {
@@ -576,7 +588,11 @@ fn audit_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), St
576
588
  }
577
589
  push_number_flag(cli, args, "max_decisions", "--max-decisions")?;
578
590
  push_bool_flag(cli, args, "brief", "--brief")?;
579
- Ok(())
591
+ push_report_gate_args(cli, args)
592
+ }
593
+
594
+ fn push_report_gate_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
595
+ push_bool_flag(cli, args, "strict", "--strict")
580
596
  }
581
597
 
582
598
  fn decision_surface_args(cli: &mut Vec<String>, args: &Map<String, Value>) -> Result<(), String> {
@@ -17,6 +17,7 @@ fn analyze_maps_read_only_parity_flags() -> Result<(), String> {
17
17
  "baseline": "baseline.json",
18
18
  "regression_baseline": "regression.json",
19
19
  "fail_on_regression": true,
20
+ "strict": true,
20
21
  "tolerance": "10%",
21
22
  "include_entry_exports": true,
22
23
  "private_type_leaks": true,
@@ -65,6 +66,7 @@ fn analyze_maps_read_only_parity_flags() -> Result<(), String> {
65
66
  assert_pair(&cli, "--baseline", "baseline.json");
66
67
  assert_pair(&cli, "--regression-baseline", "regression.json");
67
68
  assert_flag(&cli, "--fail-on-regression");
69
+ assert_flag(&cli, "--strict");
68
70
  assert_pair(&cli, "--tolerance", "10%");
69
71
  assert_flag(&cli, "--include-entry-exports");
70
72
  assert_flag(&cli, "--private-type-leaks");
package/src/mcp/tools.rs CHANGED
@@ -56,6 +56,7 @@ fn analyze_tool() -> Value {
56
56
  ("baseline", "string"),
57
57
  ("regression_baseline", "string"),
58
58
  ("fail_on_regression", "boolean"),
59
+ ("strict", "boolean"),
59
60
  ("tolerance", "string"),
60
61
  ("include_entry_exports", "boolean"),
61
62
  ("private_type_leaks", "boolean"),
@@ -110,6 +111,7 @@ fn check_changed_tool() -> Value {
110
111
  ("baseline", "string"),
111
112
  ("regression_baseline", "string"),
112
113
  ("fail_on_regression", "boolean"),
114
+ ("strict", "boolean"),
113
115
  ("tolerance", "string"),
114
116
  ("production", "boolean"),
115
117
  ],
@@ -300,6 +302,7 @@ fn dupes_tool() -> Value {
300
302
  ("baseline", "string"),
301
303
  ("regression_baseline", "string"),
302
304
  ("fail_on_regression", "boolean"),
305
+ ("strict", "boolean"),
303
306
  ("tolerance", "string"),
304
307
  ("production", "boolean"),
305
308
  ("min_tokens", "integer"),
@@ -339,6 +342,7 @@ fn health_tool() -> Value {
339
342
  ("baseline", "string"),
340
343
  ("regression_baseline", "string"),
341
344
  ("fail_on_regression", "boolean"),
345
+ ("strict", "boolean"),
342
346
  ("tolerance", "string"),
343
347
  ("runtime_coverage", "string"),
344
348
  ("min_invocations_hot", "integer"),
@@ -398,6 +402,7 @@ fn security_tool() -> Value {
398
402
  ("baseline", "string"),
399
403
  ("regression_baseline", "string"),
400
404
  ("fail_on_regression", "boolean"),
405
+ ("strict", "boolean"),
401
406
  ("tolerance", "string"),
402
407
  ("surface", "boolean"),
403
408
  ("production", "boolean"),
@@ -448,6 +453,7 @@ fn feature_flags_tool() -> Value {
448
453
  ("baseline", "string"),
449
454
  ("regression_baseline", "string"),
450
455
  ("fail_on_regression", "boolean"),
456
+ ("strict", "boolean"),
451
457
  ("tolerance", "string"),
452
458
  ("production", "boolean"),
453
459
  ],
@@ -573,6 +579,7 @@ fn audit_tool() -> Value {
573
579
  ("production", "boolean"),
574
580
  ("brief", "boolean"),
575
581
  ("max_decisions", "integer"),
582
+ ("strict", "boolean"),
576
583
  ],
577
584
  &["base"],
578
585
  ),
@@ -112,3 +112,51 @@ fn code_duplication_finding(root: &Path, clone: &crate::CodeClone) -> Finding {
112
112
  ],
113
113
  }
114
114
  }
115
+
116
+ // Findings and clone inventories share suppression semantics. Reconcile all
117
+ // groups before limiting details so --top cannot weaken the duplication gate.
118
+ pub(super) fn reconcile_clone_visibility(
119
+ report: &mut super::JsonReport,
120
+ results: &super::AnalysisResults,
121
+ ) {
122
+ let original_count = report.clone_groups.len();
123
+ report.clone_groups.retain(|group| {
124
+ report.findings.iter().any(|finding| {
125
+ finding.kind == FindingKind::CodeDuplication
126
+ && finding.fingerprint.as_ref() == Some(&group.fingerprint)
127
+ })
128
+ });
129
+ if report.clone_groups.len() != original_count {
130
+ super::recompute_visible_duplication_summary(report);
131
+ }
132
+ if let Some(top) = results
133
+ .duplicates
134
+ .as_ref()
135
+ .and_then(|dupes| dupes.options.top)
136
+ {
137
+ report.clone_groups.truncate(top);
138
+ report.findings.retain(|finding| {
139
+ finding.kind != FindingKind::CodeDuplication
140
+ || report
141
+ .clone_groups
142
+ .iter()
143
+ .any(|group| finding.fingerprint.as_ref() == Some(&group.fingerprint))
144
+ });
145
+ report.summary.code_duplications = report.clone_groups.len();
146
+ report.summary.findings = report.findings.len();
147
+ report.verdict = super::report_verdict(&report.findings);
148
+ }
149
+ report.next_steps.retain_mut(|step| {
150
+ if step.id != "trace-code-duplication" {
151
+ return true;
152
+ }
153
+ let Some(group) = report.clone_groups.first() else {
154
+ return false;
155
+ };
156
+ step.command = format!(
157
+ "dart-decimate trace-clone --format json --fingerprint {}",
158
+ group.fingerprint
159
+ );
160
+ true
161
+ });
162
+ }
@@ -1,4 +1,5 @@
1
1
  use std::collections::BTreeSet;
2
+ use std::fs;
2
3
 
3
4
  use super::format;
4
5
  use super::{
@@ -7,6 +8,7 @@ use super::{
7
8
  JsonRefactoringTarget, JsonSecurityCandidate,
8
9
  };
9
10
  use crate::{HealthReport, SemanticOmissionReason, SemanticReport, scan::ScannedProject};
11
+ use crate::{dupes::is_ignored_path, graph::normalize_against};
10
12
 
11
13
  pub(super) fn file_scope(
12
14
  project: &ScannedProject,
@@ -201,6 +203,28 @@ pub(super) fn project_file_scope_count(
201
203
  .count()
202
204
  }
203
205
 
206
+ pub(super) fn scoped_duplication_analyzed_lines(
207
+ project: &ScannedProject,
208
+ scope: &BTreeSet<String>,
209
+ ) -> usize {
210
+ project
211
+ .files
212
+ .iter()
213
+ .filter_map(|file| {
214
+ let path = normalize_against(&project.root, &file.path);
215
+ if !path.starts_with(&project.root)
216
+ || is_ignored_path(&path)
217
+ || !scope.contains(&format::display_path(&project.root, &path))
218
+ {
219
+ return None;
220
+ }
221
+ fs::read_to_string(path)
222
+ .ok()
223
+ .map(|source| source.lines().count())
224
+ })
225
+ .sum()
226
+ }
227
+
204
228
  pub(super) fn health_file_score_count(
205
229
  project: &ScannedProject,
206
230
  scores: &[crate::FileHealthScore],
package/src/output.rs CHANGED
@@ -69,7 +69,7 @@ pub use runtime_coverage::{
69
69
  use scope::{
70
70
  file_scope, finding_in_scope, health_file_score_count, project_file_scope_count,
71
71
  scope_clone_groups, scope_feature_flags, scope_file_scores, scope_hotspots,
72
- scope_refactoring_targets, scoped_quality_score,
72
+ scope_refactoring_targets, scoped_duplication_analyzed_lines, scoped_quality_score,
73
73
  };
74
74
  pub use security_findings::{
75
75
  JsonAttackSurfaceEntry, JsonSecurityBlindSpot, JsonSecurityCandidate, JsonSecurityOccurrence,
@@ -195,10 +195,10 @@ pub fn build_json_report(project: &ScannedProject, results: &AnalysisResults) ->
195
195
  );
196
196
  }
197
197
 
198
- JsonReport {
198
+ let mut report = JsonReport {
199
199
  schema_version: SCHEMA_VERSION.to_owned(),
200
200
  kind: results.command.kind().to_owned(),
201
- tool: "dart-decimate".to_owned(),
201
+ tool: crate::REPORT_TOOL.to_owned(),
202
202
  command: results.command,
203
203
  verdict: report_verdict(&findings),
204
204
  summary,
@@ -218,7 +218,43 @@ pub fn build_json_report(project: &ScannedProject, results: &AnalysisResults) ->
218
218
  attack_surface: security.attack_surface,
219
219
  runtime_coverage,
220
220
  next_steps,
221
+ };
222
+ if results.duplicates.is_some()
223
+ && let Some(scope) = scope.as_ref()
224
+ {
225
+ report.summary.duplication_analyzed_lines =
226
+ scoped_duplication_analyzed_lines(project, scope);
227
+ recompute_visible_duplication_summary(&mut report);
221
228
  }
229
+ duplication_findings::reconcile_clone_visibility(&mut report, results);
230
+ report
231
+ }
232
+
233
+ /// Recompute duplicate statistics from the clone groups visible in a report.
234
+ pub(crate) fn recompute_visible_duplication_summary(report: &mut JsonReport) {
235
+ let mut duplicated = BTreeSet::<(String, usize)>::new();
236
+ for group in &report.clone_groups {
237
+ for instance in &group.instances {
238
+ for line in instance.start_line..=instance.end_line {
239
+ duplicated.insert((instance.path.clone(), line));
240
+ }
241
+ }
242
+ }
243
+ report.summary.code_duplications = report.clone_groups.len();
244
+ report.summary.duplicated_lines = duplicated.len();
245
+ report.summary.duplication_percentage_basis_points =
246
+ if report.summary.duplication_analyzed_lines == 0 {
247
+ 0
248
+ } else {
249
+ let raw = ((report.summary.duplicated_lines as u128) * 10_000)
250
+ / (report.summary.duplication_analyzed_lines as u128);
251
+ u32::try_from(raw).unwrap_or(u32::MAX)
252
+ };
253
+ report.summary.duplication_threshold_exceeded = crate::dupes::duplication_threshold_exceeded(
254
+ report.summary.duplication_analyzed_lines,
255
+ report.summary.duplicated_lines,
256
+ report.summary.duplication_threshold_basis_points,
257
+ );
222
258
  }
223
259
 
224
260
  /// Keep only selected finding kinds and recompute visible report counts.
@@ -231,6 +267,7 @@ pub fn filter_report_findings(report: &mut JsonReport, allowed: &[FindingKind])
231
267
  .retain(|finding| allowed.contains(&finding.kind));
232
268
  if !allowed.contains(&FindingKind::CodeDuplication) {
233
269
  report.clone_groups.clear();
270
+ recompute_visible_duplication_summary(report);
234
271
  }
235
272
  if !allowed.iter().any(|kind| is_complexity_kind(*kind)) {
236
273
  report.complexity.clear();
@@ -38,7 +38,10 @@ pub fn report_schema() -> Value {
38
38
  "properties": {
39
39
  "schema_version": { "const": SCHEMA_VERSION },
40
40
  "kind": { "type": "string", "enum": kind_values() },
41
- "tool": { "const": "dart-decimate" },
41
+ "tool": {
42
+ "type": "string",
43
+ "pattern": r"^dart-decimate [0-9]+\.[0-9]+\.[0-9]+(?:-[0-9A-Za-z.-]+)?(?:\+[0-9A-Za-z.-]+)?$"
44
+ },
42
45
  "command": { "type": "string", "enum": command_values() },
43
46
  "verdict": { "type": "string", "enum": ["pass", "fail"] },
44
47
  "summary": { "$ref": "#/$defs/summary" },