dart-decimate 0.0.44 → 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.
- package/Cargo.lock +1 -1
- package/Cargo.toml +1 -1
- package/README.md +14 -9
- package/package.json +1 -1
- package/src/cli/analyze.rs +9 -3
- package/src/dupes/declarations.rs +70 -4
- package/src/dupes.rs +6 -1
- package/src/output/duplication_findings.rs +48 -0
- package/src/output.rs +1 -0
package/Cargo.lock
CHANGED
package/Cargo.toml
CHANGED
package/README.md
CHANGED
|
@@ -90,7 +90,7 @@ You do not need to install anything permanently. Use the command above.
|
|
|
90
90
|
For repeatable automation, pin the version:
|
|
91
91
|
|
|
92
92
|
```bash
|
|
93
|
-
npx --yes dart-decimate@0.0.
|
|
93
|
+
npx --yes dart-decimate@0.0.45
|
|
94
94
|
```
|
|
95
95
|
|
|
96
96
|
Add this to `package.json` if you want a short project command:
|
|
@@ -101,7 +101,7 @@ Add this to `package.json` if you want a short project command:
|
|
|
101
101
|
"dart-decimate": "dart-decimate json ."
|
|
102
102
|
},
|
|
103
103
|
"devDependencies": {
|
|
104
|
-
"dart-decimate": "0.0.
|
|
104
|
+
"dart-decimate": "0.0.45"
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
```
|
|
@@ -115,7 +115,7 @@ npm run dart-decimate
|
|
|
115
115
|
If you prefer Cargo, install the matching tagged source:
|
|
116
116
|
|
|
117
117
|
```bash
|
|
118
|
-
cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.
|
|
118
|
+
cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.45 --locked
|
|
119
119
|
```
|
|
120
120
|
|
|
121
121
|
The npm release `X.Y.Z` and Cargo tag `vX.Y.Z` are verified against each other
|
|
@@ -126,7 +126,7 @@ Confirm a Cargo build's version with:
|
|
|
126
126
|
|
|
127
127
|
```bash
|
|
128
128
|
dart-decimate --version
|
|
129
|
-
# dart-decimate 0.0.
|
|
129
|
+
# dart-decimate 0.0.45
|
|
130
130
|
```
|
|
131
131
|
|
|
132
132
|
## npx
|
|
@@ -255,8 +255,13 @@ Dart Decimate finds exact and semantic clone groups. Each clone group gets a sta
|
|
|
255
255
|
fingerprint like `dup:abc12345`, so agents can trace it before touching code.
|
|
256
256
|
Clone windows must meet both line and token thresholds; sparse duplicated blocks
|
|
257
257
|
can span more than `--min-lines`, and `line_count` reports the actual match.
|
|
258
|
-
|
|
258
|
+
Bodyless contract declarations are excluded even when a clone window covers
|
|
259
|
+
only part of a signature or matches a concrete implementation. Matching concrete
|
|
260
|
+
implementations remain eligible for duplication checks. Copied local Pub package
|
|
259
261
|
mirrors are canonicalized before same-mirror matches are ignored.
|
|
262
|
+
A next-line `code-duplication` suppression on the reported group anchor removes
|
|
263
|
+
that group from findings, clone details, and duplication-threshold accounting.
|
|
264
|
+
`--top` limits displayed groups without reducing the remaining duplication total.
|
|
260
265
|
Pair-only class clones joined by an explicit `toEntity()` or `toDomain()` mapper
|
|
261
266
|
are treated as intentional boundaries by default. Set
|
|
262
267
|
`dupes.ignore_mapper_pairs = false` to report those pairs.
|
|
@@ -531,7 +536,7 @@ Example shape:
|
|
|
531
536
|
{
|
|
532
537
|
"schema_version": "dart-decimate.report.v1",
|
|
533
538
|
"kind": "combined",
|
|
534
|
-
"tool": "dart-decimate 0.0.
|
|
539
|
+
"tool": "dart-decimate 0.0.45",
|
|
535
540
|
"command": "check",
|
|
536
541
|
"verdict": "fail",
|
|
537
542
|
"summary": {
|
|
@@ -547,7 +552,7 @@ Example shape:
|
|
|
547
552
|
|
|
548
553
|
The `dart-decimate.report.v1` field layout is unchanged. Its existing `tool`
|
|
549
554
|
string includes the producing version so saved reports identify the exact
|
|
550
|
-
build, for example `dart-decimate 0.0.
|
|
555
|
+
build, for example `dart-decimate 0.0.45`.
|
|
551
556
|
|
|
552
557
|
When grouped security findings hide additional occurrences, `next_steps` can
|
|
553
558
|
include `review-security-surface`, which reruns
|
|
@@ -635,7 +640,7 @@ you need the installed binary's exact list.
|
|
|
635
640
|
For a complete repository check, including discovered local packages:
|
|
636
641
|
|
|
637
642
|
```bash
|
|
638
|
-
npx --yes dart-decimate@0.0.
|
|
643
|
+
npx --yes dart-decimate@0.0.45 --strict
|
|
639
644
|
```
|
|
640
645
|
|
|
641
646
|
This runs every enabled check from the repository root. The default duplication
|
|
@@ -678,7 +683,7 @@ This repository forbids `unsafe_code`.
|
|
|
678
683
|
|
|
679
684
|
## Release Flow
|
|
680
685
|
|
|
681
|
-
Current source version: `0.0.
|
|
686
|
+
Current source version: `0.0.45`.
|
|
682
687
|
|
|
683
688
|
After the first public release, changes should go through pull requests. Every
|
|
684
689
|
PR to `main` must bump both `Cargo.toml` and `package.json` above the base
|
package/package.json
CHANGED
package/src/cli/analyze.rs
CHANGED
|
@@ -274,9 +274,15 @@ fn analyze_project_duplicates(
|
|
|
274
274
|
request: &CommandRequest,
|
|
275
275
|
) -> Result<Option<crate::DuplicateCodeReport>, CliError> {
|
|
276
276
|
match request.command {
|
|
277
|
-
ReportCommand::Check | ReportCommand::Audit | ReportCommand::Dupes =>
|
|
278
|
-
|
|
279
|
-
|
|
277
|
+
ReportCommand::Check | ReportCommand::Audit | ReportCommand::Dupes => {
|
|
278
|
+
// Suppression and threshold accounting need all groups. Apply the
|
|
279
|
+
// requested detail limit only after the report has reconciled them.
|
|
280
|
+
let mut options = request.duplicate_options.clone();
|
|
281
|
+
options.top = None;
|
|
282
|
+
let mut report = detect_duplicates(project, &options)?;
|
|
283
|
+
report.options.top = request.duplicate_options.top;
|
|
284
|
+
Ok(Some(report))
|
|
285
|
+
}
|
|
280
286
|
ReportCommand::DeadCode
|
|
281
287
|
| ReportCommand::Cycles
|
|
282
288
|
| ReportCommand::Health
|
|
@@ -2,7 +2,9 @@ use std::collections::{BTreeMap, BTreeSet};
|
|
|
2
2
|
use std::fs;
|
|
3
3
|
use std::path::{Path, PathBuf};
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
#[cfg(test)]
|
|
6
|
+
use super::CodeClone;
|
|
7
|
+
use super::CodeCloneInstance;
|
|
6
8
|
|
|
7
9
|
pub(super) struct DeclarationCloneFilter {
|
|
8
10
|
files: BTreeMap<PathBuf, Option<DeclarationFileContext>>,
|
|
@@ -15,6 +17,7 @@ impl DeclarationCloneFilter {
|
|
|
15
17
|
}
|
|
16
18
|
}
|
|
17
19
|
|
|
20
|
+
#[cfg(test)]
|
|
18
21
|
pub(super) fn is_declaration_only_clone(&mut self, group: &CodeClone) -> bool {
|
|
19
22
|
group
|
|
20
23
|
.instances
|
|
@@ -22,7 +25,10 @@ impl DeclarationCloneFilter {
|
|
|
22
25
|
.all(|instance| self.clone_instance_is_declaration_only(instance))
|
|
23
26
|
}
|
|
24
27
|
|
|
25
|
-
fn clone_instance_is_declaration_only(
|
|
28
|
+
pub(super) fn clone_instance_is_declaration_only(
|
|
29
|
+
&mut self,
|
|
30
|
+
instance: &CodeCloneInstance,
|
|
31
|
+
) -> bool {
|
|
26
32
|
let path = instance.path.clone();
|
|
27
33
|
let Some(file) = self
|
|
28
34
|
.files
|
|
@@ -43,7 +49,11 @@ impl DeclarationCloneFilter {
|
|
|
43
49
|
})
|
|
44
50
|
.filter(|(_, line)| !line.is_empty())
|
|
45
51
|
.collect::<Vec<_>>();
|
|
46
|
-
!lines.is_empty()
|
|
52
|
+
!lines.is_empty()
|
|
53
|
+
&& (lines
|
|
54
|
+
.iter()
|
|
55
|
+
.all(|(line, _)| file.bodyless_lines.contains(line))
|
|
56
|
+
|| declaration_only_lines(&lines, &file.context.direct_type_body_lines))
|
|
47
57
|
}
|
|
48
58
|
|
|
49
59
|
#[cfg(test)]
|
|
@@ -55,13 +65,69 @@ impl DeclarationCloneFilter {
|
|
|
55
65
|
struct DeclarationFileContext {
|
|
56
66
|
source: String,
|
|
57
67
|
context: DeclarationContext,
|
|
68
|
+
bodyless_lines: BTreeSet<usize>,
|
|
58
69
|
}
|
|
59
70
|
|
|
60
71
|
impl DeclarationFileContext {
|
|
61
72
|
fn read(path: &Path) -> Option<Self> {
|
|
62
73
|
let source = fs::read_to_string(path).ok()?;
|
|
63
74
|
let context = DeclarationContext::from_source(&source);
|
|
64
|
-
|
|
75
|
+
let bodyless_lines = bodyless_member_lines(path, &source);
|
|
76
|
+
Some(Self {
|
|
77
|
+
source,
|
|
78
|
+
context,
|
|
79
|
+
bodyless_lines,
|
|
80
|
+
})
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Class-member declaration nodes exclude concrete method bodies. Classify the
|
|
85
|
+
// entire source before looking at clone windows, which may end mid-signature.
|
|
86
|
+
fn bodyless_member_lines(path: &Path, source: &str) -> BTreeSet<usize> {
|
|
87
|
+
let mut lines = BTreeSet::new();
|
|
88
|
+
let Ok(parsed) = crate::dart_parser::parse_dart_source_strict(path, source) else {
|
|
89
|
+
return lines;
|
|
90
|
+
};
|
|
91
|
+
collect_bodyless_lines(parsed.tree().root_node(), parsed.source(), &mut lines);
|
|
92
|
+
lines
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
fn collect_bodyless_lines(node: tree_sitter::Node<'_>, source: &str, lines: &mut BTreeSet<usize>) {
|
|
96
|
+
if node.kind() == "class_member" {
|
|
97
|
+
let mut cursor = node.walk();
|
|
98
|
+
let bodyless = node.named_children(&mut cursor).any(|child| {
|
|
99
|
+
child.kind() == "declaration" && {
|
|
100
|
+
let mut cursor = child.walk();
|
|
101
|
+
child.named_children(&mut cursor).any(|signature| {
|
|
102
|
+
matches!(
|
|
103
|
+
signature.kind(),
|
|
104
|
+
"function_signature"
|
|
105
|
+
| "getter_signature"
|
|
106
|
+
| "setter_signature"
|
|
107
|
+
| "operator_signature"
|
|
108
|
+
)
|
|
109
|
+
})
|
|
110
|
+
}
|
|
111
|
+
});
|
|
112
|
+
// Keep the existing conservative treatment of default values.
|
|
113
|
+
let text = &source[node.byte_range()];
|
|
114
|
+
if bodyless && !signature_contains_non_operator_equals(text) {
|
|
115
|
+
let start = node.start_position();
|
|
116
|
+
let end = node.end_position();
|
|
117
|
+
for (row, line) in source.lines().enumerate().take(end.row + 1).skip(start.row) {
|
|
118
|
+
let before = row != start.row || line[..start.column].trim().is_empty();
|
|
119
|
+
let after =
|
|
120
|
+
row != end.row || strip_line_comment(&line[end.column..]).trim().is_empty();
|
|
121
|
+
if before && after {
|
|
122
|
+
lines.insert(row + 1);
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return;
|
|
127
|
+
}
|
|
128
|
+
let mut cursor = node.walk();
|
|
129
|
+
for child in node.named_children(&mut cursor) {
|
|
130
|
+
collect_bodyless_lines(child, source, lines);
|
|
65
131
|
}
|
|
66
132
|
}
|
|
67
133
|
|
package/src/dupes.rs
CHANGED
|
@@ -415,7 +415,12 @@ pub fn detect_duplicates(
|
|
|
415
415
|
}
|
|
416
416
|
clone_groups.retain(|group| group_satisfies_occurrence_options(group, options));
|
|
417
417
|
let mut declaration_filter = DeclarationCloneFilter::new();
|
|
418
|
-
|
|
418
|
+
for group in &mut clone_groups {
|
|
419
|
+
group
|
|
420
|
+
.instances
|
|
421
|
+
.retain(|instance| !declaration_filter.clone_instance_is_declaration_only(instance));
|
|
422
|
+
}
|
|
423
|
+
clone_groups.retain(|group| group_satisfies_occurrence_options(group, options));
|
|
419
424
|
if options.ignore_mapper_pairs {
|
|
420
425
|
let mapping_filter = MappingBoundaryFilter::new(project);
|
|
421
426
|
clone_groups.retain(|group| !mapping_filter.is_mapping_boundary_clone(group));
|
|
@@ -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
|
+
}
|
package/src/output.rs
CHANGED
|
@@ -226,6 +226,7 @@ pub fn build_json_report(project: &ScannedProject, results: &AnalysisResults) ->
|
|
|
226
226
|
scoped_duplication_analyzed_lines(project, scope);
|
|
227
227
|
recompute_visible_duplication_summary(&mut report);
|
|
228
228
|
}
|
|
229
|
+
duplication_findings::reconcile_clone_visibility(&mut report, results);
|
|
229
230
|
report
|
|
230
231
|
}
|
|
231
232
|
|