dart-decimate 0.0.8 → 0.0.10
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 +43 -58
- package/package.json +1 -1
- package/src/cli/analyze.rs +6 -3
- package/src/cli/entry_points.rs +18 -2
- package/src/cli/list_run.rs +1 -0
- package/src/cli/tests.rs +74 -0
- package/src/config/rules.rs +50 -13
- package/src/config.rs +3 -2
- package/src/dependencies/analyze.rs +7 -1
- package/src/dependencies/tests.rs +29 -0
- package/src/dependencies.rs +19 -0
- package/src/dependency_scripts.rs +2 -0
- package/src/dupes/packages.rs +71 -0
- package/src/dupes/tests.rs +60 -0
- package/src/dupes.rs +56 -13
- package/src/extract/reference_tests.rs +106 -0
- package/src/extract/references.rs +264 -2
- package/src/extract/tests.rs +25 -0
- package/src/extract.rs +6 -3
- package/src/generated.rs +96 -3
- package/src/graph/package_config_tests.rs +123 -0
- package/src/graph/tests.rs +125 -0
- package/src/graph.rs +6 -5
- package/src/output/duplication_findings.rs +2 -2
- package/src/output/feature_flag_findings.rs +63 -1
- package/src/output/graph_findings.rs +23 -21
- package/src/output/security_findings.rs +15 -2
- package/src/output/tests.rs +104 -1
- package/src/package_map.rs +220 -28
- package/src/routes.rs +6 -1
- package/src/scan.rs +15 -5
- package/src/security/detect.rs +140 -6
- package/src/security/tests.rs +96 -0
- package/src/trace.rs +1 -1
package/src/generated.rs
CHANGED
|
@@ -10,9 +10,12 @@ pub(crate) const GENERATED_DART_SUFFIXES: &[&str] = &[
|
|
|
10
10
|
|
|
11
11
|
#[must_use]
|
|
12
12
|
pub(crate) fn is_generated_dart_path(path: &Path) -> bool {
|
|
13
|
-
path.file_name()
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
let Some(file_name) = path.file_name().and_then(|name| name.to_str()) else {
|
|
14
|
+
return false;
|
|
15
|
+
};
|
|
16
|
+
is_generated_dart_file_name(file_name)
|
|
17
|
+
|| is_flutter_gen_l10n_path(path, file_name)
|
|
18
|
+
|| is_flutterfire_options_path(path)
|
|
16
19
|
}
|
|
17
20
|
|
|
18
21
|
#[must_use]
|
|
@@ -22,6 +25,65 @@ pub(crate) fn is_generated_dart_file_name(name: &str) -> bool {
|
|
|
22
25
|
.any(|suffix| name.ends_with(suffix))
|
|
23
26
|
}
|
|
24
27
|
|
|
28
|
+
fn is_flutter_gen_l10n_path(path: &Path, file_name: &str) -> bool {
|
|
29
|
+
(file_name == "app_localizations.dart"
|
|
30
|
+
|| file_name
|
|
31
|
+
.strip_prefix("app_localizations_")
|
|
32
|
+
.is_some_and(is_flutter_gen_l10n_locale_file))
|
|
33
|
+
&& path.components().any(|component| {
|
|
34
|
+
matches!(
|
|
35
|
+
component.as_os_str().to_str(),
|
|
36
|
+
Some("l10n" | "gen_l10n" | "generated")
|
|
37
|
+
)
|
|
38
|
+
})
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
fn is_flutter_gen_l10n_locale_file(name: &str) -> bool {
|
|
42
|
+
let Some(locale) = name.strip_suffix(".dart") else {
|
|
43
|
+
return false;
|
|
44
|
+
};
|
|
45
|
+
let parts = locale.split('_').collect::<Vec<_>>();
|
|
46
|
+
match parts.as_slice() {
|
|
47
|
+
[language] => is_language_subtag(language),
|
|
48
|
+
[language, script_or_region] => {
|
|
49
|
+
is_language_subtag(language)
|
|
50
|
+
&& (is_script_subtag(script_or_region) || is_region_subtag(script_or_region))
|
|
51
|
+
}
|
|
52
|
+
[language, script, region] => {
|
|
53
|
+
is_language_subtag(language) && is_script_subtag(script) && is_region_subtag(region)
|
|
54
|
+
}
|
|
55
|
+
_ => false,
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
fn is_language_subtag(part: &str) -> bool {
|
|
60
|
+
matches!(part.len(), 2 | 3) && part.bytes().all(|byte| byte.is_ascii_lowercase())
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fn is_script_subtag(part: &str) -> bool {
|
|
64
|
+
part.len() == 4
|
|
65
|
+
&& part.bytes().enumerate().all(|(index, byte)| match index {
|
|
66
|
+
0 => byte.is_ascii_uppercase(),
|
|
67
|
+
_ => byte.is_ascii_lowercase(),
|
|
68
|
+
})
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fn is_region_subtag(part: &str) -> bool {
|
|
72
|
+
(part.len() == 2 && part.bytes().all(|byte| byte.is_ascii_uppercase()))
|
|
73
|
+
|| (part.len() == 3 && part.bytes().all(|byte| byte.is_ascii_digit()))
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
#[must_use]
|
|
77
|
+
pub(crate) fn is_flutterfire_options_path(path: &Path) -> bool {
|
|
78
|
+
path.file_name()
|
|
79
|
+
.and_then(|name| name.to_str())
|
|
80
|
+
.is_some_and(|file_name| file_name == "firebase_options.dart")
|
|
81
|
+
&& path
|
|
82
|
+
.parent()
|
|
83
|
+
.and_then(|parent| parent.file_name())
|
|
84
|
+
.is_some_and(|parent| parent == "lib")
|
|
85
|
+
}
|
|
86
|
+
|
|
25
87
|
#[cfg(test)]
|
|
26
88
|
mod tests {
|
|
27
89
|
use std::path::Path;
|
|
@@ -50,4 +112,35 @@ mod tests {
|
|
|
50
112
|
assert!(!is_generated_dart_file_name(file_name), "{file_name}");
|
|
51
113
|
}
|
|
52
114
|
}
|
|
115
|
+
|
|
116
|
+
#[test]
|
|
117
|
+
fn recognizes_flutter_generated_entry_files() {
|
|
118
|
+
for path in [
|
|
119
|
+
Path::new("lib/l10n/app_localizations.dart"),
|
|
120
|
+
Path::new("lib/l10n/app_localizations_en.dart"),
|
|
121
|
+
Path::new("lib/l10n/app_localizations_en_US.dart"),
|
|
122
|
+
Path::new("lib/l10n/app_localizations_zh_Hant.dart"),
|
|
123
|
+
Path::new("lib/l10n/app_localizations_sr_Latn_RS.dart"),
|
|
124
|
+
Path::new("lib/l10n/app_localizations_es_419.dart"),
|
|
125
|
+
Path::new("lib/gen_l10n/app_localizations_es.dart"),
|
|
126
|
+
Path::new("lib/firebase_options.dart"),
|
|
127
|
+
Path::new("packages/foo/lib/firebase_options.dart"),
|
|
128
|
+
] {
|
|
129
|
+
assert!(is_generated_dart_path(path), "{}", path.display());
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
#[test]
|
|
134
|
+
fn rejects_handwritten_app_localizations_sources() {
|
|
135
|
+
for path in [
|
|
136
|
+
Path::new("lib/l10n/app_localizations_repository.dart"),
|
|
137
|
+
Path::new("lib/l10n/app_localizations_en_US_helper.dart"),
|
|
138
|
+
Path::new("lib/l10n/app_localizations_.dart"),
|
|
139
|
+
Path::new("lib/l10n/app_localizations_en-us.dart"),
|
|
140
|
+
Path::new("lib/src/firebase_options.dart"),
|
|
141
|
+
Path::new("packages/foo/lib/config/firebase_options.dart"),
|
|
142
|
+
] {
|
|
143
|
+
assert!(!is_generated_dart_path(path), "{}", path.display());
|
|
144
|
+
}
|
|
145
|
+
}
|
|
53
146
|
}
|
|
@@ -64,6 +64,113 @@ fn resolves_package_imports_using_ancestor_package_config_from_member_root()
|
|
|
64
64
|
Ok(())
|
|
65
65
|
}
|
|
66
66
|
|
|
67
|
+
#[test]
|
|
68
|
+
fn nested_pubspec_missing_path_dependency_does_not_use_ancestor_package_config()
|
|
69
|
+
-> Result<(), Box<dyn std::error::Error>> {
|
|
70
|
+
let fixture = tempfile::tempdir()?;
|
|
71
|
+
write(&fixture, "pubspec.yaml", "name: app\n")?;
|
|
72
|
+
write(&fixture, "functions/worker/pubspec.yaml", "name: worker\n")?;
|
|
73
|
+
write(&fixture, "packages/shared/pubspec.yaml", "name: shared\n")?;
|
|
74
|
+
write(
|
|
75
|
+
&fixture,
|
|
76
|
+
".dart_tool/package_config.json",
|
|
77
|
+
r#"{
|
|
78
|
+
"configVersion": 2,
|
|
79
|
+
"packages": [
|
|
80
|
+
{"name": "app", "rootUri": "../", "packageUri": "lib/"},
|
|
81
|
+
{"name": "shared", "rootUri": "../packages/shared", "packageUri": "lib/"}
|
|
82
|
+
]
|
|
83
|
+
}
|
|
84
|
+
"#,
|
|
85
|
+
)?;
|
|
86
|
+
let worker = dart_file(
|
|
87
|
+
fixture.path().join("functions/worker/lib/worker.dart"),
|
|
88
|
+
"package:shared/shared.dart",
|
|
89
|
+
);
|
|
90
|
+
let shared = empty_dart_file(fixture.path().join("packages/shared/lib/shared.dart"));
|
|
91
|
+
|
|
92
|
+
let graph = build_module_graph(fixture.path(), &[worker, shared])?;
|
|
93
|
+
|
|
94
|
+
assert_eq!(graph.edge_count(), 0);
|
|
95
|
+
assert!(graph.unresolved().is_empty());
|
|
96
|
+
|
|
97
|
+
Ok(())
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
#[test]
|
|
101
|
+
fn nested_pubspec_missing_path_dependency_ignores_unowned_nested_pubspec()
|
|
102
|
+
-> Result<(), Box<dyn std::error::Error>> {
|
|
103
|
+
let fixture = tempfile::tempdir()?;
|
|
104
|
+
write(&fixture, "pubspec.yaml", "name: app\n")?;
|
|
105
|
+
write(&fixture, "functions/worker/pubspec.yaml", "name: worker\n")?;
|
|
106
|
+
write(&fixture, "functions/shared/pubspec.yaml", "name: shared\n")?;
|
|
107
|
+
write(
|
|
108
|
+
&fixture,
|
|
109
|
+
".dart_tool/package_config.json",
|
|
110
|
+
r#"{
|
|
111
|
+
"configVersion": 2,
|
|
112
|
+
"packages": [
|
|
113
|
+
{"name": "app", "rootUri": "../", "packageUri": "lib/"}
|
|
114
|
+
]
|
|
115
|
+
}
|
|
116
|
+
"#,
|
|
117
|
+
)?;
|
|
118
|
+
let worker = dart_file(
|
|
119
|
+
fixture.path().join("functions/worker/lib/worker.dart"),
|
|
120
|
+
"package:shared/shared.dart",
|
|
121
|
+
);
|
|
122
|
+
let shared = empty_dart_file(fixture.path().join("functions/shared/lib/shared.dart"));
|
|
123
|
+
|
|
124
|
+
let graph = build_module_graph(fixture.path(), &[worker, shared])?;
|
|
125
|
+
|
|
126
|
+
assert_eq!(graph.edge_count(), 0);
|
|
127
|
+
assert!(graph.unresolved().is_empty());
|
|
128
|
+
|
|
129
|
+
Ok(())
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
#[test]
|
|
133
|
+
fn nested_pubspec_path_dependency_resolves_before_ancestor_package_config()
|
|
134
|
+
-> Result<(), Box<dyn std::error::Error>> {
|
|
135
|
+
let fixture = tempfile::tempdir()?;
|
|
136
|
+
write(&fixture, "pubspec.yaml", "name: app\n")?;
|
|
137
|
+
write(
|
|
138
|
+
&fixture,
|
|
139
|
+
"functions/worker/pubspec.yaml",
|
|
140
|
+
"name: worker\ndependencies:\n shared:\n path: ../shared\n",
|
|
141
|
+
)?;
|
|
142
|
+
write(&fixture, "functions/shared/pubspec.yaml", "name: shared\n")?;
|
|
143
|
+
write(&fixture, "packages/shared/pubspec.yaml", "name: shared\n")?;
|
|
144
|
+
write(
|
|
145
|
+
&fixture,
|
|
146
|
+
".dart_tool/package_config.json",
|
|
147
|
+
r#"{
|
|
148
|
+
"configVersion": 2,
|
|
149
|
+
"packages": [
|
|
150
|
+
{"name": "app", "rootUri": "../", "packageUri": "lib/"},
|
|
151
|
+
{"name": "shared", "rootUri": "../packages/shared", "packageUri": "lib/"}
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
"#,
|
|
155
|
+
)?;
|
|
156
|
+
let worker = dart_file(
|
|
157
|
+
fixture.path().join("functions/worker/lib/worker.dart"),
|
|
158
|
+
"package:shared/shared.dart",
|
|
159
|
+
);
|
|
160
|
+
let local_shared = empty_dart_file(fixture.path().join("functions/shared/lib/shared.dart"));
|
|
161
|
+
let configured_shared = empty_dart_file(fixture.path().join("packages/shared/lib/shared.dart"));
|
|
162
|
+
|
|
163
|
+
let graph = build_module_graph(fixture.path(), &[worker, local_shared, configured_shared])?;
|
|
164
|
+
|
|
165
|
+
assert_eq!(graph.edge_count(), 1);
|
|
166
|
+
assert_eq!(
|
|
167
|
+
strip_root(fixture.path(), &graph.dependencies()[0].to_path),
|
|
168
|
+
PathBuf::from("functions/shared/lib/shared.dart")
|
|
169
|
+
);
|
|
170
|
+
|
|
171
|
+
Ok(())
|
|
172
|
+
}
|
|
173
|
+
|
|
67
174
|
fn dart_file(path: PathBuf, import_uri: &str) -> DartFile {
|
|
68
175
|
DartFile {
|
|
69
176
|
path,
|
|
@@ -87,6 +194,22 @@ fn dart_file(path: PathBuf, import_uri: &str) -> DartFile {
|
|
|
87
194
|
}
|
|
88
195
|
}
|
|
89
196
|
|
|
197
|
+
fn empty_dart_file(path: PathBuf) -> DartFile {
|
|
198
|
+
DartFile {
|
|
199
|
+
path,
|
|
200
|
+
library: None,
|
|
201
|
+
part_of: None,
|
|
202
|
+
imports: Vec::new(),
|
|
203
|
+
exports: Vec::new(),
|
|
204
|
+
parts: Vec::new(),
|
|
205
|
+
declarations: Vec::new(),
|
|
206
|
+
members: Vec::new(),
|
|
207
|
+
references: Vec::new(),
|
|
208
|
+
signature_references: Vec::new(),
|
|
209
|
+
routes: Vec::new(),
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
|
|
90
213
|
fn strip_root(root: &Path, path: &Path) -> PathBuf {
|
|
91
214
|
path.strip_prefix(root).unwrap_or(path).to_path_buf()
|
|
92
215
|
}
|
package/src/graph/tests.rs
CHANGED
|
@@ -377,6 +377,131 @@ fn package_config_hosted_entries_remain_external() -> Result<(), Box<dyn std::er
|
|
|
377
377
|
Ok(())
|
|
378
378
|
}
|
|
379
379
|
|
|
380
|
+
#[test]
|
|
381
|
+
fn package_config_prevents_nested_same_name_fallback() -> Result<(), Box<dyn std::error::Error>> {
|
|
382
|
+
let fixture = Fixture::new()?;
|
|
383
|
+
fixture.write(
|
|
384
|
+
"pubspec.yaml",
|
|
385
|
+
"name: app\ndependencies:\n shared: ^1.0.0\n",
|
|
386
|
+
)?;
|
|
387
|
+
fixture.write("functions/a/shared/pubspec.yaml", "name: shared\n")?;
|
|
388
|
+
fixture.write(
|
|
389
|
+
".dart_tool/package_config.json",
|
|
390
|
+
r#"{
|
|
391
|
+
"configVersion": 2,
|
|
392
|
+
"packages": [
|
|
393
|
+
{"name": "app", "rootUri": "../", "packageUri": "lib/"},
|
|
394
|
+
{"name": "shared", "rootUri": "file:///tmp/.pub-cache/hosted/shared-1.0.0", "packageUri": "lib/"}
|
|
395
|
+
]
|
|
396
|
+
}
|
|
397
|
+
"#,
|
|
398
|
+
)?;
|
|
399
|
+
let main = fixture.file(
|
|
400
|
+
"lib/main.dart",
|
|
401
|
+
vec![import("package:shared/shared.dart")],
|
|
402
|
+
vec![],
|
|
403
|
+
);
|
|
404
|
+
let nested = fixture.file("functions/a/shared/lib/shared.dart", vec![], vec![]);
|
|
405
|
+
|
|
406
|
+
let graph = build_module_graph(fixture.root(), &[main, nested])?;
|
|
407
|
+
|
|
408
|
+
assert_eq!(graph.edge_count(), 0);
|
|
409
|
+
assert!(graph.unresolved().is_empty());
|
|
410
|
+
|
|
411
|
+
Ok(())
|
|
412
|
+
}
|
|
413
|
+
|
|
414
|
+
#[test]
|
|
415
|
+
fn package_config_owned_import_missing_from_config_ignores_nested_pubspec()
|
|
416
|
+
-> Result<(), Box<dyn std::error::Error>> {
|
|
417
|
+
let fixture = Fixture::new()?;
|
|
418
|
+
fixture.write("pubspec.yaml", "name: app\n")?;
|
|
419
|
+
fixture.write("functions/shared/pubspec.yaml", "name: shared\n")?;
|
|
420
|
+
fixture.write(
|
|
421
|
+
".dart_tool/package_config.json",
|
|
422
|
+
r#"{
|
|
423
|
+
"configVersion": 2,
|
|
424
|
+
"packages": [
|
|
425
|
+
{"name": "app", "rootUri": "../", "packageUri": "lib/"}
|
|
426
|
+
]
|
|
427
|
+
}
|
|
428
|
+
"#,
|
|
429
|
+
)?;
|
|
430
|
+
let main = fixture.file(
|
|
431
|
+
"lib/main.dart",
|
|
432
|
+
vec![import("package:shared/shared.dart")],
|
|
433
|
+
vec![],
|
|
434
|
+
);
|
|
435
|
+
let nested = fixture.file("functions/shared/lib/shared.dart", vec![], vec![]);
|
|
436
|
+
|
|
437
|
+
let graph = build_module_graph(fixture.root(), &[main, nested])?;
|
|
438
|
+
|
|
439
|
+
assert_eq!(graph.edge_count(), 0);
|
|
440
|
+
assert!(graph.unresolved().is_empty());
|
|
441
|
+
|
|
442
|
+
Ok(())
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
#[test]
|
|
446
|
+
fn package_config_ignores_malformed_unowned_nested_pubspec()
|
|
447
|
+
-> Result<(), Box<dyn std::error::Error>> {
|
|
448
|
+
let fixture = Fixture::new()?;
|
|
449
|
+
fixture.write("pubspec.yaml", "name: app\n")?;
|
|
450
|
+
fixture.write("fixtures/bad/pubspec.yaml", "name: [\n")?;
|
|
451
|
+
fixture.write(
|
|
452
|
+
".dart_tool/package_config.json",
|
|
453
|
+
r#"{
|
|
454
|
+
"configVersion": 2,
|
|
455
|
+
"packages": [
|
|
456
|
+
{"name": "app", "rootUri": "../", "packageUri": "lib/"}
|
|
457
|
+
]
|
|
458
|
+
}
|
|
459
|
+
"#,
|
|
460
|
+
)?;
|
|
461
|
+
let main = fixture.file("lib/main.dart", vec![], vec![]);
|
|
462
|
+
|
|
463
|
+
let graph = build_module_graph(fixture.root(), &[main])?;
|
|
464
|
+
|
|
465
|
+
assert_eq!(graph.package_names(), vec!["app"]);
|
|
466
|
+
assert_eq!(graph.edge_count(), 0);
|
|
467
|
+
|
|
468
|
+
Ok(())
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
#[test]
|
|
472
|
+
fn package_config_keeps_nested_self_imports_local() -> Result<(), Box<dyn std::error::Error>> {
|
|
473
|
+
let fixture = Fixture::new()?;
|
|
474
|
+
fixture.write("pubspec.yaml", "name: app\n")?;
|
|
475
|
+
fixture.write("functions/a/shared/pubspec.yaml", "name: shared\n")?;
|
|
476
|
+
fixture.write(
|
|
477
|
+
".dart_tool/package_config.json",
|
|
478
|
+
r#"{
|
|
479
|
+
"configVersion": 2,
|
|
480
|
+
"packages": [
|
|
481
|
+
{"name": "app", "rootUri": "../", "packageUri": "lib/"},
|
|
482
|
+
{"name": "shared", "rootUri": "file:///tmp/.pub-cache/hosted/shared-1.0.0", "packageUri": "lib/"}
|
|
483
|
+
]
|
|
484
|
+
}
|
|
485
|
+
"#,
|
|
486
|
+
)?;
|
|
487
|
+
let main = fixture.file(
|
|
488
|
+
"functions/a/shared/lib/main.dart",
|
|
489
|
+
vec![import("package:shared/src/foo.dart")],
|
|
490
|
+
vec![],
|
|
491
|
+
);
|
|
492
|
+
let foo = fixture.file("functions/a/shared/lib/src/foo.dart", vec![], vec![]);
|
|
493
|
+
|
|
494
|
+
let graph = build_module_graph(fixture.root(), &[main, foo])?;
|
|
495
|
+
|
|
496
|
+
assert_eq!(graph.edge_count(), 1);
|
|
497
|
+
assert_eq!(
|
|
498
|
+
strip_root(fixture.root(), &graph.dependencies()[0].to_path),
|
|
499
|
+
"functions/a/shared/lib/src/foo.dart"
|
|
500
|
+
);
|
|
501
|
+
|
|
502
|
+
Ok(())
|
|
503
|
+
}
|
|
504
|
+
|
|
380
505
|
#[test]
|
|
381
506
|
fn package_config_local_missing_target_is_unresolved() -> Result<(), Box<dyn std::error::Error>> {
|
|
382
507
|
let fixture = Fixture::new()?;
|
package/src/graph.rs
CHANGED
|
@@ -271,13 +271,14 @@ pub enum GraphError {
|
|
|
271
271
|
/// Build a directed module graph from extracted Dart file facts.
|
|
272
272
|
///
|
|
273
273
|
/// Local relative imports and exports are resolved from the source file's
|
|
274
|
-
/// directory. `package:` imports resolve through
|
|
275
|
-
///
|
|
274
|
+
/// directory. `package:` imports resolve through Pub package metadata,
|
|
275
|
+
/// including `.dart_tool/package_config.json`, workspaces, path dependencies,
|
|
276
|
+
/// same-package imports, and owner-local copied packages with duplicate names.
|
|
276
277
|
///
|
|
277
278
|
/// # Errors
|
|
278
279
|
///
|
|
279
|
-
/// Returns [`GraphError`] if
|
|
280
|
-
/// parsed, or if a workspace glob entry is invalid.
|
|
280
|
+
/// Returns [`GraphError`] if package config or declared Pub package metadata
|
|
281
|
+
/// cannot be read or parsed, or if a workspace glob entry is invalid.
|
|
281
282
|
pub fn build_module_graph(
|
|
282
283
|
root: impl AsRef<Path>,
|
|
283
284
|
files: &[DartFile],
|
|
@@ -547,7 +548,7 @@ pub(super) fn resolve_local_uri(
|
|
|
547
548
|
let (package, path) = rest.split_once('/')?;
|
|
548
549
|
let path = percent_decode_uri_path(path);
|
|
549
550
|
return packages
|
|
550
|
-
.
|
|
551
|
+
.resolve_from(from_path, package, &path)
|
|
551
552
|
.map(|resolution| ResolvedTarget {
|
|
552
553
|
path: resolution.path,
|
|
553
554
|
local: resolution.local,
|
|
@@ -13,9 +13,9 @@ pub struct JsonCloneGroup {
|
|
|
13
13
|
pub fingerprint: String,
|
|
14
14
|
/// Matching clone instances.
|
|
15
15
|
pub instances: Vec<JsonCloneInstance>,
|
|
16
|
-
///
|
|
16
|
+
/// Normalized lines in the matched duplicated block.
|
|
17
17
|
pub line_count: usize,
|
|
18
|
-
///
|
|
18
|
+
/// Normalized tokens in the matched duplicated block.
|
|
19
19
|
pub token_count: usize,
|
|
20
20
|
}
|
|
21
21
|
|
|
@@ -86,7 +86,7 @@ fn feature_flag_finding(root: &Path, flag: &FeatureFlag) -> Finding {
|
|
|
86
86
|
rule_id: "dart-decimate/feature-flag".to_owned(),
|
|
87
87
|
fingerprint: Some(feature_flag_fingerprint(flag)),
|
|
88
88
|
kind: FindingKind::FeatureFlag,
|
|
89
|
-
severity:
|
|
89
|
+
severity: feature_flag_severity(root, flag),
|
|
90
90
|
message: format!(
|
|
91
91
|
"Feature flag {} is referenced via {}",
|
|
92
92
|
flag.name, flag.provider
|
|
@@ -111,6 +111,68 @@ fn feature_flag_finding(root: &Path, flag: &FeatureFlag) -> Finding {
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
+
fn feature_flag_severity(root: &Path, flag: &FeatureFlag) -> Severity {
|
|
115
|
+
if flag.source == FeatureFlagSource::CompileTimeEnvironment
|
|
116
|
+
&& flag.occurrences.iter().all(|occurrence| {
|
|
117
|
+
let path = occurrence.path.as_path();
|
|
118
|
+
is_dev_or_test_path(root, path)
|
|
119
|
+
})
|
|
120
|
+
{
|
|
121
|
+
Severity::Warning
|
|
122
|
+
} else {
|
|
123
|
+
Severity::Error
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
fn is_dev_or_test_path(root: &Path, path: &Path) -> bool {
|
|
128
|
+
let relative = path.strip_prefix(root).unwrap_or(path);
|
|
129
|
+
let mut under_production_lib = false;
|
|
130
|
+
let mut saw_lib = false;
|
|
131
|
+
for component in relative
|
|
132
|
+
.components()
|
|
133
|
+
.filter_map(|component| component.as_os_str().to_str())
|
|
134
|
+
{
|
|
135
|
+
if matches!(
|
|
136
|
+
component,
|
|
137
|
+
"test"
|
|
138
|
+
| "tests"
|
|
139
|
+
| "integration_test"
|
|
140
|
+
| "test_driver"
|
|
141
|
+
| "tool"
|
|
142
|
+
| "scripts"
|
|
143
|
+
| "dev"
|
|
144
|
+
| "debug"
|
|
145
|
+
| "e2e"
|
|
146
|
+
| "example"
|
|
147
|
+
) && !under_production_lib
|
|
148
|
+
{
|
|
149
|
+
return true;
|
|
150
|
+
}
|
|
151
|
+
if component == "lib" {
|
|
152
|
+
under_production_lib = true;
|
|
153
|
+
saw_lib = true;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if saw_lib {
|
|
157
|
+
return relative
|
|
158
|
+
.file_name()
|
|
159
|
+
.and_then(|file_name| file_name.to_str())
|
|
160
|
+
.is_some_and(is_non_production_flutter_entrypoint);
|
|
161
|
+
}
|
|
162
|
+
false
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
fn is_non_production_flutter_entrypoint(file_name: &str) -> bool {
|
|
166
|
+
matches!(
|
|
167
|
+
file_name,
|
|
168
|
+
"main_dev.dart"
|
|
169
|
+
| "main_debug.dart"
|
|
170
|
+
| "main_e2e.dart"
|
|
171
|
+
| "main_test.dart"
|
|
172
|
+
| "main_driver.dart"
|
|
173
|
+
)
|
|
174
|
+
}
|
|
175
|
+
|
|
114
176
|
fn feature_flag_fingerprint(flag: &FeatureFlag) -> String {
|
|
115
177
|
let text = format!("{}:{}:{}", flag.name, flag.provider, flag.source as u8);
|
|
116
178
|
let mut hash = 0xcbf2_9ce4_8422_2325_u64;
|
|
@@ -52,15 +52,19 @@ pub(super) fn add_dead_code_findings(
|
|
|
52
52
|
safe_to_delete: dead_file.safe_to_delete,
|
|
53
53
|
files: Vec::new(),
|
|
54
54
|
edge: None,
|
|
55
|
-
actions: vec![
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
55
|
+
actions: vec![FindingAction::new(
|
|
56
|
+
"delete-file",
|
|
57
|
+
"Delete the unreachable Dart file after confirming no dynamic entry point uses it",
|
|
58
|
+
dead_file.safe_to_delete,
|
|
59
|
+
)
|
|
60
|
+
.with_target_path(path.clone())
|
|
61
|
+
.with_dart_decimate_args([
|
|
62
|
+
"inspect",
|
|
63
|
+
"--format",
|
|
64
|
+
"json",
|
|
65
|
+
"--file",
|
|
66
|
+
path.as_str(),
|
|
67
|
+
])],
|
|
64
68
|
});
|
|
65
69
|
}
|
|
66
70
|
}
|
|
@@ -92,7 +96,7 @@ pub(super) fn add_cycle_findings(
|
|
|
92
96
|
actions: vec![
|
|
93
97
|
FindingAction::new(
|
|
94
98
|
"break-cycle",
|
|
95
|
-
"
|
|
99
|
+
"Inspect the cycle edge; split barrels or move shared ownership before expanding imports",
|
|
96
100
|
false,
|
|
97
101
|
)
|
|
98
102
|
.with_target_path(path.clone())
|
|
@@ -251,17 +255,15 @@ pub(super) fn add_boundary_call_findings(
|
|
|
251
255
|
safe_to_delete: false,
|
|
252
256
|
files: vec![display_path(root, &violation.from_boundary)],
|
|
253
257
|
edge: None,
|
|
254
|
-
actions: vec![
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
.with_suppression_comment("// dart-decimate-ignore-next-line boundary-call-violation"),
|
|
264
|
-
],
|
|
258
|
+
actions: vec![FindingAction::new(
|
|
259
|
+
"repair-boundary-call",
|
|
260
|
+
"Move the call behind an allowed boundary or replace it with an owned abstraction",
|
|
261
|
+
false,
|
|
262
|
+
)
|
|
263
|
+
.with_target_path(path.clone())
|
|
264
|
+
.with_config_key("boundary_calls")
|
|
265
|
+
.with_value_schema("array of FROM:PATTERN forbidden direct call rules")
|
|
266
|
+
.with_suppression_comment("// dart-decimate-ignore-next-line boundary-call-violation")],
|
|
265
267
|
});
|
|
266
268
|
}
|
|
267
269
|
}
|
|
@@ -196,7 +196,7 @@ pub(super) fn json_security_candidates(
|
|
|
196
196
|
.iter()
|
|
197
197
|
.map(|cwe| (*cwe).to_owned())
|
|
198
198
|
.collect(),
|
|
199
|
-
severity:
|
|
199
|
+
severity: security_severity(candidate.category),
|
|
200
200
|
candidate: JsonSecurityCandidateDetails {
|
|
201
201
|
source: source_label(candidate.category).to_owned(),
|
|
202
202
|
sink: candidate.sink.clone(),
|
|
@@ -261,7 +261,7 @@ fn security_finding(root: &Path, candidate: &SecurityCandidate) -> Finding {
|
|
|
261
261
|
rule_id: candidate.rule_id.clone(),
|
|
262
262
|
fingerprint: Some(security_fingerprint(candidate)),
|
|
263
263
|
kind: FindingKind::SecurityCandidate,
|
|
264
|
-
severity:
|
|
264
|
+
severity: security_severity(candidate.category),
|
|
265
265
|
message: format!(
|
|
266
266
|
"Security review candidate for {} via {}",
|
|
267
267
|
category_name(candidate.category),
|
|
@@ -287,6 +287,19 @@ fn security_finding(root: &Path, candidate: &SecurityCandidate) -> Finding {
|
|
|
287
287
|
}
|
|
288
288
|
}
|
|
289
289
|
|
|
290
|
+
const fn security_severity(category: SecurityCategory) -> Severity {
|
|
291
|
+
match category {
|
|
292
|
+
SecurityCategory::FirebaseApiKey => Severity::Warning,
|
|
293
|
+
SecurityCategory::HardcodedSecret
|
|
294
|
+
| SecurityCategory::InsecureTransport
|
|
295
|
+
| SecurityCategory::TlsBypass
|
|
296
|
+
| SecurityCategory::WebViewRisk
|
|
297
|
+
| SecurityCategory::ProcessExecution
|
|
298
|
+
| SecurityCategory::RawSql
|
|
299
|
+
| SecurityCategory::PlainSecretStorage => Severity::Error,
|
|
300
|
+
}
|
|
301
|
+
}
|
|
302
|
+
|
|
290
303
|
fn attack_surface_entry(root: &Path, entry: &AttackSurfaceEntry) -> JsonAttackSurfaceEntry {
|
|
291
304
|
JsonAttackSurfaceEntry {
|
|
292
305
|
category: entry.category,
|