dart-decimate 0.0.42 → 0.0.44

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.
@@ -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
  ),
@@ -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,42 @@ 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
+ report
230
+ }
231
+
232
+ /// Recompute duplicate statistics from the clone groups visible in a report.
233
+ pub(crate) fn recompute_visible_duplication_summary(report: &mut JsonReport) {
234
+ let mut duplicated = BTreeSet::<(String, usize)>::new();
235
+ for group in &report.clone_groups {
236
+ for instance in &group.instances {
237
+ for line in instance.start_line..=instance.end_line {
238
+ duplicated.insert((instance.path.clone(), line));
239
+ }
240
+ }
241
+ }
242
+ report.summary.code_duplications = report.clone_groups.len();
243
+ report.summary.duplicated_lines = duplicated.len();
244
+ report.summary.duplication_percentage_basis_points =
245
+ if report.summary.duplication_analyzed_lines == 0 {
246
+ 0
247
+ } else {
248
+ let raw = ((report.summary.duplicated_lines as u128) * 10_000)
249
+ / (report.summary.duplication_analyzed_lines as u128);
250
+ u32::try_from(raw).unwrap_or(u32::MAX)
251
+ };
252
+ report.summary.duplication_threshold_exceeded = crate::dupes::duplication_threshold_exceeded(
253
+ report.summary.duplication_analyzed_lines,
254
+ report.summary.duplicated_lines,
255
+ report.summary.duplication_threshold_basis_points,
256
+ );
222
257
  }
223
258
 
224
259
  /// Keep only selected finding kinds and recompute visible report counts.
@@ -231,6 +266,7 @@ pub fn filter_report_findings(report: &mut JsonReport, allowed: &[FindingKind])
231
266
  .retain(|finding| allowed.contains(&finding.kind));
232
267
  if !allowed.contains(&FindingKind::CodeDuplication) {
233
268
  report.clone_groups.clear();
269
+ recompute_visible_duplication_summary(report);
234
270
  }
235
271
  if !allowed.iter().any(|kind| is_complexity_kind(*kind)) {
236
272
  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" },