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/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
|
-
pnpm dlx dart-decimate@0.0.
|
|
93
|
+
pnpm dlx dart-decimate@0.0.78
|
|
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.78"
|
|
105
105
|
}
|
|
106
106
|
}
|
|
107
107
|
```
|
|
@@ -117,7 +117,7 @@ pnpm run dart-decimate
|
|
|
117
117
|
If you prefer Cargo, install the matching tagged source:
|
|
118
118
|
|
|
119
119
|
```bash
|
|
120
|
-
cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.
|
|
120
|
+
cargo install --git https://github.com/sgaabdu4/dart-decimate.git --tag v0.0.78 --locked
|
|
121
121
|
```
|
|
122
122
|
|
|
123
123
|
The npm release `X.Y.Z` and Cargo tag `vX.Y.Z` are verified against each other
|
|
@@ -128,7 +128,7 @@ Confirm a Cargo build's version with:
|
|
|
128
128
|
|
|
129
129
|
```bash
|
|
130
130
|
dart-decimate --version
|
|
131
|
-
# dart-decimate 0.0.
|
|
131
|
+
# dart-decimate 0.0.78
|
|
132
132
|
```
|
|
133
133
|
|
|
134
134
|
## pnpm dlx
|
|
@@ -540,7 +540,7 @@ Example shape:
|
|
|
540
540
|
{
|
|
541
541
|
"schema_version": "dart-decimate.report.v1",
|
|
542
542
|
"kind": "combined",
|
|
543
|
-
"tool": "dart-decimate 0.0.
|
|
543
|
+
"tool": "dart-decimate 0.0.78",
|
|
544
544
|
"command": "check",
|
|
545
545
|
"verdict": "fail",
|
|
546
546
|
"summary": {
|
|
@@ -556,7 +556,7 @@ Example shape:
|
|
|
556
556
|
|
|
557
557
|
The `dart-decimate.report.v1` field layout is unchanged. Its existing `tool`
|
|
558
558
|
string includes the producing version so saved reports identify the exact
|
|
559
|
-
build, for example `dart-decimate 0.0.
|
|
559
|
+
build, for example `dart-decimate 0.0.78`.
|
|
560
560
|
|
|
561
561
|
When grouped security findings hide additional occurrences, `next_steps` can
|
|
562
562
|
include `review-security-surface`, which reruns
|
|
@@ -644,7 +644,7 @@ you need the installed binary's exact list.
|
|
|
644
644
|
For a complete repository check, including discovered local packages:
|
|
645
645
|
|
|
646
646
|
```bash
|
|
647
|
-
pnpm dlx dart-decimate@0.0.
|
|
647
|
+
pnpm dlx dart-decimate@0.0.78 --strict
|
|
648
648
|
```
|
|
649
649
|
|
|
650
650
|
This runs every enabled check from the repository root. The default duplication
|
|
@@ -687,7 +687,7 @@ This repository forbids `unsafe_code`.
|
|
|
687
687
|
|
|
688
688
|
## Release Flow
|
|
689
689
|
|
|
690
|
-
Current source version: `0.0.
|
|
690
|
+
Current source version: `0.0.78`.
|
|
691
691
|
|
|
692
692
|
After the first public release, changes should go through pull requests. PRs to
|
|
693
693
|
`main` must bump both `Cargo.toml` and `package.json` above the base branch and to
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dart-decimate",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.78",
|
|
4
4
|
"description": "Rust-native codebase intelligence for Dart and Flutter module graphs.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"bin": {
|
|
@@ -55,7 +55,7 @@
|
|
|
55
55
|
"access": "public"
|
|
56
56
|
},
|
|
57
57
|
"devDependencies": {
|
|
58
|
-
"@biomejs/biome": "2.6.
|
|
58
|
+
"@biomejs/biome": "2.6.8",
|
|
59
59
|
"@types/node": "26.6.6"
|
|
60
60
|
}
|
|
61
61
|
}
|
package/src/boundaries.rs
CHANGED
|
@@ -5,6 +5,7 @@ use serde::{Deserialize, Serialize};
|
|
|
5
5
|
|
|
6
6
|
use crate::generated::is_generated_dart_path;
|
|
7
7
|
use crate::graph::normalize_against;
|
|
8
|
+
use crate::symbols::path_filters::is_library_source;
|
|
8
9
|
use crate::{BoundaryRule, Location, ScannedProject};
|
|
9
10
|
|
|
10
11
|
/// Built-in architecture boundary presets.
|
|
@@ -304,14 +305,5 @@ fn matches_pattern(pattern: &str, relative: &str) -> bool {
|
|
|
304
305
|
glob::Pattern::new(normalized).is_ok_and(|pattern| pattern.matches(relative))
|
|
305
306
|
}
|
|
306
307
|
|
|
307
|
-
fn is_library_source(root: &Path, path: &Path) -> bool {
|
|
308
|
-
path.strip_prefix(root).is_ok_and(|relative| {
|
|
309
|
-
relative
|
|
310
|
-
.components()
|
|
311
|
-
.next()
|
|
312
|
-
.is_some_and(|component| component.as_os_str() == "lib")
|
|
313
|
-
})
|
|
314
|
-
}
|
|
315
|
-
|
|
316
308
|
#[cfg(test)]
|
|
317
309
|
mod tests;
|
package/src/cli/analyze.rs
CHANGED
|
@@ -15,10 +15,38 @@ use crate::{
|
|
|
15
15
|
use super::entry_points::{entry_points_for_check, entry_points_for_dead_code};
|
|
16
16
|
use super::{CliError, CommandRequest};
|
|
17
17
|
|
|
18
|
+
fn has_package(project: &ScannedProject, request: &CommandRequest) -> Result<bool, CliError> {
|
|
19
|
+
if project
|
|
20
|
+
.root
|
|
21
|
+
.ancestors()
|
|
22
|
+
.any(|folder| folder.join("pubspec.yaml").is_file())
|
|
23
|
+
{
|
|
24
|
+
return Ok(true);
|
|
25
|
+
}
|
|
26
|
+
Ok(
|
|
27
|
+
!crate::local_pub_packages(&project.root, &request.scan_options.ignore_patterns)?
|
|
28
|
+
.is_empty(),
|
|
29
|
+
)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
fn scanned_files_under(project: &ScannedProject, scope: &Path) -> Vec<std::path::PathBuf> {
|
|
33
|
+
project
|
|
34
|
+
.files
|
|
35
|
+
.iter()
|
|
36
|
+
.map(|file| crate::graph::normalize_against(&project.root, &file.path))
|
|
37
|
+
.filter(|path| path.starts_with(scope))
|
|
38
|
+
.collect()
|
|
39
|
+
}
|
|
40
|
+
|
|
18
41
|
pub(super) fn analyze_project(
|
|
19
42
|
project: &ScannedProject,
|
|
20
43
|
request: &CommandRequest,
|
|
21
44
|
) -> Result<AnalysisResults, CliError> {
|
|
45
|
+
if request.command == ReportCommand::Check && !has_package(project, request)? {
|
|
46
|
+
return Err(CliError::NoPackage {
|
|
47
|
+
path: project.root.clone(),
|
|
48
|
+
});
|
|
49
|
+
}
|
|
22
50
|
let dead_code = analyze_project_dead_code(project, request)?;
|
|
23
51
|
|
|
24
52
|
Ok(AnalysisResults {
|
|
@@ -37,7 +65,10 @@ pub(super) fn analyze_project(
|
|
|
37
65
|
security: analyze_project_security(project, request, dead_code.as_ref())?,
|
|
38
66
|
routes: analyze_project_routes(project, request.command),
|
|
39
67
|
widgets: analyze_project_widgets(project, request.command, dead_code.as_ref())?,
|
|
40
|
-
file_scope:
|
|
68
|
+
file_scope: project
|
|
69
|
+
.scope
|
|
70
|
+
.as_ref()
|
|
71
|
+
.map(|scope| scanned_files_under(project, scope)),
|
|
41
72
|
require_suppression_reasons: missing_suppression_reasons_enabled(&request.rules),
|
|
42
73
|
dead_code,
|
|
43
74
|
})
|
|
@@ -275,8 +306,7 @@ fn analyze_project_duplicates(
|
|
|
275
306
|
) -> Result<Option<crate::DuplicateCodeReport>, CliError> {
|
|
276
307
|
match request.command {
|
|
277
308
|
ReportCommand::Check | ReportCommand::Audit | ReportCommand::Dupes => {
|
|
278
|
-
//
|
|
279
|
-
// requested detail limit only after the report has reconciled them.
|
|
309
|
+
// Apply the detail limit only after suppression and threshold accounting saw all groups.
|
|
280
310
|
let mut options = request.duplicate_options.clone();
|
|
281
311
|
options.top = None;
|
|
282
312
|
let mut report = detect_duplicates(project, &options)?;
|
package/src/cli/error.rs
CHANGED
|
@@ -44,6 +44,22 @@ pub enum CliError {
|
|
|
44
44
|
"security --top cannot be combined with --gate, --diff-file, --diff-stdin, --changed-since, or --compare"
|
|
45
45
|
)]
|
|
46
46
|
UnsupportedSecurityTopScope,
|
|
47
|
+
/// A check ran on a folder that no Dart package holds or sits under.
|
|
48
|
+
#[error(
|
|
49
|
+
"no pubspec.yaml in {path} or any folder above it, so no package was checked; run the check from the package folder, for example: cd <package folder> && dart-decimate check"
|
|
50
|
+
)]
|
|
51
|
+
NoPackage {
|
|
52
|
+
/// The scanned folder.
|
|
53
|
+
path: std::path::PathBuf,
|
|
54
|
+
},
|
|
55
|
+
/// No `--file` path names a scanned file.
|
|
56
|
+
#[error(
|
|
57
|
+
"no scanned file matches --file {files:?}; paths count from the scanned folder, so pass a path under it or run from the package folder"
|
|
58
|
+
)]
|
|
59
|
+
NoFileMatch {
|
|
60
|
+
/// The `--file` values.
|
|
61
|
+
files: Vec<std::path::PathBuf>,
|
|
62
|
+
},
|
|
47
63
|
/// Cross-language duplicate detection is JavaScript/TypeScript-specific in Fallow.
|
|
48
64
|
#[error("dupes --cross-language is not supported for Dart-only analysis")]
|
|
49
65
|
UnsupportedCrossLanguageDupes,
|
package/src/cli/list_run.rs
CHANGED
|
@@ -95,7 +95,7 @@ fn run_list_with_options<W: Write>(
|
|
|
95
95
|
conditional_environment: conditional_environment(subcommand),
|
|
96
96
|
};
|
|
97
97
|
let project = scan_project_with_options(&root, &scan_options)?;
|
|
98
|
-
let mut packages = local_pub_packages(&project.root)?;
|
|
98
|
+
let mut packages = local_pub_packages(&project.root, &config.ignore_patterns)?;
|
|
99
99
|
let project = scoped_project(subcommand, project, &mut packages, production)?;
|
|
100
100
|
let entries = entry_points_for_check(
|
|
101
101
|
&project,
|
|
@@ -224,6 +224,8 @@ fn scoped_project(
|
|
|
224
224
|
.filter(|file| scope.contains(&file.path))
|
|
225
225
|
.collect(),
|
|
226
226
|
graph: project.graph,
|
|
227
|
+
ignore_patterns: project.ignore_patterns,
|
|
228
|
+
scope: project.scope,
|
|
227
229
|
})
|
|
228
230
|
}
|
|
229
231
|
|
package/src/cli/scope_args.rs
CHANGED
|
@@ -123,11 +123,22 @@ pub(super) fn apply_report_scope(
|
|
|
123
123
|
}
|
|
124
124
|
|
|
125
125
|
if !request.file_paths.is_empty() {
|
|
126
|
+
let base = project.scope.as_deref().unwrap_or(&project.root);
|
|
126
127
|
let file_scope = request
|
|
127
128
|
.file_paths
|
|
128
129
|
.iter()
|
|
129
|
-
.map(|path| normalize_against(
|
|
130
|
+
.map(|path| normalize_against(base, path))
|
|
130
131
|
.collect::<Vec<_>>();
|
|
132
|
+
let known = project
|
|
133
|
+
.files
|
|
134
|
+
.iter()
|
|
135
|
+
.map(|file| normalize_against(&project.root, &file.path))
|
|
136
|
+
.collect::<BTreeSet<_>>();
|
|
137
|
+
if !file_scope.iter().any(|path| known.contains(path)) {
|
|
138
|
+
return Err(CliError::NoFileMatch {
|
|
139
|
+
files: request.file_paths.clone(),
|
|
140
|
+
});
|
|
141
|
+
}
|
|
131
142
|
results.file_scope = Some(intersect_scope(results.file_scope.take(), file_scope));
|
|
132
143
|
}
|
|
133
144
|
|
|
@@ -137,14 +148,14 @@ pub(super) fn apply_report_scope(
|
|
|
137
148
|
}
|
|
138
149
|
|
|
139
150
|
if !request.workspace_patterns.is_empty() {
|
|
140
|
-
let packages = local_pub_packages(&project.root)?;
|
|
151
|
+
let packages = local_pub_packages(&project.root, &project.ignore_patterns)?;
|
|
141
152
|
let workspace_scope =
|
|
142
153
|
workspace_file_scope(project, &packages, &request.workspace_patterns)?;
|
|
143
154
|
results.file_scope = Some(intersect_scope(results.file_scope.take(), workspace_scope));
|
|
144
155
|
}
|
|
145
156
|
|
|
146
157
|
if let Some(base) = &request.changed_workspaces {
|
|
147
|
-
let packages = local_pub_packages(&project.root)?;
|
|
158
|
+
let packages = local_pub_packages(&project.root, &project.ignore_patterns)?;
|
|
148
159
|
let changed = changed_files(&project.root, base)?;
|
|
149
160
|
let workspace_scope = changed_workspace_file_scope(project, &packages, &changed);
|
|
150
161
|
results.file_scope = Some(intersect_scope(results.file_scope.take(), workspace_scope));
|
package/src/config.rs
CHANGED
|
@@ -57,7 +57,7 @@ pub struct DartDecimateConfig {
|
|
|
57
57
|
pub boundary_calls: Vec<BoundaryCallRule>,
|
|
58
58
|
/// Declarative policy pack paths.
|
|
59
59
|
pub policy_packs: Vec<PathBuf>,
|
|
60
|
-
/// Glob patterns excluded from Dart file discovery.
|
|
60
|
+
/// Glob patterns excluded from Dart file and pubspec discovery.
|
|
61
61
|
pub ignore_patterns: Vec<String>,
|
|
62
62
|
/// Pub dependency names ignored by dependency hygiene checks.
|
|
63
63
|
pub ignore_dependencies: Vec<String>,
|
|
@@ -97,8 +97,7 @@ pub struct DuplicateConfig {
|
|
|
97
97
|
/// Minimum normalized tokens per clone window.
|
|
98
98
|
#[serde(default, alias = "minTokens")]
|
|
99
99
|
pub min_tokens: Option<usize>,
|
|
100
|
-
/// Minimum normalized lines per clone window
|
|
101
|
-
/// this to satisfy `min_tokens`.
|
|
100
|
+
/// Minimum normalized lines per clone window.
|
|
102
101
|
#[serde(default, alias = "minLines")]
|
|
103
102
|
pub min_lines: Option<usize>,
|
|
104
103
|
/// Minimum clone instances per group.
|
|
@@ -212,12 +211,9 @@ pub enum ConfigError {
|
|
|
212
211
|
Rule(#[from] RuleError),
|
|
213
212
|
}
|
|
214
213
|
|
|
215
|
-
/// Load Dart Decimate config discovered from `root`, or from an explicit config path.
|
|
216
|
-
///
|
|
217
214
|
/// # Errors
|
|
218
215
|
///
|
|
219
|
-
/// Returns [`ConfigError`] when an explicit config is missing, unreadable,
|
|
220
|
-
/// malformed, or contains an invalid boundary rule.
|
|
216
|
+
/// Returns [`ConfigError`] when an explicit config is missing, unreadable, malformed, or has an invalid boundary rule.
|
|
221
217
|
pub fn load_dart_decimate_config(
|
|
222
218
|
root: impl AsRef<Path>,
|
|
223
219
|
explicit: Option<&Path>,
|
|
@@ -469,7 +465,15 @@ fn config_path(root: &Path, explicit: Option<&Path>) -> Result<Option<PathBuf>,
|
|
|
469
465
|
return Err(ConfigError::NotFound { path });
|
|
470
466
|
}
|
|
471
467
|
|
|
472
|
-
|
|
468
|
+
let folder = if root.join("pubspec.yaml").is_file() {
|
|
469
|
+
root
|
|
470
|
+
} else {
|
|
471
|
+
root.ancestors()
|
|
472
|
+
.skip(1)
|
|
473
|
+
.find(|folder| folder.join("pubspec.yaml").is_file())
|
|
474
|
+
.unwrap_or(root)
|
|
475
|
+
};
|
|
476
|
+
Ok(config_candidates(folder)
|
|
473
477
|
.into_iter()
|
|
474
478
|
.find(|candidate| candidate.is_file()))
|
|
475
479
|
}
|
package/src/dart_parser.rs
CHANGED
|
@@ -9,10 +9,7 @@ mod test_support;
|
|
|
9
9
|
#[cfg(test)]
|
|
10
10
|
pub(crate) use test_support::track_parse_count;
|
|
11
11
|
|
|
12
|
-
/// Parsed Dart source
|
|
13
|
-
///
|
|
14
|
-
/// Tree-Sitter node byte ranges are relative to this buffer, which may be a
|
|
15
|
-
/// normalized compatibility copy when the upstream grammar lags new Dart syntax.
|
|
12
|
+
/// Parsed Dart source; node byte ranges refer to `source`, which may be a normalized copy.
|
|
16
13
|
pub(crate) struct ParsedDart<'source> {
|
|
17
14
|
tree: Tree,
|
|
18
15
|
source: Cow<'source, str>,
|
|
@@ -92,10 +89,7 @@ pub(crate) fn parse_dart_source_strict<'source>(
|
|
|
92
89
|
})
|
|
93
90
|
}
|
|
94
91
|
|
|
95
|
-
/// Parse Dart source, preferring a syntax-clean compatibility parse
|
|
96
|
-
///
|
|
97
|
-
/// Some analyzers historically tolerated partial Tree-Sitter trees. This keeps
|
|
98
|
-
/// that behavior while still letting them benefit from compatibility rewrites.
|
|
92
|
+
/// Parse Dart source, preferring a syntax-clean compatibility parse and tolerating partial trees.
|
|
99
93
|
pub(crate) fn parse_dart_source_lossy<'source>(
|
|
100
94
|
path: &Path,
|
|
101
95
|
source: &'source str,
|
|
@@ -152,11 +146,49 @@ fn normalize_modern_dart_compatibility(source: &str) -> Option<String> {
|
|
|
152
146
|
let mut output = normalized.take().unwrap_or_else(|| source.to_owned());
|
|
153
147
|
let mut changed = output != source;
|
|
154
148
|
changed |= normalize_concise_constructors(&mut output);
|
|
149
|
+
changed |= normalize_extension_type_representations(&mut output);
|
|
155
150
|
changed |= normalize_dot_shorthands(&mut output);
|
|
156
151
|
changed |= normalize_null_aware_collection_elements(&mut output);
|
|
157
152
|
changed.then_some(output)
|
|
158
153
|
}
|
|
159
154
|
|
|
155
|
+
fn normalize_extension_type_representations(source: &mut String) -> bool {
|
|
156
|
+
let mut replacements = Vec::new();
|
|
157
|
+
let mut cursor = 0;
|
|
158
|
+
|
|
159
|
+
while let Some((keyword_start, keyword)) = find_next_class_like_header(source, cursor) {
|
|
160
|
+
cursor = keyword_start + keyword.len();
|
|
161
|
+
if keyword == "type"
|
|
162
|
+
&& let Some(comma) = representation_trailing_comma(source, cursor)
|
|
163
|
+
{
|
|
164
|
+
replacements.push((comma, comma + 1, " ".to_owned()));
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
apply_text_replacements(source, replacements)
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
fn representation_trailing_comma(source: &str, after_keyword: usize) -> Option<usize> {
|
|
172
|
+
let mut cursor = skip_whitespace(source, after_keyword)?;
|
|
173
|
+
if starts_keyword(source, cursor, "const") {
|
|
174
|
+
cursor = skip_whitespace(source, cursor + "const".len())?;
|
|
175
|
+
}
|
|
176
|
+
cursor = skip_whitespace(source, identifier_end(source, cursor)?)?;
|
|
177
|
+
if source.as_bytes().get(cursor).copied() == Some(b'<') {
|
|
178
|
+
cursor = skip_whitespace(source, matching_delimiter(source, cursor, b'<', b'>')? + 1)?;
|
|
179
|
+
}
|
|
180
|
+
if source.as_bytes().get(cursor).copied() == Some(b'.') {
|
|
181
|
+
cursor = skip_whitespace(source, cursor + 1)?;
|
|
182
|
+
cursor = skip_whitespace(source, identifier_end(source, cursor)?)?;
|
|
183
|
+
}
|
|
184
|
+
if source.as_bytes().get(cursor).copied() != Some(b'(') {
|
|
185
|
+
return None;
|
|
186
|
+
}
|
|
187
|
+
let close = matching_delimiter(source, cursor, b'(', b')')?;
|
|
188
|
+
let before_close = source[..close].trim_end();
|
|
189
|
+
before_close.ends_with(',').then(|| before_close.len() - 1)
|
|
190
|
+
}
|
|
191
|
+
|
|
160
192
|
fn normalize_concise_constructors(source: &mut String) -> bool {
|
|
161
193
|
let mut replacements = Vec::new();
|
|
162
194
|
let mut cursor = 0;
|
|
@@ -713,7 +745,7 @@ fn normalize_dot_shorthands(source: &mut String) -> bool {
|
|
|
713
745
|
}
|
|
714
746
|
|
|
715
747
|
pub(crate) fn is_dot_shorthand_start(bytes: &[u8], cursor: usize) -> bool {
|
|
716
|
-
if cursor > 0 && bytes[cursor - 1]
|
|
748
|
+
if cursor > 0 && matches!(bytes[cursor - 1], b'?' | b'>') {
|
|
717
749
|
return false;
|
|
718
750
|
}
|
|
719
751
|
let Some(next) = bytes.get(cursor + 1).copied() else {
|
|
@@ -728,6 +760,9 @@ pub(crate) fn is_dot_shorthand_start(bytes: &[u8], cursor: usize) -> bool {
|
|
|
728
760
|
let Some(previous) = previous_non_whitespace_byte(bytes, cursor) else {
|
|
729
761
|
return true;
|
|
730
762
|
};
|
|
763
|
+
if previous == b'!' && is_postfix_null_assertion(bytes, cursor) {
|
|
764
|
+
return false;
|
|
765
|
+
}
|
|
731
766
|
matches!(
|
|
732
767
|
previous,
|
|
733
768
|
b'=' | b'(' | b'[' | b'{' | b',' | b':' | b'?' | b'!' | b'>' | b'|'
|
|
@@ -816,6 +851,18 @@ fn find_header_terminator(source: &str, start: usize) -> Option<(usize, u8)> {
|
|
|
816
851
|
None
|
|
817
852
|
}
|
|
818
853
|
|
|
854
|
+
fn is_postfix_null_assertion(bytes: &[u8], cursor: usize) -> bool {
|
|
855
|
+
let Some(bang) = bytes
|
|
856
|
+
.get(..cursor)
|
|
857
|
+
.and_then(|head| head.iter().rposition(|byte| !byte.is_ascii_whitespace()))
|
|
858
|
+
else {
|
|
859
|
+
return false;
|
|
860
|
+
};
|
|
861
|
+
previous_non_whitespace_byte(bytes, bang).is_some_and(|byte| {
|
|
862
|
+
byte.is_ascii_alphanumeric() || matches!(byte, b'_' | b'$' | b')' | b']')
|
|
863
|
+
})
|
|
864
|
+
}
|
|
865
|
+
|
|
819
866
|
fn previous_non_whitespace_byte(bytes: &[u8], cursor: usize) -> Option<u8> {
|
|
820
867
|
bytes
|
|
821
868
|
.get(..cursor)?
|
|
@@ -1097,6 +1144,50 @@ enum const Tone(final String label) {
|
|
|
1097
1144
|
Ok(())
|
|
1098
1145
|
}
|
|
1099
1146
|
|
|
1147
|
+
#[test]
|
|
1148
|
+
fn strict_parse_accepts_the_outside_file_forms() -> Result<(), DartParseError> {
|
|
1149
|
+
let source = "\
|
|
1150
|
+
extension type Pair._(
|
|
1151
|
+
(int first, int second) _info,
|
|
1152
|
+
) {
|
|
1153
|
+
int get first => _info.$1;
|
|
1154
|
+
}
|
|
1155
|
+
|
|
1156
|
+
@Marker('x')
|
|
1157
|
+
extension type Callback<T extends Function>._(
|
|
1158
|
+
RawCallback _raw,
|
|
1159
|
+
) implements Base<T>, RawCallback {}
|
|
1160
|
+
|
|
1161
|
+
extension type Wrapped(
|
|
1162
|
+
prefix.Raw _raw,
|
|
1163
|
+
) implements Base {}
|
|
1164
|
+
|
|
1165
|
+
extension type const Plain(int value) {}
|
|
1166
|
+
|
|
1167
|
+
class Holder {
|
|
1168
|
+
Holder? _next;
|
|
1169
|
+
int _count = 0;
|
|
1170
|
+
|
|
1171
|
+
void run(Holder? other) {
|
|
1172
|
+
_next!._poke();
|
|
1173
|
+
other?._next?._next!._poke();
|
|
1174
|
+
_next!._count = 1;
|
|
1175
|
+
}
|
|
1176
|
+
|
|
1177
|
+
void _poke() {}
|
|
1178
|
+
}
|
|
1179
|
+
";
|
|
1180
|
+
|
|
1181
|
+
let parsed = parse_dart_source_strict(Path::new("lib/types.dart"), source)?;
|
|
1182
|
+
|
|
1183
|
+
assert!(!parsed.tree().root_node().has_error());
|
|
1184
|
+
for name in ["Pair", "Callback", "Wrapped", "Plain", "_next!._poke()"] {
|
|
1185
|
+
assert!(parsed.source().contains(name), "{name}");
|
|
1186
|
+
}
|
|
1187
|
+
|
|
1188
|
+
Ok(())
|
|
1189
|
+
}
|
|
1190
|
+
|
|
1100
1191
|
#[test]
|
|
1101
1192
|
fn strict_parse_normalizes_current_dart_shorthands() -> Result<(), DartParseError> {
|
|
1102
1193
|
let source = "\
|
|
@@ -5,10 +5,11 @@ use crate::dependency_scripts::{package_used_in_tooling, shell_script_packages};
|
|
|
5
5
|
use crate::generated::is_generated_dart_path;
|
|
6
6
|
use crate::graph::resolve_local_uri;
|
|
7
7
|
use crate::package_map::PackageMap;
|
|
8
|
+
use crate::symbols::path_filters::is_library_source;
|
|
8
9
|
use crate::{DartFile, DependencyKind, Location, extract_dart_file, scan::ScannedProject};
|
|
9
10
|
|
|
10
11
|
use super::codegen::codegen_dependencies_for_file;
|
|
11
|
-
use super::usage::
|
|
12
|
+
use super::usage::DependencyUsage;
|
|
12
13
|
use super::{
|
|
13
14
|
DependencyHygieneError, DependencyHygieneReport, DependencyIssue, PrivateSrcImport, PubPackage,
|
|
14
15
|
UnlistedPackageDependency, UnusedPackageDependency, dependency_issue, discover_packages,
|
|
@@ -31,7 +32,7 @@ struct ImportUsage {
|
|
|
31
32
|
pub fn analyze_dependency_hygiene(
|
|
32
33
|
project: &ScannedProject,
|
|
33
34
|
) -> Result<DependencyHygieneReport, DependencyHygieneError> {
|
|
34
|
-
let packages = discover_packages(&project.root)?;
|
|
35
|
+
let packages = discover_packages(&project.root, &project.ignore_patterns)?;
|
|
35
36
|
let generated_runtime_files = reachable_generated_runtime_files(project, &packages)?;
|
|
36
37
|
let mut imports = collect_import_usage(project, &packages, &generated_runtime_files);
|
|
37
38
|
let mut unused_dependencies = unused_dependencies(&packages, &imports.used_by_package);
|
|
@@ -173,7 +174,7 @@ fn record_directive(
|
|
|
173
174
|
return;
|
|
174
175
|
}
|
|
175
176
|
|
|
176
|
-
if
|
|
177
|
+
if is_library_source(&owner.root, file_path) {
|
|
177
178
|
usage
|
|
178
179
|
.library_imports
|
|
179
180
|
.entry(owner.root.clone())
|
|
@@ -5,9 +5,17 @@ use crate::scan::{IgnoreMatcher, project_walk};
|
|
|
5
5
|
|
|
6
6
|
use super::{DependencyHygieneError, PubPackage, read_package};
|
|
7
7
|
|
|
8
|
-
pub(super) fn discover_packages(
|
|
8
|
+
pub(super) fn discover_packages(
|
|
9
|
+
root: &Path,
|
|
10
|
+
ignore_patterns: &[String],
|
|
11
|
+
) -> Result<Vec<PubPackage>, DependencyHygieneError> {
|
|
12
|
+
let ignore_matcher =
|
|
13
|
+
IgnoreMatcher::new(ignore_patterns).map_err(|error| DependencyHygieneError::ReadDir {
|
|
14
|
+
path: root.to_path_buf(),
|
|
15
|
+
source: std::io::Error::other(error),
|
|
16
|
+
})?;
|
|
9
17
|
let mut pubspecs = Vec::new();
|
|
10
|
-
for entry in project_walk(root, root, &
|
|
18
|
+
for entry in project_walk(root, root, &ignore_matcher) {
|
|
11
19
|
let entry = entry.map_err(|error| DependencyHygieneError::ReadDir {
|
|
12
20
|
path: root.to_path_buf(),
|
|
13
21
|
source: std::io::Error::other(error),
|
|
@@ -8,10 +8,14 @@ use serde_json::Value as JsonValue;
|
|
|
8
8
|
pub(super) fn flutter_metadata_dependencies(
|
|
9
9
|
package_root: &Path,
|
|
10
10
|
pubspec: &Value,
|
|
11
|
+
application: bool,
|
|
11
12
|
) -> BTreeSet<String> {
|
|
12
13
|
let mut dependencies = BTreeSet::new();
|
|
13
14
|
if is_flutter_package(pubspec) {
|
|
14
15
|
dependencies.insert("cupertino_icons".to_owned());
|
|
16
|
+
if application {
|
|
17
|
+
dependencies.insert("flutter".to_owned());
|
|
18
|
+
}
|
|
15
19
|
}
|
|
16
20
|
if let Some(flutter) = mapping_field(pubspec, "flutter") {
|
|
17
21
|
collect_package_asset_references(flutter, &mut dependencies);
|
|
@@ -50,7 +50,7 @@ import 'package:collection/collection.dart';\n\
|
|
|
50
50
|
void main() {}\n",
|
|
51
51
|
)?;
|
|
52
52
|
let project = scan_project(fixture.path())?;
|
|
53
|
-
let packages = discover_packages(&project.root)?;
|
|
53
|
+
let packages = discover_packages(&project.root, &[])?;
|
|
54
54
|
assert_eq!(packages.len(), 1);
|
|
55
55
|
assert_eq!(packages[0].name, "app");
|
|
56
56
|
assert_eq!(packages[0].dependencies.len(), 3);
|
|
@@ -291,7 +291,7 @@ dependency_overrides:\n stale: ^1.0.0\n",
|
|
|
291
291
|
"import 'package:http/http.dart';\nvoid main() {}\n",
|
|
292
292
|
)?;
|
|
293
293
|
let project = scan_project(fixture.path())?;
|
|
294
|
-
let packages = discover_packages(&project.root)?;
|
|
294
|
+
let packages = discover_packages(&project.root, &[])?;
|
|
295
295
|
assert_eq!(packages.len(), 1);
|
|
296
296
|
assert_eq!(
|
|
297
297
|
packages[0]
|
|
@@ -578,7 +578,7 @@ fn finds_declared_package_dependencies_for_trace() -> Result<(), Box<dyn std::er
|
|
|
578
578
|
dependencies:\n collection: ^1.18.0\n",
|
|
579
579
|
)?;
|
|
580
580
|
|
|
581
|
-
let declarations = declared_package_dependencies(fixture.path(), "collection")?;
|
|
581
|
+
let declarations = declared_package_dependencies(fixture.path(), &[], "collection")?;
|
|
582
582
|
|
|
583
583
|
assert_eq!(declarations.len(), 1);
|
|
584
584
|
assert_eq!(declarations[0].package, "app");
|
|
@@ -651,7 +651,7 @@ fn skips_nested_checkout_packages_and_sources() -> Result<(), Box<dyn std::error
|
|
|
651
651
|
write(&fixture, "worktrees/wt1/test/main_test.dart", app_main)?;
|
|
652
652
|
let project = scan_project(fixture.path())?;
|
|
653
653
|
|
|
654
|
-
let packages = discover_packages(&project.root)?;
|
|
654
|
+
let packages = discover_packages(&project.root, &[])?;
|
|
655
655
|
let report = analyze_dependency_hygiene(&project)?;
|
|
656
656
|
|
|
657
657
|
assert_eq!(
|
|
@@ -685,7 +685,7 @@ fn skips_gitignored_nested_package_dependencies() -> Result<(), Box<dyn std::err
|
|
|
685
685
|
)?;
|
|
686
686
|
let project = scan_project(fixture.path())?;
|
|
687
687
|
|
|
688
|
-
let packages = discover_packages(&project.root)?;
|
|
688
|
+
let packages = discover_packages(&project.root, &[])?;
|
|
689
689
|
let report = analyze_dependency_hygiene(&project)?;
|
|
690
690
|
|
|
691
691
|
assert_eq!(packages.len(), 1);
|
|
@@ -24,15 +24,6 @@ impl DependencyUsage {
|
|
|
24
24
|
}
|
|
25
25
|
}
|
|
26
26
|
|
|
27
|
-
pub(super) fn is_library_file(package_root: &Path, path: &Path) -> bool {
|
|
28
|
-
path.strip_prefix(package_root).is_ok_and(|relative| {
|
|
29
|
-
matches!(
|
|
30
|
-
relative.components().next(),
|
|
31
|
-
Some(std::path::Component::Normal(name)) if name == "lib"
|
|
32
|
-
)
|
|
33
|
-
})
|
|
34
|
-
}
|
|
35
|
-
|
|
36
27
|
pub(super) fn allows_dev_dependency(package_root: &Path, path: &Path) -> bool {
|
|
37
28
|
let relative = path.strip_prefix(package_root).unwrap_or(path);
|
|
38
29
|
!matches!(
|
package/src/dependencies.rs
CHANGED
|
@@ -208,9 +208,10 @@ pub enum DependencyHygieneError {
|
|
|
208
208
|
/// Returns [`DependencyHygieneError`] if pubspec discovery or parsing fails.
|
|
209
209
|
pub fn declared_package_dependencies(
|
|
210
210
|
root: &Path,
|
|
211
|
+
ignore_patterns: &[String],
|
|
211
212
|
dependency: &str,
|
|
212
213
|
) -> Result<Vec<DeclaredPackageDependency>, DependencyHygieneError> {
|
|
213
|
-
let packages = discover_packages(root)?;
|
|
214
|
+
let packages = discover_packages(root, ignore_patterns)?;
|
|
214
215
|
let mut declarations = Vec::new();
|
|
215
216
|
for package in packages {
|
|
216
217
|
for declared in package
|
|
@@ -248,8 +249,11 @@ pub fn declared_package_dependencies(
|
|
|
248
249
|
/// # Errors
|
|
249
250
|
///
|
|
250
251
|
/// Returns [`DependencyHygieneError`] if pubspec discovery or parsing fails.
|
|
251
|
-
pub fn local_pub_packages(
|
|
252
|
-
|
|
252
|
+
pub fn local_pub_packages(
|
|
253
|
+
root: &Path,
|
|
254
|
+
ignore_patterns: &[String],
|
|
255
|
+
) -> Result<Vec<LocalPubPackage>, DependencyHygieneError> {
|
|
256
|
+
discover_packages(root, ignore_patterns).map(|packages| {
|
|
253
257
|
packages
|
|
254
258
|
.into_iter()
|
|
255
259
|
.map(|package| LocalPubPackage {
|
|
@@ -298,8 +302,8 @@ pub(crate) struct PackageScope {
|
|
|
298
302
|
pub(crate) application: bool,
|
|
299
303
|
}
|
|
300
304
|
|
|
301
|
-
pub(crate) fn package_scopes(root: &Path) -> Vec<PackageScope> {
|
|
302
|
-
discover_packages(root)
|
|
305
|
+
pub(crate) fn package_scopes(root: &Path, ignore_patterns: &[String]) -> Vec<PackageScope> {
|
|
306
|
+
discover_packages(root, ignore_patterns)
|
|
303
307
|
.unwrap_or_default()
|
|
304
308
|
.into_iter()
|
|
305
309
|
.map(|package| PackageScope {
|
|
@@ -401,10 +405,11 @@ pub(super) fn read_package(path: &Path) -> Result<Option<PubPackage>, Dependency
|
|
|
401
405
|
.parent()
|
|
402
406
|
.map_or_else(|| PathBuf::from("."), normalize_path);
|
|
403
407
|
let overrides = read_pubspec_overrides(&root)?;
|
|
404
|
-
let
|
|
408
|
+
let application = is_application(&value, &root, name);
|
|
409
|
+
let flutter_metadata_dependencies =
|
|
410
|
+
flutter_usage::flutter_metadata_dependencies(&root, &value, application);
|
|
405
411
|
|
|
406
412
|
let needed_packages = package_graph::needed_packages(&root, name);
|
|
407
|
-
let application = is_application(&value, &root, name);
|
|
408
413
|
|
|
409
414
|
Ok(Some(PubPackage {
|
|
410
415
|
name: name.to_owned(),
|