dart-decimate 0.0.1 → 0.0.3
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 +22 -27
- package/Cargo.toml +2 -2
- package/README.md +70 -10
- package/assets/dart-decimate-banner.png +0 -0
- package/npm/bin/dart-decimate-mcp.js +2 -45
- package/npm/bin/dart-decimate.js +2 -45
- package/npm/bin/runner.js +79 -0
- package/npm/scripts/postinstall.js +159 -25
- package/npm/scripts/test-npx-local.js +1 -2
- package/npm/scripts/test-npx-mcp-local.js +5 -1
- package/npm/scripts/test-npx-prebuilt.js +126 -0
- package/npm/scripts/test-postinstall-prebuilt.js +122 -0
- package/package.json +3 -1
- package/src/cli/coverage_run.rs +12 -12
- package/src/cli/request_args.rs +4 -4
- package/src/dart_parser.rs +17 -14
- package/src/extract/members.rs +4 -4
- package/src/extract/primary_constructors.rs +5 -5
- package/src/extract/references.rs +7 -7
- package/src/extract/routes.rs +40 -38
- package/src/extract/signatures.rs +8 -8
- package/src/extract/strings.rs +3 -2
- package/src/extract.rs +8 -8
- package/src/graph.rs +25 -24
- package/src/health/runtime_coverage.rs +5 -5
- package/src/output/next_steps.rs +14 -14
- package/src/output/security_sarif.rs +4 -4
- package/src/output/suppressions.rs +12 -12
- package/src/package_map.rs +4 -3
- package/src/security/detect.rs +6 -7
- package/src/widgets/unrendered.rs +8 -9
|
@@ -535,11 +535,11 @@ fn decode_runtime_path(raw_path: &str) -> String {
|
|
|
535
535
|
if byte == b'%' {
|
|
536
536
|
let high = bytes.next();
|
|
537
537
|
let low = bytes.next();
|
|
538
|
-
if let (Some(high), Some(low)) = (high, low)
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
538
|
+
if let (Some(high), Some(low)) = (high, low) {
|
|
539
|
+
if let Some(decoded) = decode_hex_pair(high, low) {
|
|
540
|
+
output.push(char::from(decoded));
|
|
541
|
+
continue;
|
|
542
|
+
}
|
|
543
543
|
}
|
|
544
544
|
output.push('%');
|
|
545
545
|
if let Some(high) = high {
|
package/src/output/next_steps.rs
CHANGED
|
@@ -72,20 +72,20 @@ pub(super) fn next_steps(root: &Path, results: &AnalysisResults) -> Vec<NextStep
|
|
|
72
72
|
});
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
if let Some(health) = &results.health
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
)
|
|
88
|
-
}
|
|
75
|
+
if let Some(health) = &results.health {
|
|
76
|
+
if let Some(complexity) = health.complexity.first() {
|
|
77
|
+
steps.push(NextStep {
|
|
78
|
+
id: "complexity-breakdown".to_owned(),
|
|
79
|
+
command: format!(
|
|
80
|
+
"dart-decimate health --format json --complexity-breakdown --top 1 --max-cyclomatic {} --max-cognitive {}",
|
|
81
|
+
health.options.max_cyclomatic, health.options.max_cognitive
|
|
82
|
+
),
|
|
83
|
+
reason: format!(
|
|
84
|
+
"Explain the decision points driving complexity in {}",
|
|
85
|
+
display_path(root, &complexity.path)
|
|
86
|
+
),
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
89
|
}
|
|
90
90
|
|
|
91
91
|
steps
|
|
@@ -127,10 +127,10 @@ fn result_properties(
|
|
|
127
127
|
properties.insert("safeToDelete".to_owned(), json!(finding.safe_to_delete));
|
|
128
128
|
properties.insert("files".to_owned(), json!(&finding.files));
|
|
129
129
|
properties.insert("actions".to_owned(), json!(&finding.actions));
|
|
130
|
-
if let Some(fingerprint) = &finding.fingerprint
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
130
|
+
if let Some(fingerprint) = &finding.fingerprint {
|
|
131
|
+
if let Some(reachability) = reachability_by_fingerprint.get(fingerprint) {
|
|
132
|
+
properties.insert("securityReachability".to_owned(), reachability.clone());
|
|
133
|
+
}
|
|
134
134
|
}
|
|
135
135
|
Value::Object(properties)
|
|
136
136
|
}
|
|
@@ -222,18 +222,18 @@ struct ParsedSuppression {
|
|
|
222
222
|
fn parse_suppression(line: &str) -> Option<ParsedSuppression> {
|
|
223
223
|
let comment = line.trim_start().strip_prefix("//")?.trim_start();
|
|
224
224
|
for directive in ["dart-decimate-ignore-next-line"] {
|
|
225
|
-
if let Some(rest) = comment.strip_prefix(directive)
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
.
|
|
235
|
-
|
|
236
|
-
}
|
|
225
|
+
if let Some(rest) = comment.strip_prefix(directive) {
|
|
226
|
+
if rest.chars().next().is_none_or(char::is_whitespace) {
|
|
227
|
+
let (rules, reason) = split_reason(rest.trim_start());
|
|
228
|
+
return Some(ParsedSuppression {
|
|
229
|
+
rules: rules
|
|
230
|
+
.split(|character: char| character == ',' || character.is_whitespace())
|
|
231
|
+
.filter(|rule| !rule.is_empty())
|
|
232
|
+
.map(str::to_owned)
|
|
233
|
+
.collect(),
|
|
234
|
+
has_reason: reason.is_some_and(|value| !value.trim().is_empty()),
|
|
235
|
+
});
|
|
236
|
+
}
|
|
237
237
|
}
|
|
238
238
|
}
|
|
239
239
|
None
|
package/src/package_map.rs
CHANGED
|
@@ -155,9 +155,10 @@ impl PackageMap {
|
|
|
155
155
|
self.discover_nested_pubspecs(&path, visited)?;
|
|
156
156
|
} else if file_type.is_file()
|
|
157
157
|
&& path.file_name().is_some_and(|name| name == "pubspec.yaml")
|
|
158
|
-
&& let Some(package_root) = path.parent()
|
|
159
158
|
{
|
|
160
|
-
|
|
159
|
+
if let Some(package_root) = path.parent() {
|
|
160
|
+
self.discover_pubspec(package_root, visited)?;
|
|
161
|
+
}
|
|
161
162
|
}
|
|
162
163
|
}
|
|
163
164
|
|
|
@@ -315,7 +316,7 @@ fn percent_decode(value: &str) -> Option<String> {
|
|
|
315
316
|
if bytes[index] == b'%' {
|
|
316
317
|
let high = hex_value(*bytes.get(index + 1)?)?;
|
|
317
318
|
let low = hex_value(*bytes.get(index + 2)?)?;
|
|
318
|
-
decoded.push(high << 4 | low);
|
|
319
|
+
decoded.push((high << 4) | low);
|
|
319
320
|
index += 3;
|
|
320
321
|
} else {
|
|
321
322
|
decoded.push(bytes[index]);
|
package/src/security/detect.rs
CHANGED
|
@@ -311,13 +311,12 @@ fn string_literals(source: &str) -> Vec<StringLiteral> {
|
|
|
311
311
|
let mut index = 0;
|
|
312
312
|
let bytes = source.as_bytes();
|
|
313
313
|
while index < bytes.len() {
|
|
314
|
-
if matches!(bytes[index], b'\'' | b'"')
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
continue;
|
|
314
|
+
if matches!(bytes[index], b'\'' | b'"') && !is_comment_match(source, index) {
|
|
315
|
+
if let Some((value, end)) = read_string(source, index) {
|
|
316
|
+
literals.push(StringLiteral { index, value });
|
|
317
|
+
index = end;
|
|
318
|
+
continue;
|
|
319
|
+
}
|
|
321
320
|
}
|
|
322
321
|
index += 1;
|
|
323
322
|
}
|
|
@@ -116,15 +116,14 @@ fn is_abstract_class(class: Node<'_>, source: &str) -> bool {
|
|
|
116
116
|
fn object_constructor_names(root: Node<'_>, source: &str) -> Vec<String> {
|
|
117
117
|
let mut constructors = Vec::new();
|
|
118
118
|
visit_named(root, &mut |node| {
|
|
119
|
-
if is_object_constructor(node)
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
constructors.extend(constructor_name_candidates(constructor));
|
|
119
|
+
if is_object_constructor(node) && !has_ancestor_kind(node, &["annotation"]) {
|
|
120
|
+
if let Some(constructor) = constructor_type_name(node, source) {
|
|
121
|
+
constructors.extend(constructor_name_candidates(&constructor));
|
|
122
|
+
}
|
|
123
|
+
} else if is_arrow_body_constructor_identifier(node, source) {
|
|
124
|
+
if let Ok(constructor) = node.utf8_text(source.as_bytes()) {
|
|
125
|
+
constructors.extend(constructor_name_candidates(constructor));
|
|
126
|
+
}
|
|
128
127
|
}
|
|
129
128
|
});
|
|
130
129
|
constructors
|