dart-decimate 0.0.43 → 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.
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" },