dart-decimate 0.0.77 → 0.0.78
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 +8 -8
- package/package.json +2 -2
- package/src/boundaries.rs +1 -9
- package/src/cli/analyze.rs +33 -3
- package/src/cli/error.rs +16 -0
- package/src/cli/list_run.rs +3 -1
- package/src/cli/scope_args.rs +14 -3
- package/src/config.rs +12 -8
- package/src/dart_parser.rs +100 -9
- package/src/dependencies/analyze.rs +4 -3
- package/src/dependencies/discovery.rs +10 -2
- package/src/dependencies/flutter_usage.rs +4 -0
- package/src/dependencies/tests.rs +5 -5
- package/src/dependencies/usage.rs +0 -9
- package/src/dependencies.rs +12 -7
- package/src/dupes/declarations.rs +1 -2
- package/src/dupes.rs +1 -10
- package/src/explain/misc.rs +1 -1
- package/src/explain.rs +1 -1
- package/src/extract/members.rs +24 -15
- package/src/extract/tests.rs +89 -0
- package/src/extract.rs +51 -15
- package/src/graph.rs +9 -0
- package/src/lib.rs +3 -2
- package/src/output/duplication_findings.rs +1 -2
- package/src/output/human.rs +7 -2
- package/src/output/human_details.rs +6 -0
- package/src/output/next_steps.rs +111 -0
- package/src/output/route_cycle/aliases.rs +1 -2
- package/src/output/route_cycle/wrappers.rs +1 -2
- package/src/output/types.rs +2 -0
- package/src/output.rs +27 -5
- package/src/outside/loader.rs +133 -0
- package/src/outside/loader_tests.rs +136 -0
- package/src/outside/resolver.rs +484 -0
- package/src/outside/tests.rs +242 -0
- package/src/outside.rs +186 -0
- package/src/package_map.rs +30 -1
- package/src/report_schema.rs +1 -0
- package/src/routes.rs +2 -0
- package/src/scan.rs +24 -3
- package/src/security/detect/process_arguments.rs +106 -0
- package/src/security/detect.rs +98 -40
- package/src/symbols/extensions.rs +42 -27
- package/src/symbols/path_filters.rs +10 -1
- package/src/symbols/tests.rs +15 -0
- package/src/symbols.rs +489 -67
- package/src/trace.rs +6 -5
- package/src/widgets/reads.rs +4 -8
- package/src/widgets/resolution.rs +63 -10
- package/src/workspace_scope.rs +1 -10
package/src/trace.rs
CHANGED
|
@@ -338,7 +338,7 @@ pub fn trace_dependency(
|
|
|
338
338
|
project: &ScannedProject,
|
|
339
339
|
dependency: &str,
|
|
340
340
|
) -> Result<DependencyTraceReport, DependencyHygieneError> {
|
|
341
|
-
let packages = local_pub_packages(&project.root)?;
|
|
341
|
+
let packages = local_pub_packages(&project.root, &project.ignore_patterns)?;
|
|
342
342
|
let mut importing_files = dependency_directives(project, &packages, dependency);
|
|
343
343
|
importing_files.sort_by(|left, right| {
|
|
344
344
|
(
|
|
@@ -357,10 +357,11 @@ pub fn trace_dependency(
|
|
|
357
357
|
))
|
|
358
358
|
});
|
|
359
359
|
|
|
360
|
-
let declared_in =
|
|
361
|
-
.
|
|
362
|
-
|
|
363
|
-
|
|
360
|
+
let declared_in =
|
|
361
|
+
declared_package_dependencies(&project.root, &project.ignore_patterns, dependency)?
|
|
362
|
+
.iter()
|
|
363
|
+
.map(|declaration| trace_pubspec_dependency(&project.root, declaration))
|
|
364
|
+
.collect::<Vec<_>>();
|
|
364
365
|
let declared = !declared_in.is_empty();
|
|
365
366
|
let total_import_count = importing_files.len();
|
|
366
367
|
let used_in_scripts = packages.iter().any(|package| {
|
package/src/widgets/reads.rs
CHANGED
|
@@ -146,8 +146,7 @@ fn state_member_receiver(object: Node<'_>) -> Option<Node<'_>> {
|
|
|
146
146
|
if object.kind() != "function_expression" {
|
|
147
147
|
return None;
|
|
148
148
|
}
|
|
149
|
-
// The
|
|
150
|
-
// expression body for `() => widget.onSubmit?.call()`.
|
|
149
|
+
// The grammar attaches `().onSubmit` to the closure, not its expression body.
|
|
151
150
|
let body = object.child_by_field_name("body")?;
|
|
152
151
|
if body.kind() != "function_expression_body" || body.named_child_count() != 1 {
|
|
153
152
|
return None;
|
|
@@ -423,8 +422,7 @@ pub(super) fn scoped_header_binding_exists(
|
|
|
423
422
|
return false;
|
|
424
423
|
}
|
|
425
424
|
if for_in_iterable(scope, path_child) {
|
|
426
|
-
// The iterable is evaluated in the enclosing scope, so
|
|
427
|
-
// `for (final widget in widget.items)` reads the outer `widget`.
|
|
425
|
+
// The iterable is evaluated in the enclosing scope, so it reads the outer name.
|
|
428
426
|
return false;
|
|
429
427
|
}
|
|
430
428
|
if header_field_binding_exists(scope, path_child, usage_start, name, source) {
|
|
@@ -453,8 +451,7 @@ fn for_in_iterable(scope: Node<'_>, path_child: Node<'_>) -> bool {
|
|
|
453
451
|
}
|
|
454
452
|
|
|
455
453
|
fn header_child_binds_name(child: Node<'_>, name: &str, source: &str) -> bool {
|
|
456
|
-
// A classic `for` initializer binds only its declared names
|
|
457
|
-
// initializer expressions are reads.
|
|
454
|
+
// A classic `for` initializer binds only its declared names.
|
|
458
455
|
if child.kind() == "local_variable_declaration" {
|
|
459
456
|
return declaration_binds_name(child, name, source);
|
|
460
457
|
}
|
|
@@ -563,8 +560,7 @@ fn header_binding_child(scope_kind: &str, child: Node<'_>) -> bool {
|
|
|
563
560
|
{
|
|
564
561
|
return true;
|
|
565
562
|
}
|
|
566
|
-
//
|
|
567
|
-
// not bindings; only pattern-bearing header children can bind names.
|
|
563
|
+
// Only pattern-bearing header children can bind names.
|
|
568
564
|
!is_body_statement_child(child.kind()) && node_can_contain_pattern_binding(child)
|
|
569
565
|
}
|
|
570
566
|
|
|
@@ -11,6 +11,20 @@ pub(crate) struct ClassKey {
|
|
|
11
11
|
pub(crate) name: String,
|
|
12
12
|
}
|
|
13
13
|
|
|
14
|
+
#[derive(Debug, Clone, PartialEq, Eq)]
|
|
15
|
+
pub(crate) enum Resolution {
|
|
16
|
+
Found(BTreeSet<ClassKey>),
|
|
17
|
+
Absent,
|
|
18
|
+
Unknown,
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
#[derive(Debug)]
|
|
22
|
+
pub(crate) struct ExportReach {
|
|
23
|
+
pub(crate) prefix: Option<String>,
|
|
24
|
+
pub(crate) combinators: Vec<DartCombinator>,
|
|
25
|
+
pub(crate) file: PathBuf,
|
|
26
|
+
}
|
|
27
|
+
|
|
14
28
|
#[derive(Debug)]
|
|
15
29
|
pub(crate) struct DeclarationResolver {
|
|
16
30
|
declarations: BTreeMap<PathBuf, BTreeSet<String>>,
|
|
@@ -88,10 +102,17 @@ impl DeclarationResolver {
|
|
|
88
102
|
}
|
|
89
103
|
|
|
90
104
|
pub(crate) fn resolve(&self, from: &Path, reference: &str) -> BTreeSet<ClassKey> {
|
|
105
|
+
match self.resolve_detailed(from, reference) {
|
|
106
|
+
Resolution::Found(classes) => classes,
|
|
107
|
+
Resolution::Absent | Resolution::Unknown => BTreeSet::new(),
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
pub(crate) fn resolve_detailed(&self, from: &Path, reference: &str) -> Resolution {
|
|
91
112
|
let reference = compact_reference(reference);
|
|
92
113
|
let segments = reference.split('.').collect::<Vec<_>>();
|
|
93
114
|
let Some(first) = segments.first().copied() else {
|
|
94
|
-
return
|
|
115
|
+
return Resolution::Absent;
|
|
95
116
|
};
|
|
96
117
|
let library = self.library_path(from);
|
|
97
118
|
let imports = self.imports.get(&library).map_or(&[][..], Vec::as_slice);
|
|
@@ -102,7 +123,7 @@ impl DeclarationResolver {
|
|
|
102
123
|
.any(|dependency| dependency.visibility.prefix.as_deref() == Some(first));
|
|
103
124
|
if has_prefixed_import {
|
|
104
125
|
if name.starts_with('_') {
|
|
105
|
-
return
|
|
126
|
+
return Resolution::Unknown;
|
|
106
127
|
}
|
|
107
128
|
return self.imported_classes(
|
|
108
129
|
imports
|
|
@@ -116,10 +137,12 @@ impl DeclarationResolver {
|
|
|
116
137
|
|
|
117
138
|
let local = self.library_classes(&library, first);
|
|
118
139
|
if !local.is_empty() {
|
|
119
|
-
return exactly_one(local).
|
|
140
|
+
return exactly_one(local).map_or(Resolution::Unknown, |class| {
|
|
141
|
+
Resolution::Found(BTreeSet::from([class]))
|
|
142
|
+
});
|
|
120
143
|
}
|
|
121
144
|
if first.starts_with('_') {
|
|
122
|
-
return
|
|
145
|
+
return Resolution::Unknown;
|
|
123
146
|
}
|
|
124
147
|
self.imported_classes(
|
|
125
148
|
imports
|
|
@@ -130,11 +153,39 @@ impl DeclarationResolver {
|
|
|
130
153
|
)
|
|
131
154
|
}
|
|
132
155
|
|
|
156
|
+
pub(crate) fn export_reach(&self, from: &Path) -> Vec<ExportReach> {
|
|
157
|
+
let library = self.library_path(from);
|
|
158
|
+
let mut reach = Vec::new();
|
|
159
|
+
for import in self.imports.get(&library).into_iter().flatten() {
|
|
160
|
+
let mut visited = BTreeSet::new();
|
|
161
|
+
let mut pending = vec![(
|
|
162
|
+
self.library_path(&import.to_path),
|
|
163
|
+
import.visibility.combinators.clone(),
|
|
164
|
+
)];
|
|
165
|
+
while let Some((file, combinators)) = pending.pop() {
|
|
166
|
+
if !visited.insert(file.clone()) {
|
|
167
|
+
continue;
|
|
168
|
+
}
|
|
169
|
+
for export in self.exports.get(&file).into_iter().flatten() {
|
|
170
|
+
let mut hop = combinators.clone();
|
|
171
|
+
hop.extend(export.visibility.combinators.iter().cloned());
|
|
172
|
+
pending.push((self.library_path(&export.to_path), hop));
|
|
173
|
+
}
|
|
174
|
+
reach.push(ExportReach {
|
|
175
|
+
prefix: import.visibility.prefix.clone(),
|
|
176
|
+
combinators,
|
|
177
|
+
file,
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
reach
|
|
182
|
+
}
|
|
183
|
+
|
|
133
184
|
fn imported_classes<'a>(
|
|
134
185
|
&self,
|
|
135
186
|
imports: impl IntoIterator<Item = &'a ResolvedDependency>,
|
|
136
187
|
name: &str,
|
|
137
|
-
) ->
|
|
188
|
+
) -> Resolution {
|
|
138
189
|
let mut candidates_by_directive = BTreeMap::<(usize, usize), BTreeSet<ClassKey>>::new();
|
|
139
190
|
for dependency in imports {
|
|
140
191
|
candidates_by_directive
|
|
@@ -151,10 +202,12 @@ impl DeclarationResolver {
|
|
|
151
202
|
matching_directives += 1;
|
|
152
203
|
resolved.extend(candidates);
|
|
153
204
|
}
|
|
154
|
-
if matching_directives
|
|
155
|
-
|
|
205
|
+
if matching_directives == 0 {
|
|
206
|
+
Resolution::Absent
|
|
207
|
+
} else if matching_directives == 1 || resolved.len() <= 1 {
|
|
208
|
+
Resolution::Found(resolved)
|
|
156
209
|
} else {
|
|
157
|
-
|
|
210
|
+
Resolution::Unknown
|
|
158
211
|
}
|
|
159
212
|
}
|
|
160
213
|
|
|
@@ -211,7 +264,7 @@ impl DeclarationResolver {
|
|
|
211
264
|
}
|
|
212
265
|
}
|
|
213
266
|
|
|
214
|
-
fn compact_reference(reference: &str) -> String {
|
|
267
|
+
pub(crate) fn compact_reference(reference: &str) -> String {
|
|
215
268
|
reference
|
|
216
269
|
.trim()
|
|
217
270
|
.trim_end_matches('?')
|
|
@@ -233,7 +286,7 @@ fn visible(name: &str, visibility: &DependencyVisibility) -> bool {
|
|
|
233
286
|
visible_through_combinators(name, &visibility.combinators)
|
|
234
287
|
}
|
|
235
288
|
|
|
236
|
-
fn visible_through_combinators(name: &str, combinators: &[DartCombinator]) -> bool {
|
|
289
|
+
pub(crate) fn visible_through_combinators(name: &str, combinators: &[DartCombinator]) -> bool {
|
|
237
290
|
let mut is_visible = true;
|
|
238
291
|
for combinator in combinators {
|
|
239
292
|
match combinator.kind {
|
package/src/workspace_scope.rs
CHANGED
|
@@ -26,12 +26,6 @@ pub enum WorkspaceScopeError {
|
|
|
26
26
|
},
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
/// Return root-normalized files belonging to selected local pub packages.
|
|
30
|
-
///
|
|
31
|
-
/// Selectors match package names and package roots relative to the scan root.
|
|
32
|
-
/// Values may contain comma-separated patterns, and `!pattern` excludes matches.
|
|
33
|
-
/// When only excludes are provided, every local package starts selected.
|
|
34
|
-
///
|
|
35
29
|
/// # Errors
|
|
36
30
|
///
|
|
37
31
|
/// Returns [`WorkspaceScopeError`] for invalid glob syntax or empty selection.
|
|
@@ -45,10 +39,7 @@ pub fn workspace_file_scope(
|
|
|
45
39
|
Ok(file_scope_for_roots(project, packages, &selected_roots))
|
|
46
40
|
}
|
|
47
41
|
|
|
48
|
-
/// Return root-normalized files
|
|
49
|
-
///
|
|
50
|
-
/// Non-Dart files inside a package still select that package. If no changed
|
|
51
|
-
/// paths belong to a local package, the returned scope is empty.
|
|
42
|
+
/// Return root-normalized files of the packages that changed paths touch.
|
|
52
43
|
#[must_use]
|
|
53
44
|
pub fn changed_workspace_file_scope(
|
|
54
45
|
project: &ScannedProject,
|