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.
@@ -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
- && let Some(decoded) = decode_hex_pair(high, low)
540
- {
541
- output.push(char::from(decoded));
542
- continue;
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 {
@@ -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
- && let Some(complexity) = health.complexity.first()
77
- {
78
- steps.push(NextStep {
79
- id: "complexity-breakdown".to_owned(),
80
- command: format!(
81
- "dart-decimate health --format json --complexity-breakdown --top 1 --max-cyclomatic {} --max-cognitive {}",
82
- health.options.max_cyclomatic, health.options.max_cognitive
83
- ),
84
- reason: format!(
85
- "Explain the decision points driving complexity in {}",
86
- display_path(root, &complexity.path)
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
- && let Some(reachability) = reachability_by_fingerprint.get(fingerprint)
132
- {
133
- properties.insert("securityReachability".to_owned(), reachability.clone());
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
- && rest.chars().next().is_none_or(char::is_whitespace)
227
- {
228
- let (rules, reason) = split_reason(rest.trim_start());
229
- return Some(ParsedSuppression {
230
- rules: rules
231
- .split(|character: char| character == ',' || character.is_whitespace())
232
- .filter(|rule| !rule.is_empty())
233
- .map(str::to_owned)
234
- .collect(),
235
- has_reason: reason.is_some_and(|value| !value.trim().is_empty()),
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
@@ -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
- self.discover_pubspec(package_root, visited)?;
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]);
@@ -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
- && !is_comment_match(source, index)
316
- && let Some((value, end)) = read_string(source, index)
317
- {
318
- literals.push(StringLiteral { index, value });
319
- index = end;
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
- && !has_ancestor_kind(node, &["annotation"])
121
- && let Some(constructor) = constructor_type_name(node, source)
122
- {
123
- constructors.extend(constructor_name_candidates(&constructor));
124
- } else if is_arrow_body_constructor_identifier(node, source)
125
- && let Ok(constructor) = node.utf8_text(source.as_bytes())
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