dart-decimate 0.0.17 → 0.0.19
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 +10 -2
- package/package.json +1 -1
- package/src/config.rs +10 -3
- package/src/dependencies/analyze.rs +6 -0
- package/src/dependencies/flutter_usage.rs +92 -0
- package/src/dependencies.rs +4 -0
- package/src/dupes/mappings.rs +101 -0
- package/src/dupes.rs +4 -0
- package/src/extract/primary_constructors.rs +1 -0
- package/src/extract/references.rs +45 -0
- package/src/extract/tests.rs +34 -0
- package/src/extract.rs +3 -0
- package/src/feature_flags.rs +3 -0
- package/src/output/feature_flag_findings.rs +1 -0
- package/src/security/detect.rs +4 -0
- package/src/security/tests.rs +7 -25
- package/src/symbols/extensions.rs +95 -0
- package/src/symbols/index.rs +126 -0
- package/src/symbols/riverpod.rs +8 -1
- package/src/symbols.rs +14 -83
package/Cargo.lock
CHANGED
package/Cargo.toml
CHANGED
package/README.md
CHANGED
|
@@ -91,7 +91,7 @@ Add this to `package.json` if you want a short project command:
|
|
|
91
91
|
"dart-decimate": "dart-decimate json ."
|
|
92
92
|
},
|
|
93
93
|
"devDependencies": {
|
|
94
|
-
"dart-decimate": "^0.0.
|
|
94
|
+
"dart-decimate": "^0.0.19"
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
```
|
|
@@ -612,6 +612,9 @@ mode = "semantic"
|
|
|
612
612
|
min_tokens = 80
|
|
613
613
|
threshold = 5
|
|
614
614
|
|
|
615
|
+
[flags]
|
|
616
|
+
allow = ["SKIP_PERMISSION_PROMPT"]
|
|
617
|
+
|
|
615
618
|
[boundaries]
|
|
616
619
|
presets = ["layered"]
|
|
617
620
|
rules = ["lib/domain:lib/ui"]
|
|
@@ -627,6 +630,11 @@ security-candidate = "warn"
|
|
|
627
630
|
"dart-decimate/security-firebase-api-key" = "error"
|
|
628
631
|
```
|
|
629
632
|
|
|
633
|
+
Allowed feature flags remain visible in the inventory but do not create
|
|
634
|
+
`feature-flag` findings. Inline suppressions can document intent after `--`,
|
|
635
|
+
`because`, or `reason:`, for example
|
|
636
|
+
`// dart-decimate-ignore-next-line feature-flag -- required by E2E startup`.
|
|
637
|
+
|
|
630
638
|
## Full Issue List
|
|
631
639
|
|
|
632
640
|
Run this for the live list:
|
|
@@ -667,7 +675,7 @@ This repository forbids `unsafe_code`.
|
|
|
667
675
|
|
|
668
676
|
## Release Flow
|
|
669
677
|
|
|
670
|
-
Current version: `0.0.
|
|
678
|
+
Current version: `0.0.19`.
|
|
671
679
|
|
|
672
680
|
After the first public release, changes should go through pull requests. Every
|
|
673
681
|
PR to `main` must bump both `Cargo.toml` and `package.json` above the base
|
package/package.json
CHANGED
package/src/config.rs
CHANGED
|
@@ -125,6 +125,9 @@ pub struct FeatureFlagConfig {
|
|
|
125
125
|
/// Limit output to the N most frequently referenced flags.
|
|
126
126
|
#[serde(default)]
|
|
127
127
|
pub top: Option<usize>,
|
|
128
|
+
/// Intentional flag names retained in inventory without findings.
|
|
129
|
+
#[serde(default)]
|
|
130
|
+
pub allow: Vec<String>,
|
|
128
131
|
}
|
|
129
132
|
|
|
130
133
|
/// Security analyzer config defaults.
|
|
@@ -257,7 +260,8 @@ pub fn config_schema() -> Value {
|
|
|
257
260
|
"cache": cache::cache_schema(),
|
|
258
261
|
"health": health::health_schema(),
|
|
259
262
|
"dupes": dupes_schema(),
|
|
260
|
-
"flags":
|
|
263
|
+
"flags": feature_flags_schema(),
|
|
264
|
+
"featureFlags": feature_flags_schema(),
|
|
261
265
|
"security": security_schema(),
|
|
262
266
|
"rules": rules_schema()
|
|
263
267
|
}
|
|
@@ -286,6 +290,7 @@ impl DartDecimateConfig {
|
|
|
286
290
|
pub fn feature_flag_options(&self) -> FeatureFlagOptions {
|
|
287
291
|
FeatureFlagOptions {
|
|
288
292
|
top: self.flags.top,
|
|
293
|
+
allow: self.flags.allow.iter().cloned().collect(),
|
|
289
294
|
}
|
|
290
295
|
}
|
|
291
296
|
|
|
@@ -356,6 +361,7 @@ struct RawConfig {
|
|
|
356
361
|
cache: CacheConfig,
|
|
357
362
|
health: HealthConfig,
|
|
358
363
|
dupes: DuplicateConfig,
|
|
364
|
+
#[serde(alias = "featureFlags")]
|
|
359
365
|
flags: FeatureFlagConfig,
|
|
360
366
|
security: SecurityConfig,
|
|
361
367
|
rules: RuleConfig,
|
|
@@ -580,12 +586,13 @@ fn dupes_schema() -> Value {
|
|
|
580
586
|
})
|
|
581
587
|
}
|
|
582
588
|
|
|
583
|
-
fn
|
|
589
|
+
fn feature_flags_schema() -> Value {
|
|
584
590
|
json!({
|
|
585
591
|
"type": "object",
|
|
586
592
|
"additionalProperties": false,
|
|
587
593
|
"properties": {
|
|
588
|
-
"top": positive_integer_schema()
|
|
594
|
+
"top": positive_integer_schema(),
|
|
595
|
+
"allow": string_list_schema()
|
|
589
596
|
}
|
|
590
597
|
})
|
|
591
598
|
}
|
|
@@ -248,6 +248,12 @@ fn unused_dependency(
|
|
|
248
248
|
if dependency.name == package.name {
|
|
249
249
|
return None;
|
|
250
250
|
}
|
|
251
|
+
if package
|
|
252
|
+
.flutter_metadata_dependencies
|
|
253
|
+
.contains(&dependency.name)
|
|
254
|
+
{
|
|
255
|
+
return None;
|
|
256
|
+
}
|
|
251
257
|
let mut usage = used
|
|
252
258
|
.and_then(|used| used.get(&dependency.name))
|
|
253
259
|
.copied()
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
use std::collections::BTreeSet;
|
|
2
|
+
use std::fs;
|
|
3
|
+
use std::path::Path;
|
|
4
|
+
|
|
5
|
+
use serde_json::Value as JsonValue;
|
|
6
|
+
use serde_yaml_ng::Value;
|
|
7
|
+
|
|
8
|
+
pub(super) fn flutter_metadata_dependencies(
|
|
9
|
+
package_root: &Path,
|
|
10
|
+
pubspec: &Value,
|
|
11
|
+
) -> BTreeSet<String> {
|
|
12
|
+
let mut dependencies = BTreeSet::new();
|
|
13
|
+
if is_flutter_package(pubspec) {
|
|
14
|
+
dependencies.insert("cupertino_icons".to_owned());
|
|
15
|
+
}
|
|
16
|
+
if let Some(flutter) = mapping_field(pubspec, "flutter") {
|
|
17
|
+
collect_package_asset_references(flutter, &mut dependencies);
|
|
18
|
+
}
|
|
19
|
+
collect_native_plugins(package_root, &mut dependencies);
|
|
20
|
+
dependencies
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
fn is_flutter_package(pubspec: &Value) -> bool {
|
|
24
|
+
mapping_field(pubspec, "dependencies")
|
|
25
|
+
.and_then(|dependencies| mapping_field(dependencies, "flutter"))
|
|
26
|
+
.and_then(|flutter| mapping_field(flutter, "sdk"))
|
|
27
|
+
.and_then(Value::as_str)
|
|
28
|
+
== Some("flutter")
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
fn collect_package_asset_references(value: &Value, dependencies: &mut BTreeSet<String>) {
|
|
32
|
+
match value {
|
|
33
|
+
Value::String(value) => {
|
|
34
|
+
if let Some(package) = value
|
|
35
|
+
.strip_prefix("packages/")
|
|
36
|
+
.and_then(|path| path.split('/').next())
|
|
37
|
+
.filter(|package| !package.is_empty())
|
|
38
|
+
{
|
|
39
|
+
dependencies.insert(package.to_owned());
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
Value::Sequence(values) => {
|
|
43
|
+
for value in values {
|
|
44
|
+
collect_package_asset_references(value, dependencies);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
Value::Mapping(mapping) => {
|
|
48
|
+
for value in mapping.values() {
|
|
49
|
+
collect_package_asset_references(value, dependencies);
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
_ => {}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
fn collect_native_plugins(package_root: &Path, dependencies: &mut BTreeSet<String>) {
|
|
57
|
+
let path = package_root.join(".flutter-plugins-dependencies");
|
|
58
|
+
let Ok(source) = fs::read_to_string(path) else {
|
|
59
|
+
return;
|
|
60
|
+
};
|
|
61
|
+
let Ok(value) = serde_json::from_str::<JsonValue>(&source) else {
|
|
62
|
+
return;
|
|
63
|
+
};
|
|
64
|
+
for section in ["plugins", "dependencyGraph"] {
|
|
65
|
+
if let Some(value) = value.get(section) {
|
|
66
|
+
collect_plugin_names(value, dependencies);
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
fn collect_plugin_names(value: &JsonValue, dependencies: &mut BTreeSet<String>) {
|
|
72
|
+
match value {
|
|
73
|
+
JsonValue::Object(object) => {
|
|
74
|
+
if let Some(name) = object.get("name").and_then(JsonValue::as_str) {
|
|
75
|
+
dependencies.insert(name.to_owned());
|
|
76
|
+
}
|
|
77
|
+
for value in object.values() {
|
|
78
|
+
collect_plugin_names(value, dependencies);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
JsonValue::Array(values) => {
|
|
82
|
+
for value in values {
|
|
83
|
+
collect_plugin_names(value, dependencies);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
_ => {}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
fn mapping_field<'value>(value: &'value Value, key: &str) -> Option<&'value Value> {
|
|
91
|
+
value.as_mapping()?.get(Value::String(key.to_owned()))
|
|
92
|
+
}
|
package/src/dependencies.rs
CHANGED
|
@@ -13,6 +13,7 @@ mod analyze;
|
|
|
13
13
|
mod codegen;
|
|
14
14
|
pub(crate) use codegen::file_uses_codegen_dependency;
|
|
15
15
|
mod discovery;
|
|
16
|
+
mod flutter_usage;
|
|
16
17
|
mod overrides;
|
|
17
18
|
mod private_src_imports;
|
|
18
19
|
mod pubspec_document;
|
|
@@ -280,6 +281,7 @@ pub(super) struct PubPackage {
|
|
|
280
281
|
root: PathBuf,
|
|
281
282
|
pubspec_path: PathBuf,
|
|
282
283
|
dependencies: Vec<DeclaredDependency>,
|
|
284
|
+
flutter_metadata_dependencies: BTreeSet<String>,
|
|
283
285
|
misconfigured_dependency_overrides: Vec<MisconfiguredDependencyOverride>,
|
|
284
286
|
locked_packages: Option<BTreeSet<String>>,
|
|
285
287
|
}
|
|
@@ -348,12 +350,14 @@ pub(super) fn read_package(path: &Path) -> Result<Option<PubPackage>, Dependency
|
|
|
348
350
|
.parent()
|
|
349
351
|
.map_or_else(|| PathBuf::from("."), normalize_path);
|
|
350
352
|
let overrides = read_pubspec_overrides(&root)?;
|
|
353
|
+
let flutter_metadata_dependencies = flutter_usage::flutter_metadata_dependencies(&root, &value);
|
|
351
354
|
|
|
352
355
|
Ok(Some(PubPackage {
|
|
353
356
|
name: name.to_owned(),
|
|
354
357
|
root,
|
|
355
358
|
pubspec_path: path.to_path_buf(),
|
|
356
359
|
dependencies: merged_declared_dependencies(&value, &source, path, overrides.as_ref()),
|
|
360
|
+
flutter_metadata_dependencies,
|
|
357
361
|
misconfigured_dependency_overrides: merged_misconfigured_dependency_overrides(
|
|
358
362
|
&value,
|
|
359
363
|
&source,
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
use std::path::PathBuf;
|
|
2
|
+
|
|
3
|
+
use crate::graph::normalize_against;
|
|
4
|
+
use crate::{DeclarationKind, DependencyKind, MemberKind, ScannedProject, SourceRange};
|
|
5
|
+
|
|
6
|
+
use super::{CodeClone, CodeCloneInstance};
|
|
7
|
+
|
|
8
|
+
pub(super) struct MappingBoundaryFilter {
|
|
9
|
+
boundaries: Vec<MappingBoundary>,
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
struct MappingBoundary {
|
|
13
|
+
model_path: PathBuf,
|
|
14
|
+
model_range: SourceRange,
|
|
15
|
+
entity_path: PathBuf,
|
|
16
|
+
entity_range: SourceRange,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
impl MappingBoundaryFilter {
|
|
20
|
+
pub(super) fn new(project: &ScannedProject) -> Self {
|
|
21
|
+
let dependencies = project.graph.dependencies();
|
|
22
|
+
let mut boundaries = Vec::new();
|
|
23
|
+
|
|
24
|
+
for model_file in &project.files {
|
|
25
|
+
let model_path = normalize_against(&project.root, &model_file.path);
|
|
26
|
+
for member in model_file.members.iter().filter(|member| {
|
|
27
|
+
member.kind == MemberKind::Method
|
|
28
|
+
&& member.name == "toEntity"
|
|
29
|
+
&& member.owner.ends_with("Model")
|
|
30
|
+
}) {
|
|
31
|
+
let Some(model) = model_file.declarations.iter().find(|declaration| {
|
|
32
|
+
declaration.kind == DeclarationKind::Class && declaration.name == member.owner
|
|
33
|
+
}) else {
|
|
34
|
+
continue;
|
|
35
|
+
};
|
|
36
|
+
let Some(prefix) = model.name.strip_suffix("Model") else {
|
|
37
|
+
continue;
|
|
38
|
+
};
|
|
39
|
+
let entity_name = format!("{prefix}Entity");
|
|
40
|
+
|
|
41
|
+
for dependency in dependencies.iter().filter(|dependency| {
|
|
42
|
+
dependency.kind == DependencyKind::Import && dependency.from_path == model_path
|
|
43
|
+
}) {
|
|
44
|
+
let Some(entity_file) = project
|
|
45
|
+
.files
|
|
46
|
+
.iter()
|
|
47
|
+
.find(|file| file.path == dependency.to_path)
|
|
48
|
+
else {
|
|
49
|
+
continue;
|
|
50
|
+
};
|
|
51
|
+
let Some(entity) = entity_file.declarations.iter().find(|declaration| {
|
|
52
|
+
declaration.kind == DeclarationKind::Class
|
|
53
|
+
&& declaration.name == entity_name
|
|
54
|
+
}) else {
|
|
55
|
+
continue;
|
|
56
|
+
};
|
|
57
|
+
if !model_file
|
|
58
|
+
.references
|
|
59
|
+
.iter()
|
|
60
|
+
.any(|reference| reference.name == entity_name)
|
|
61
|
+
{
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
boundaries.push(MappingBoundary {
|
|
65
|
+
model_path: model_path.clone(),
|
|
66
|
+
model_range: model.range,
|
|
67
|
+
entity_path: dependency.to_path.clone(),
|
|
68
|
+
entity_range: entity.range,
|
|
69
|
+
});
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
Self { boundaries }
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
pub(super) fn is_mapping_boundary_clone(&self, group: &CodeClone) -> bool {
|
|
78
|
+
self.boundaries.iter().any(|boundary| {
|
|
79
|
+
let mut saw_model = false;
|
|
80
|
+
let mut saw_entity = false;
|
|
81
|
+
let all_inside_pair = group.instances.iter().all(|instance| {
|
|
82
|
+
if instance_inside(instance, &boundary.model_path, boundary.model_range) {
|
|
83
|
+
saw_model = true;
|
|
84
|
+
return true;
|
|
85
|
+
}
|
|
86
|
+
if instance_inside(instance, &boundary.entity_path, boundary.entity_range) {
|
|
87
|
+
saw_entity = true;
|
|
88
|
+
return true;
|
|
89
|
+
}
|
|
90
|
+
false
|
|
91
|
+
});
|
|
92
|
+
all_inside_pair && saw_model && saw_entity
|
|
93
|
+
})
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
fn instance_inside(instance: &CodeCloneInstance, path: &PathBuf, range: SourceRange) -> bool {
|
|
98
|
+
instance.path == *path
|
|
99
|
+
&& instance.start_line >= range.start_line
|
|
100
|
+
&& instance.end_line <= range.end_line
|
|
101
|
+
}
|
package/src/dupes.rs
CHANGED
|
@@ -16,6 +16,8 @@ mod lex;
|
|
|
16
16
|
use lex::normalized_lines;
|
|
17
17
|
mod declarations;
|
|
18
18
|
use declarations::DeclarationCloneFilter;
|
|
19
|
+
mod mappings;
|
|
20
|
+
use mappings::MappingBoundaryFilter;
|
|
19
21
|
mod packages;
|
|
20
22
|
use packages::CopiedPackageFilter;
|
|
21
23
|
|
|
@@ -387,6 +389,8 @@ pub fn detect_duplicates(
|
|
|
387
389
|
clone_groups.retain(|group| group_satisfies_occurrence_options(group, options));
|
|
388
390
|
let mut declaration_filter = DeclarationCloneFilter::new();
|
|
389
391
|
clone_groups.retain(|group| !declaration_filter.is_declaration_only_clone(group));
|
|
392
|
+
let mapping_filter = MappingBoundaryFilter::new(project);
|
|
393
|
+
clone_groups.retain(|group| !mapping_filter.is_mapping_boundary_clone(group));
|
|
390
394
|
sort_clone_groups(&mut clone_groups);
|
|
391
395
|
clone_groups = collapse_overlapping_groups(clone_groups);
|
|
392
396
|
clone_groups.retain(|group| !copied_packages.is_copied_package_clone(group));
|
|
@@ -24,6 +24,7 @@ fn collect_identifier_references(
|
|
|
24
24
|
if let Ok(name) = node.utf8_text(source.as_bytes()) {
|
|
25
25
|
references.push(IdentifierReference {
|
|
26
26
|
name: name.to_owned(),
|
|
27
|
+
qualifier: simple_member_qualifier(node, source),
|
|
27
28
|
location: node.start_position().into(),
|
|
28
29
|
});
|
|
29
30
|
}
|
|
@@ -97,6 +98,7 @@ fn collect_string_segment_interpolation_references(
|
|
|
97
98
|
if let Some((name, start)) = interpolation_identifier(text, interpolation_start) {
|
|
98
99
|
references.push(IdentifierReference {
|
|
99
100
|
name: name.to_owned(),
|
|
101
|
+
qualifier: None,
|
|
100
102
|
location: location_at(source, base_byte + start),
|
|
101
103
|
});
|
|
102
104
|
index = start + name.len();
|
|
@@ -104,6 +106,49 @@ fn collect_string_segment_interpolation_references(
|
|
|
104
106
|
}
|
|
105
107
|
}
|
|
106
108
|
|
|
109
|
+
fn simple_member_qualifier(node: Node<'_>, source: &str) -> Option<String> {
|
|
110
|
+
let parent = node.parent()?;
|
|
111
|
+
if parent.kind() == "constant_pattern" {
|
|
112
|
+
let text = parent.utf8_text(source.as_bytes()).ok()?;
|
|
113
|
+
let (qualifier, property) = text.rsplit_once('.')?;
|
|
114
|
+
let qualifier = qualifier.trim();
|
|
115
|
+
if property.trim() == node.utf8_text(source.as_bytes()).ok()?
|
|
116
|
+
&& qualifier.bytes().all(is_identifier_byte)
|
|
117
|
+
{
|
|
118
|
+
return Some(qualifier.to_owned());
|
|
119
|
+
}
|
|
120
|
+
return None;
|
|
121
|
+
}
|
|
122
|
+
if parent.kind() == "qualified" {
|
|
123
|
+
let qualifier = parent.named_child(0)?;
|
|
124
|
+
let property_index = u32::try_from(parent.named_child_count().checked_sub(1)?).ok()?;
|
|
125
|
+
let property = parent.named_child(property_index)?;
|
|
126
|
+
if property == node && matches!(qualifier.kind(), "identifier" | "type_identifier") {
|
|
127
|
+
return qualifier
|
|
128
|
+
.utf8_text(source.as_bytes())
|
|
129
|
+
.ok()
|
|
130
|
+
.map(str::to_owned);
|
|
131
|
+
}
|
|
132
|
+
return None;
|
|
133
|
+
}
|
|
134
|
+
if !matches!(
|
|
135
|
+
parent.kind(),
|
|
136
|
+
"member_expression" | "null_aware_member_expression" | "assignable_expression"
|
|
137
|
+
) || parent.child_by_field_name("property")? != node
|
|
138
|
+
{
|
|
139
|
+
return None;
|
|
140
|
+
}
|
|
141
|
+
let object = parent.child_by_field_name("object")?;
|
|
142
|
+
if !matches!(object.kind(), "identifier" | "type_identifier") {
|
|
143
|
+
return None;
|
|
144
|
+
}
|
|
145
|
+
object.utf8_text(source.as_bytes()).ok().map(str::to_owned)
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
fn is_identifier_byte(byte: u8) -> bool {
|
|
149
|
+
byte.is_ascii_alphanumeric() || matches!(byte, b'_' | b'$')
|
|
150
|
+
}
|
|
151
|
+
|
|
107
152
|
fn is_string_literal_segment(kind: &str) -> bool {
|
|
108
153
|
kind.starts_with("raw_string_literal") || kind.starts_with("string_literal_")
|
|
109
154
|
}
|
package/src/extract/tests.rs
CHANGED
|
@@ -625,6 +625,40 @@ void boot(String suffix, String escaped) {
|
|
|
625
625
|
Ok(())
|
|
626
626
|
}
|
|
627
627
|
|
|
628
|
+
#[test]
|
|
629
|
+
fn extracts_simple_member_qualifiers() -> Result<(), ExtractError> {
|
|
630
|
+
let source = r"
|
|
631
|
+
void boot(Command command) {
|
|
632
|
+
print(Command.settings.name);
|
|
633
|
+
print('${Command.tips.id}');
|
|
634
|
+
print(command.settings);
|
|
635
|
+
final label = switch (command) {
|
|
636
|
+
ReminderType.doctor => 'doctor',
|
|
637
|
+
};
|
|
638
|
+
print(label);
|
|
639
|
+
}
|
|
640
|
+
";
|
|
641
|
+
|
|
642
|
+
let extracted = extract_dart_source("lib/qualified.dart", source)?;
|
|
643
|
+
let references = extracted
|
|
644
|
+
.references
|
|
645
|
+
.iter()
|
|
646
|
+
.filter(|reference| matches!(reference.name.as_str(), "settings" | "tips" | "doctor"))
|
|
647
|
+
.map(|reference| (reference.name.as_str(), reference.qualifier.as_deref()))
|
|
648
|
+
.collect::<Vec<_>>();
|
|
649
|
+
|
|
650
|
+
assert_eq!(
|
|
651
|
+
references,
|
|
652
|
+
vec![
|
|
653
|
+
("settings", Some("Command")),
|
|
654
|
+
("tips", Some("Command")),
|
|
655
|
+
("settings", Some("command")),
|
|
656
|
+
("doctor", Some("ReminderType"))
|
|
657
|
+
]
|
|
658
|
+
);
|
|
659
|
+
Ok(())
|
|
660
|
+
}
|
|
661
|
+
|
|
628
662
|
#[test]
|
|
629
663
|
fn extracts_references_from_annotations_generics_and_patterns() -> Result<(), ExtractError> {
|
|
630
664
|
let source = "\
|
package/src/extract.rs
CHANGED
|
@@ -224,6 +224,9 @@ pub struct MemberDeclaration {
|
|
|
224
224
|
pub struct IdentifierReference {
|
|
225
225
|
/// Referenced identifier text.
|
|
226
226
|
pub name: String,
|
|
227
|
+
/// Simple receiver identifier for a qualified member access.
|
|
228
|
+
#[serde(default, skip_serializing)]
|
|
229
|
+
pub qualifier: Option<String>,
|
|
227
230
|
/// Location of the identifier token.
|
|
228
231
|
pub location: Location,
|
|
229
232
|
}
|
package/src/feature_flags.rs
CHANGED
|
@@ -14,6 +14,9 @@ use crate::{Location, ScannedProject};
|
|
|
14
14
|
pub struct FeatureFlagOptions {
|
|
15
15
|
/// Limit output to the N most frequently referenced flags.
|
|
16
16
|
pub top: Option<usize>,
|
|
17
|
+
/// Flag names kept in inventory but acknowledged as intentional.
|
|
18
|
+
#[serde(default)]
|
|
19
|
+
pub allow: BTreeSet<String>,
|
|
17
20
|
}
|
|
18
21
|
|
|
19
22
|
/// Feature flag report.
|
package/src/security/detect.rs
CHANGED
|
@@ -124,6 +124,9 @@ fn detect_firebase_api_keys(
|
|
|
124
124
|
source: &str,
|
|
125
125
|
candidates: &mut Vec<DetectedSecurityCandidate>,
|
|
126
126
|
) {
|
|
127
|
+
if is_flutterfire_options_path(path) {
|
|
128
|
+
return;
|
|
129
|
+
}
|
|
127
130
|
for literal in string_literals(source) {
|
|
128
131
|
if is_comment_match(source, literal.index)
|
|
129
132
|
|| is_placeholder(&literal.value)
|
|
@@ -2432,6 +2435,7 @@ fn literal_looks_like_user_facing_copy(value: &str) -> bool {
|
|
|
2432
2435
|
"password reset",
|
|
2433
2436
|
"enter password",
|
|
2434
2437
|
"confirm password",
|
|
2438
|
+
"confirm your password",
|
|
2435
2439
|
"password must",
|
|
2436
2440
|
"password is",
|
|
2437
2441
|
"password should",
|
package/src/security/tests.rs
CHANGED
|
@@ -267,7 +267,7 @@ fn classifies_firebase_options_api_key_separately() -> Result<(), Box<dyn std::e
|
|
|
267
267
|
write(&fixture, "pubspec.yaml", "name: app\n")?;
|
|
268
268
|
write(
|
|
269
269
|
&fixture,
|
|
270
|
-
"lib/
|
|
270
|
+
"lib/firebase_config.dart",
|
|
271
271
|
"const options = FirebaseOptions(
|
|
272
272
|
apiKey: 'DartDecimateFirebaseKeyValue123456789',
|
|
273
273
|
appId: '1:123:web:abc',
|
|
@@ -334,14 +334,8 @@ fn classifies_compact_firebase_options_literals_by_argument()
|
|
|
334
334
|
.collect::<Vec<_>>();
|
|
335
335
|
rules.sort_unstable();
|
|
336
336
|
|
|
337
|
-
assert_eq!(report.total_occurrences,
|
|
338
|
-
assert_eq!(
|
|
339
|
-
rules,
|
|
340
|
-
vec![
|
|
341
|
-
"dart-decimate/security-firebase-api-key",
|
|
342
|
-
"dart-decimate/security-hardcoded-secret"
|
|
343
|
-
]
|
|
344
|
-
);
|
|
337
|
+
assert_eq!(report.total_occurrences, 1);
|
|
338
|
+
assert_eq!(rules, vec!["dart-decimate/security-hardcoded-secret"]);
|
|
345
339
|
|
|
346
340
|
Ok(())
|
|
347
341
|
}
|
|
@@ -367,14 +361,8 @@ fn classifies_newline_firebase_options_api_key_by_argument()
|
|
|
367
361
|
.collect::<Vec<_>>();
|
|
368
362
|
rules.sort_unstable();
|
|
369
363
|
|
|
370
|
-
assert_eq!(report.total_occurrences,
|
|
371
|
-
assert_eq!(
|
|
372
|
-
rules,
|
|
373
|
-
vec![
|
|
374
|
-
"dart-decimate/security-firebase-api-key",
|
|
375
|
-
"dart-decimate/security-hardcoded-secret"
|
|
376
|
-
]
|
|
377
|
-
);
|
|
364
|
+
assert_eq!(report.total_occurrences, 1);
|
|
365
|
+
assert_eq!(rules, vec!["dart-decimate/security-hardcoded-secret"]);
|
|
378
366
|
|
|
379
367
|
Ok(())
|
|
380
368
|
}
|
|
@@ -405,14 +393,8 @@ fn classifies_newline_firebase_options_secret_argument() -> Result<(), Box<dyn s
|
|
|
405
393
|
.collect::<Vec<_>>();
|
|
406
394
|
rules.sort_unstable();
|
|
407
395
|
|
|
408
|
-
assert_eq!(report.total_occurrences,
|
|
409
|
-
assert_eq!(
|
|
410
|
-
rules,
|
|
411
|
-
vec![
|
|
412
|
-
"dart-decimate/security-firebase-api-key",
|
|
413
|
-
"dart-decimate/security-hardcoded-secret"
|
|
414
|
-
]
|
|
415
|
-
);
|
|
396
|
+
assert_eq!(report.total_occurrences, 1);
|
|
397
|
+
assert_eq!(rules, vec!["dart-decimate/security-hardcoded-secret"]);
|
|
416
398
|
|
|
417
399
|
Ok(())
|
|
418
400
|
}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
use std::collections::{BTreeMap, BTreeSet};
|
|
2
|
+
use std::path::PathBuf;
|
|
3
|
+
|
|
4
|
+
use crate::{DartCombinatorKind, DeclarationKind, DependencyKind, ScannedProject};
|
|
5
|
+
|
|
6
|
+
use super::{IndexedDeclaration, IndexedMember, IndexedReference, PublicExportedDeclaration};
|
|
7
|
+
|
|
8
|
+
pub(super) fn extend_implicit_extension_references(
|
|
9
|
+
references_by_name: &mut BTreeMap<String, Vec<IndexedReference>>,
|
|
10
|
+
declarations: &[IndexedDeclaration],
|
|
11
|
+
members: &[IndexedMember],
|
|
12
|
+
library_by_path: &BTreeMap<PathBuf, PathBuf>,
|
|
13
|
+
public_exports: &[PublicExportedDeclaration],
|
|
14
|
+
project: &ScannedProject,
|
|
15
|
+
) {
|
|
16
|
+
let dependencies = project.graph.dependencies();
|
|
17
|
+
for declaration in declarations
|
|
18
|
+
.iter()
|
|
19
|
+
.filter(|declaration| declaration.declaration.kind == DeclarationKind::Extension)
|
|
20
|
+
{
|
|
21
|
+
let entry_paths = public_exports
|
|
22
|
+
.iter()
|
|
23
|
+
.filter(|exported| {
|
|
24
|
+
exported.path == declaration.path
|
|
25
|
+
&& exported.declaration.name == declaration.declaration.name
|
|
26
|
+
})
|
|
27
|
+
.map(|exported| exported.entry_path.clone())
|
|
28
|
+
.chain(std::iter::once(declaration.path.clone()))
|
|
29
|
+
.collect::<BTreeSet<_>>();
|
|
30
|
+
let implicit_references = members
|
|
31
|
+
.iter()
|
|
32
|
+
.filter(|member| {
|
|
33
|
+
member.path == declaration.path
|
|
34
|
+
&& member.member.owner == declaration.declaration.name
|
|
35
|
+
})
|
|
36
|
+
.filter_map(|member| references_by_name.get(&member.member.name))
|
|
37
|
+
.flatten()
|
|
38
|
+
.filter(|reference| {
|
|
39
|
+
extension_visible_from(
|
|
40
|
+
reference,
|
|
41
|
+
declaration,
|
|
42
|
+
&entry_paths,
|
|
43
|
+
library_by_path,
|
|
44
|
+
&dependencies,
|
|
45
|
+
)
|
|
46
|
+
})
|
|
47
|
+
.cloned()
|
|
48
|
+
.collect::<Vec<_>>();
|
|
49
|
+
if implicit_references.is_empty() {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
references_by_name
|
|
54
|
+
.entry(declaration.declaration.name.clone())
|
|
55
|
+
.or_default()
|
|
56
|
+
.extend(implicit_references);
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
fn extension_visible_from(
|
|
61
|
+
reference: &IndexedReference,
|
|
62
|
+
declaration: &IndexedDeclaration,
|
|
63
|
+
entry_paths: &BTreeSet<PathBuf>,
|
|
64
|
+
library_by_path: &BTreeMap<PathBuf, PathBuf>,
|
|
65
|
+
dependencies: &[crate::ResolvedDependency],
|
|
66
|
+
) -> bool {
|
|
67
|
+
let reference_library = library_by_path
|
|
68
|
+
.get(&reference.path)
|
|
69
|
+
.unwrap_or(&reference.path);
|
|
70
|
+
let declaration_library = library_by_path
|
|
71
|
+
.get(&declaration.path)
|
|
72
|
+
.unwrap_or(&declaration.path);
|
|
73
|
+
if reference_library == declaration_library {
|
|
74
|
+
return true;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
dependencies.iter().any(|dependency| {
|
|
78
|
+
dependency.kind == DependencyKind::Import
|
|
79
|
+
&& dependency.from_path == reference.path
|
|
80
|
+
&& entry_paths.contains(&dependency.to_path)
|
|
81
|
+
&& dependency.visibility.prefix.is_none()
|
|
82
|
+
&& dependency
|
|
83
|
+
.visibility
|
|
84
|
+
.combinators
|
|
85
|
+
.iter()
|
|
86
|
+
.all(|combinator| match combinator.kind {
|
|
87
|
+
DartCombinatorKind::Show => {
|
|
88
|
+
combinator.names.contains(&declaration.declaration.name)
|
|
89
|
+
}
|
|
90
|
+
DartCombinatorKind::Hide => {
|
|
91
|
+
!combinator.names.contains(&declaration.declaration.name)
|
|
92
|
+
}
|
|
93
|
+
})
|
|
94
|
+
})
|
|
95
|
+
}
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
use std::collections::{BTreeMap, BTreeSet};
|
|
2
|
+
use std::path::{Path, PathBuf};
|
|
3
|
+
|
|
4
|
+
use crate::ScannedProject;
|
|
5
|
+
use crate::graph::normalize_against;
|
|
6
|
+
|
|
7
|
+
use super::{
|
|
8
|
+
IndexedDeclaration, IndexedMember, IndexedReference, SymbolIndex,
|
|
9
|
+
extend_generated_provider_owner_references, extend_implicit_extension_references,
|
|
10
|
+
library_by_path, public_exported_declarations,
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
impl SymbolIndex {
|
|
14
|
+
/// Build a symbol index from parsed Dart files.
|
|
15
|
+
#[must_use]
|
|
16
|
+
pub fn from_project(project: &ScannedProject) -> Self {
|
|
17
|
+
let mut declarations = Vec::new();
|
|
18
|
+
let mut members = Vec::new();
|
|
19
|
+
let mut references_by_name = BTreeMap::<String, Vec<IndexedReference>>::new();
|
|
20
|
+
let mut qualified_references_by_name =
|
|
21
|
+
BTreeMap::<(String, String), Vec<IndexedReference>>::new();
|
|
22
|
+
let library_by_path = library_by_path(project);
|
|
23
|
+
let public_exported_declarations = public_exported_declarations(project);
|
|
24
|
+
let public_exports = public_exported_declarations
|
|
25
|
+
.iter()
|
|
26
|
+
.map(|exported| (exported.path.clone(), exported.declaration.name.clone()))
|
|
27
|
+
.collect();
|
|
28
|
+
|
|
29
|
+
for file in &project.files {
|
|
30
|
+
let path = normalize_against(&project.root, &file.path);
|
|
31
|
+
declarations.extend(file.declarations.iter().cloned().map(|declaration| {
|
|
32
|
+
IndexedDeclaration {
|
|
33
|
+
path: path.clone(),
|
|
34
|
+
declaration,
|
|
35
|
+
}
|
|
36
|
+
}));
|
|
37
|
+
members.extend(file.members.iter().cloned().map(|member| IndexedMember {
|
|
38
|
+
path: path.clone(),
|
|
39
|
+
member,
|
|
40
|
+
}));
|
|
41
|
+
for reference in &file.references {
|
|
42
|
+
let indexed = IndexedReference { path: path.clone() };
|
|
43
|
+
references_by_name
|
|
44
|
+
.entry(reference.name.clone())
|
|
45
|
+
.or_default()
|
|
46
|
+
.push(indexed.clone());
|
|
47
|
+
if let Some(qualifier) = &reference.qualifier {
|
|
48
|
+
qualified_references_by_name
|
|
49
|
+
.entry((qualifier.clone(), reference.name.clone()))
|
|
50
|
+
.or_default()
|
|
51
|
+
.push(indexed);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
extend_generated_provider_owner_references(&mut references_by_name, &declarations);
|
|
56
|
+
extend_implicit_extension_references(
|
|
57
|
+
&mut references_by_name,
|
|
58
|
+
&declarations,
|
|
59
|
+
&members,
|
|
60
|
+
&library_by_path,
|
|
61
|
+
&public_exported_declarations,
|
|
62
|
+
project,
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
Self {
|
|
66
|
+
declarations,
|
|
67
|
+
members,
|
|
68
|
+
references_by_name,
|
|
69
|
+
qualified_references_by_name,
|
|
70
|
+
library_by_path,
|
|
71
|
+
public_exports,
|
|
72
|
+
public_exported_declarations,
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
pub(super) fn qualified_reference_count(
|
|
77
|
+
&self,
|
|
78
|
+
owner: &str,
|
|
79
|
+
name: &str,
|
|
80
|
+
reachable_files: &BTreeSet<PathBuf>,
|
|
81
|
+
) -> usize {
|
|
82
|
+
self.qualified_references_by_name
|
|
83
|
+
.get(&(owner.to_owned(), name.to_owned()))
|
|
84
|
+
.map_or(0, |references| {
|
|
85
|
+
references
|
|
86
|
+
.iter()
|
|
87
|
+
.filter(|reference| reachable_files.contains(&reference.path))
|
|
88
|
+
.count()
|
|
89
|
+
})
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
pub(super) fn reference_count(&self, name: &str, reachable_files: &BTreeSet<PathBuf>) -> usize {
|
|
93
|
+
self.references_by_name.get(name).map_or(0, |references| {
|
|
94
|
+
references
|
|
95
|
+
.iter()
|
|
96
|
+
.filter(|reference| reachable_files.contains(&reference.path))
|
|
97
|
+
.count()
|
|
98
|
+
})
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
pub(super) fn library_reference_count(
|
|
102
|
+
&self,
|
|
103
|
+
name: &str,
|
|
104
|
+
library: &Path,
|
|
105
|
+
reachable_files: &BTreeSet<PathBuf>,
|
|
106
|
+
) -> usize {
|
|
107
|
+
self.references_by_name.get(name).map_or(0, |references| {
|
|
108
|
+
references
|
|
109
|
+
.iter()
|
|
110
|
+
.filter(|reference| reachable_files.contains(&reference.path))
|
|
111
|
+
.filter(|reference| self.library_path(&reference.path) == library)
|
|
112
|
+
.count()
|
|
113
|
+
})
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
pub(super) fn library_path<'a>(&'a self, path: &'a Path) -> &'a Path {
|
|
117
|
+
self.library_by_path
|
|
118
|
+
.get(path)
|
|
119
|
+
.map_or(path, std::path::PathBuf::as_path)
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
pub(super) fn is_public_export(&self, path: &Path, name: &str) -> bool {
|
|
123
|
+
self.public_exports
|
|
124
|
+
.contains(&(path.to_path_buf(), name.to_owned()))
|
|
125
|
+
}
|
|
126
|
+
}
|
package/src/symbols/riverpod.rs
CHANGED
|
@@ -58,8 +58,15 @@ fn annotation_window(source: &str, declaration_line: usize) -> String {
|
|
|
58
58
|
}
|
|
59
59
|
|
|
60
60
|
fn riverpod_provider_names(declaration_name: &str) -> Vec<String> {
|
|
61
|
-
|
|
61
|
+
let mut source_names = vec![declaration_name];
|
|
62
|
+
if let Some(stripped) = declaration_name.strip_suffix("Notifier")
|
|
63
|
+
&& !stripped.is_empty()
|
|
64
|
+
{
|
|
65
|
+
source_names.push(stripped);
|
|
66
|
+
}
|
|
67
|
+
source_names
|
|
62
68
|
.into_iter()
|
|
69
|
+
.flat_map(lower_camel_candidates)
|
|
63
70
|
.map(|name| format!("{name}Provider"))
|
|
64
71
|
.collect()
|
|
65
72
|
}
|
package/src/symbols.rs
CHANGED
|
@@ -10,9 +10,12 @@ use crate::{
|
|
|
10
10
|
MemberDeclaration, MemberKind, ScannedProject, TopLevelDeclaration,
|
|
11
11
|
};
|
|
12
12
|
|
|
13
|
+
mod extensions;
|
|
14
|
+
mod index;
|
|
13
15
|
mod path_filters;
|
|
14
16
|
mod private_type_leaks;
|
|
15
17
|
mod riverpod;
|
|
18
|
+
use extensions::extend_implicit_extension_references;
|
|
16
19
|
use path_filters::{is_library_source, is_private, is_public_library_entry};
|
|
17
20
|
pub use private_type_leaks::PrivateTypeLeak;
|
|
18
21
|
use private_type_leaks::private_type_leaks;
|
|
@@ -81,6 +84,7 @@ pub struct SymbolIndex {
|
|
|
81
84
|
declarations: Vec<IndexedDeclaration>,
|
|
82
85
|
members: Vec<IndexedMember>,
|
|
83
86
|
references_by_name: BTreeMap<String, Vec<IndexedReference>>,
|
|
87
|
+
qualified_references_by_name: BTreeMap<(String, String), Vec<IndexedReference>>,
|
|
84
88
|
library_by_path: BTreeMap<PathBuf, PathBuf>,
|
|
85
89
|
public_exports: BTreeSet<(PathBuf, String)>,
|
|
86
90
|
public_exported_declarations: Vec<PublicExportedDeclaration>,
|
|
@@ -110,86 +114,6 @@ struct PublicExportedDeclaration {
|
|
|
110
114
|
declaration: TopLevelDeclaration,
|
|
111
115
|
}
|
|
112
116
|
|
|
113
|
-
impl SymbolIndex {
|
|
114
|
-
/// Build a symbol index from parsed Dart files.
|
|
115
|
-
#[must_use]
|
|
116
|
-
pub fn from_project(project: &ScannedProject) -> Self {
|
|
117
|
-
let mut declarations = Vec::new();
|
|
118
|
-
let mut members = Vec::new();
|
|
119
|
-
let mut references_by_name = BTreeMap::<String, Vec<IndexedReference>>::new();
|
|
120
|
-
let library_by_path = library_by_path(project);
|
|
121
|
-
let public_exported_declarations = public_exported_declarations(project);
|
|
122
|
-
let public_exports = public_exported_declarations
|
|
123
|
-
.iter()
|
|
124
|
-
.map(|exported| (exported.path.clone(), exported.declaration.name.clone()))
|
|
125
|
-
.collect();
|
|
126
|
-
|
|
127
|
-
for file in &project.files {
|
|
128
|
-
let path = normalize_against(&project.root, &file.path);
|
|
129
|
-
declarations.extend(file.declarations.iter().cloned().map(|declaration| {
|
|
130
|
-
IndexedDeclaration {
|
|
131
|
-
path: path.clone(),
|
|
132
|
-
declaration,
|
|
133
|
-
}
|
|
134
|
-
}));
|
|
135
|
-
members.extend(file.members.iter().cloned().map(|member| IndexedMember {
|
|
136
|
-
path: path.clone(),
|
|
137
|
-
member,
|
|
138
|
-
}));
|
|
139
|
-
for reference in &file.references {
|
|
140
|
-
references_by_name
|
|
141
|
-
.entry(reference.name.clone())
|
|
142
|
-
.or_default()
|
|
143
|
-
.push(IndexedReference { path: path.clone() });
|
|
144
|
-
}
|
|
145
|
-
}
|
|
146
|
-
extend_generated_provider_owner_references(&mut references_by_name, &declarations);
|
|
147
|
-
|
|
148
|
-
Self {
|
|
149
|
-
declarations,
|
|
150
|
-
members,
|
|
151
|
-
references_by_name,
|
|
152
|
-
library_by_path,
|
|
153
|
-
public_exports,
|
|
154
|
-
public_exported_declarations,
|
|
155
|
-
}
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
fn reference_count(&self, name: &str, reachable_files: &BTreeSet<PathBuf>) -> usize {
|
|
159
|
-
self.references_by_name.get(name).map_or(0, |references| {
|
|
160
|
-
references
|
|
161
|
-
.iter()
|
|
162
|
-
.filter(|reference| reachable_files.contains(&reference.path))
|
|
163
|
-
.count()
|
|
164
|
-
})
|
|
165
|
-
}
|
|
166
|
-
|
|
167
|
-
fn library_reference_count(
|
|
168
|
-
&self,
|
|
169
|
-
name: &str,
|
|
170
|
-
library: &Path,
|
|
171
|
-
reachable_files: &BTreeSet<PathBuf>,
|
|
172
|
-
) -> usize {
|
|
173
|
-
self.references_by_name.get(name).map_or(0, |references| {
|
|
174
|
-
references
|
|
175
|
-
.iter()
|
|
176
|
-
.filter(|reference| reachable_files.contains(&reference.path))
|
|
177
|
-
.filter(|reference| self.library_path(&reference.path) == library)
|
|
178
|
-
.count()
|
|
179
|
-
})
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
fn library_path<'a>(&'a self, path: &'a Path) -> &'a Path {
|
|
183
|
-
self.library_by_path
|
|
184
|
-
.get(path)
|
|
185
|
-
.map_or(path, std::path::PathBuf::as_path)
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
fn is_public_export(&self, path: &Path, name: &str) -> bool {
|
|
189
|
-
self.public_exports
|
|
190
|
-
.contains(&(path.to_path_buf(), name.to_owned()))
|
|
191
|
-
}
|
|
192
|
-
}
|
|
193
117
|
/// Find the first conservative unused-export symbol findings.
|
|
194
118
|
#[must_use]
|
|
195
119
|
pub fn analyze_symbols(
|
|
@@ -419,9 +343,16 @@ fn unused_member_from_declaration(
|
|
|
419
343
|
return None;
|
|
420
344
|
}
|
|
421
345
|
|
|
422
|
-
let
|
|
423
|
-
|
|
424
|
-
|
|
346
|
+
let reference_count = if indexed.member.kind == MemberKind::EnumConstant {
|
|
347
|
+
index.qualified_reference_count(
|
|
348
|
+
&indexed.member.owner,
|
|
349
|
+
&indexed.member.name,
|
|
350
|
+
reachable_files,
|
|
351
|
+
) + index.qualified_reference_count(&indexed.member.owner, "values", reachable_files)
|
|
352
|
+
} else {
|
|
353
|
+
let library = index.library_path(&indexed.path);
|
|
354
|
+
index.library_reference_count(&indexed.member.name, library, reachable_files)
|
|
355
|
+
};
|
|
425
356
|
if reference_count != 0 {
|
|
426
357
|
return None;
|
|
427
358
|
}
|