dart-decimate 0.0.38 → 0.0.40

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.
@@ -125,11 +125,118 @@ fn normalize_modern_dart_compatibility(source: &str) -> Option<String> {
125
125
  let mut normalized = normalize_primary_constructors(source);
126
126
  let mut output = normalized.take().unwrap_or_else(|| source.to_owned());
127
127
  let mut changed = output != source;
128
+ changed |= normalize_concise_constructors(&mut output);
128
129
  changed |= normalize_dot_shorthands(&mut output);
129
130
  changed |= normalize_null_aware_collection_elements(&mut output);
130
131
  changed.then_some(output)
131
132
  }
132
133
 
134
+ fn normalize_concise_constructors(source: &mut String) -> bool {
135
+ let mut replacements = Vec::new();
136
+ let mut cursor = 0;
137
+
138
+ while let Some((keyword_start, keyword)) = find_next_header_keyword(source, cursor) {
139
+ let Some((class_name, body_start, body_end)) =
140
+ class_body(source, keyword_start + keyword.len(), keyword)
141
+ else {
142
+ cursor = keyword_start + keyword.len();
143
+ continue;
144
+ };
145
+ push_concise_constructor_replacements(
146
+ source,
147
+ body_start + 1,
148
+ body_end,
149
+ &class_name,
150
+ &mut replacements,
151
+ );
152
+ cursor = body_end + 1;
153
+ }
154
+
155
+ apply_text_replacements(source, replacements)
156
+ }
157
+
158
+ fn class_body(
159
+ source: &str,
160
+ cursor: usize,
161
+ keyword: &'static str,
162
+ ) -> Option<(String, usize, usize)> {
163
+ let mut name_start = skip_whitespace(source, cursor)?;
164
+ if matches!(keyword, "class" | "enum") && starts_keyword(source, name_start, "const") {
165
+ name_start = skip_whitespace(source, name_start + "const".len())?;
166
+ }
167
+ let name_end = identifier_end(source, name_start)?;
168
+ let name = source[name_start..name_end].to_owned();
169
+ let (body_start, terminator) = find_header_terminator(source, name_end)?;
170
+ if terminator != b'{' {
171
+ return None;
172
+ }
173
+ let body_end = matching_delimiter(source, body_start, b'{', b'}')?;
174
+ Some((name, body_start, body_end))
175
+ }
176
+
177
+ fn push_concise_constructor_replacements(
178
+ source: &str,
179
+ start: usize,
180
+ end: usize,
181
+ class_name: &str,
182
+ replacements: &mut Vec<(usize, usize, String)>,
183
+ ) {
184
+ let bytes = source.as_bytes();
185
+ let mut cursor = start;
186
+ while cursor < end {
187
+ if let Some(after) = skip_non_code(source, cursor) {
188
+ cursor = after;
189
+ continue;
190
+ }
191
+ if matches!(bytes[cursor], b'{' | b'(' | b'[') {
192
+ let close = match bytes[cursor] {
193
+ b'{' => b'}',
194
+ b'(' => b')',
195
+ _ => b']',
196
+ };
197
+ if let Some(after) = matching_delimiter(source, cursor, bytes[cursor], close) {
198
+ cursor = after + 1;
199
+ continue;
200
+ }
201
+ }
202
+ if starts_keyword(source, cursor, "new")
203
+ && let Some((suffix, after_suffix)) = concise_constructor_suffix(source, cursor + 3)
204
+ {
205
+ replacements.push((cursor, after_suffix, format!("{class_name}{suffix}")));
206
+ cursor = after_suffix;
207
+ continue;
208
+ }
209
+ if starts_keyword(source, cursor, "factory")
210
+ && let Some((suffix, after_suffix)) = concise_constructor_suffix(source, cursor + 7)
211
+ {
212
+ replacements.push((
213
+ cursor,
214
+ after_suffix,
215
+ format!("factory {class_name}{suffix}"),
216
+ ));
217
+ cursor = after_suffix;
218
+ continue;
219
+ }
220
+ cursor += 1;
221
+ }
222
+ }
223
+
224
+ fn concise_constructor_suffix(source: &str, cursor: usize) -> Option<(String, usize)> {
225
+ let suffix_start = skip_whitespace(source, cursor)?;
226
+ if source.as_bytes().get(suffix_start).copied() == Some(b'(') {
227
+ return Some((String::new(), suffix_start));
228
+ }
229
+ let suffix_end = identifier_end(source, suffix_start)?;
230
+ let after_suffix = skip_whitespace(source, suffix_end)?;
231
+ if source.as_bytes().get(after_suffix).copied() != Some(b'(') {
232
+ return None;
233
+ }
234
+ Some((
235
+ format!(".{}", &source[suffix_start..suffix_end]),
236
+ after_suffix,
237
+ ))
238
+ }
239
+
133
240
  fn normalize_primary_constructors(source: &str) -> Option<String> {
134
241
  let mut replacements = Vec::new();
135
242
  let mut cursor = 0;
@@ -175,11 +282,10 @@ fn primary_constructor_header(
175
282
  let class_name = source[name_start..name_end].to_owned();
176
283
  let mut header_cursor = skip_whitespace(source, name_end).unwrap_or(name_end);
177
284
 
178
- if source.as_bytes().get(header_cursor).copied() == Some(b'<') {
179
- if let Some(type_params_end) = matching_delimiter(source, header_cursor, b'<', b'>') {
180
- header_cursor =
181
- skip_whitespace(source, type_params_end + 1).unwrap_or(type_params_end + 1);
182
- }
285
+ if source.as_bytes().get(header_cursor).copied() == Some(b'<')
286
+ && let Some(type_params_end) = matching_delimiter(source, header_cursor, b'<', b'>')
287
+ {
288
+ header_cursor = skip_whitespace(source, type_params_end + 1).unwrap_or(type_params_end + 1);
183
289
  }
184
290
 
185
291
  let replacement_start = primary_constructor_replacement_start(source, &mut header_cursor)?;
@@ -268,18 +374,16 @@ fn push_constructor_body_replacement(
268
374
  replacements: &mut Vec<Replacement>,
269
375
  header: &PrimaryConstructorHeader,
270
376
  ) {
271
- if let Some((terminator_start, _)) = header.terminator {
272
- if let Some(body_end) = matching_delimiter(source, terminator_start, b'{', b'}') {
273
- if let Some(this_start) =
274
- find_primary_constructor_body(source, terminator_start + 1, body_end)
275
- {
276
- replacements.push(Replacement {
277
- start: this_start,
278
- end: this_start + "this".len(),
279
- kind: ReplacementKind::ConstructorBody(header.class_name.clone()),
280
- });
281
- }
282
- }
377
+ if let Some((terminator_start, _)) = header.terminator
378
+ && let Some(body_end) = matching_delimiter(source, terminator_start, b'{', b'}')
379
+ && let Some(this_start) =
380
+ find_primary_constructor_body(source, terminator_start + 1, body_end)
381
+ {
382
+ replacements.push(Replacement {
383
+ start: this_start,
384
+ end: this_start + "this".len(),
385
+ kind: ReplacementKind::ConstructorBody(header.class_name.clone()),
386
+ });
283
387
  }
284
388
  }
285
389
 
@@ -321,6 +425,10 @@ fn normalize_dot_shorthands(source: &mut String) -> bool {
321
425
  let mut replacements = Vec::new();
322
426
  let mut cursor = 0;
323
427
  while cursor < bytes.len() {
428
+ if let Some(after) = skip_non_code(source, cursor) {
429
+ cursor = after;
430
+ continue;
431
+ }
324
432
  if bytes[cursor] != b'.' {
325
433
  cursor += 1;
326
434
  continue;
@@ -372,11 +480,18 @@ fn is_dot_shorthand_start(bytes: &[u8], cursor: usize) -> bool {
372
480
  fn normalize_null_aware_collection_elements(source: &mut String) -> bool {
373
481
  let bytes = source.as_bytes().to_vec();
374
482
  let mut replacements = Vec::new();
375
- for cursor in 0..bytes.len() {
483
+ let mut cursor = 0;
484
+ while cursor < bytes.len() {
485
+ if let Some(after) = skip_non_code(source, cursor) {
486
+ cursor = after;
487
+ continue;
488
+ }
376
489
  if bytes[cursor] != b'?' || !is_null_aware_collection_marker(&bytes, cursor) {
490
+ cursor += 1;
377
491
  continue;
378
492
  }
379
493
  replacements.push((cursor, cursor + 1, " ".to_owned()));
494
+ cursor += 1;
380
495
  }
381
496
  apply_text_replacements(source, replacements)
382
497
  }
@@ -412,11 +527,14 @@ fn find_header_terminator(source: &str, start: usize) -> Option<(usize, u8)> {
412
527
  let bytes = source.as_bytes();
413
528
  let mut cursor = start;
414
529
  while cursor < bytes.len() {
530
+ if let Some(after) = skip_non_code(source, cursor) {
531
+ cursor = after;
532
+ continue;
533
+ }
415
534
  match bytes[cursor] {
416
535
  b'{' | b';' => return Some((cursor, bytes[cursor])),
417
536
  b'(' => cursor = matching_delimiter(source, cursor, b'(', b')')?,
418
537
  b'<' => cursor = matching_delimiter(source, cursor, b'<', b'>')?,
419
- b'\'' | b'"' => cursor = skip_quoted(source, cursor)?,
420
538
  _ => {}
421
539
  }
422
540
  cursor += 1;
@@ -471,10 +589,13 @@ fn find_primary_constructor_body(source: &str, start: usize, end: usize) -> Opti
471
589
  let mut depth = 0usize;
472
590
  let mut cursor = start;
473
591
  while cursor < end {
592
+ if let Some(after) = skip_non_code(source, cursor) {
593
+ cursor = after;
594
+ continue;
595
+ }
474
596
  match bytes[cursor] {
475
597
  b'{' | b'(' | b'[' => depth += 1,
476
598
  b'}' | b')' | b']' => depth = depth.saturating_sub(1),
477
- b'\'' | b'"' => cursor = skip_quoted(source, cursor)?,
478
599
  _ if depth == 0 && starts_keyword(source, cursor, "this") => {
479
600
  let after_this = skip_whitespace(source, cursor + "this".len())?;
480
601
  if matches!(
@@ -494,6 +615,10 @@ fn find_primary_constructor_body(source: &str, start: usize, end: usize) -> Opti
494
615
  fn find_next_header_keyword(source: &str, start: usize) -> Option<(usize, &'static str)> {
495
616
  let mut cursor = start;
496
617
  while cursor < source.len() {
618
+ if let Some(after) = skip_non_code(source, cursor) {
619
+ cursor = after;
620
+ continue;
621
+ }
497
622
  if starts_keyword(source, cursor, "class") {
498
623
  return Some((cursor, "class"));
499
624
  }
@@ -555,6 +680,10 @@ fn matching_delimiter(source: &str, start: usize, open: u8, close: u8) -> Option
555
680
  let mut depth = 0usize;
556
681
  let mut cursor = start;
557
682
  while cursor < bytes.len() {
683
+ if let Some(after) = skip_non_code(source, cursor) {
684
+ cursor = after;
685
+ continue;
686
+ }
558
687
  match bytes[cursor] {
559
688
  byte if byte == open => depth += 1,
560
689
  byte if byte == close => {
@@ -563,7 +692,6 @@ fn matching_delimiter(source: &str, start: usize, open: u8, close: u8) -> Option
563
692
  return Some(cursor);
564
693
  }
565
694
  }
566
- b'\'' | b'"' => cursor = skip_quoted(source, cursor)?,
567
695
  _ => {}
568
696
  }
569
697
  cursor += 1;
@@ -571,17 +699,65 @@ fn matching_delimiter(source: &str, start: usize, open: u8, close: u8) -> Option
571
699
  None
572
700
  }
573
701
 
574
- fn skip_quoted(source: &str, start: usize) -> Option<usize> {
575
- let quote = source.as_bytes().get(start).copied()?;
576
- let mut cursor = start + 1;
577
- while cursor < source.len() {
578
- match source.as_bytes()[cursor] {
579
- b'\\' => cursor += 2,
580
- byte if byte == quote => return Some(cursor),
581
- _ => cursor += 1,
702
+ fn skip_non_code(source: &str, start: usize) -> Option<usize> {
703
+ let bytes = source.as_bytes();
704
+ if bytes.get(start..start + 2) == Some(b"//") {
705
+ return Some(
706
+ bytes[start + 2..]
707
+ .iter()
708
+ .position(|byte| *byte == b'\n')
709
+ .map_or(bytes.len(), |offset| start + 2 + offset),
710
+ );
711
+ }
712
+ if bytes.get(start..start + 2) == Some(b"/*") {
713
+ let mut depth = 1usize;
714
+ let mut cursor = start + 2;
715
+ while cursor < bytes.len() {
716
+ if bytes.get(cursor..cursor + 2) == Some(b"/*") {
717
+ depth += 1;
718
+ cursor += 2;
719
+ } else if bytes.get(cursor..cursor + 2) == Some(b"*/") {
720
+ depth -= 1;
721
+ cursor += 2;
722
+ if depth == 0 {
723
+ return Some(cursor);
724
+ }
725
+ } else {
726
+ cursor += 1;
727
+ }
582
728
  }
729
+ return Some(bytes.len());
583
730
  }
584
- None
731
+
732
+ let raw = matches!(bytes.get(start), Some(b'r' | b'R'))
733
+ && matches!(bytes.get(start + 1), Some(b'\'' | b'"'))
734
+ && !source
735
+ .get(..start)
736
+ .and_then(|prefix| prefix.chars().next_back())
737
+ .is_some_and(is_identifier_char);
738
+ let quote_start = if raw { start + 1 } else { start };
739
+ let quote = bytes.get(quote_start).copied()?;
740
+ if !matches!(quote, b'\'' | b'"') {
741
+ return None;
742
+ }
743
+ let triple = bytes.get(quote_start..quote_start + 3) == Some(&[quote, quote, quote]);
744
+ let delimiter_len = if triple { 3 } else { 1 };
745
+ let mut cursor = quote_start + delimiter_len;
746
+ while cursor < bytes.len() {
747
+ if !raw && bytes[cursor] == b'\\' {
748
+ cursor = (cursor + 2).min(bytes.len());
749
+ continue;
750
+ }
751
+ if triple {
752
+ if bytes.get(cursor..cursor + 3) == Some(&[quote, quote, quote]) {
753
+ return Some(cursor + 3);
754
+ }
755
+ } else if bytes[cursor] == quote {
756
+ return Some(cursor + 1);
757
+ }
758
+ cursor += 1;
759
+ }
760
+ Some(bytes.len())
585
761
  }
586
762
 
587
763
  fn push_preserved_whitespace(output: &mut String, span: &str) {
@@ -614,7 +790,7 @@ fn is_identifier_char(ch: char) -> bool {
614
790
  mod tests {
615
791
  use std::path::Path;
616
792
 
617
- use super::{DartParseError, parse_dart_source_strict};
793
+ use super::{DartParseError, normalize_modern_dart_compatibility, parse_dart_source_strict};
618
794
 
619
795
  #[test]
620
796
  fn strict_parse_normalizes_primary_constructor_headers() -> Result<(), DartParseError> {
@@ -668,6 +844,60 @@ Widget build(Banner? banner, List<Widget>? extras) {
668
844
  Ok(())
669
845
  }
670
846
 
847
+ #[test]
848
+ fn strict_parse_normalizes_concise_constructor_forms() -> Result<(), DartParseError> {
849
+ let source = r"
850
+ class Base {
851
+ new() {}
852
+ new named() : this();
853
+ const new empty();
854
+ }
855
+
856
+ class FactoryBox {
857
+ factory() => Child();
858
+ factory namedFactory() { return Child(); }
859
+ factory redirect() = Child;
860
+ const factory cached() = Child.cached;
861
+ }
862
+
863
+ class Child implements FactoryBox {
864
+ Child();
865
+ const Child.cached();
866
+ }
867
+ ";
868
+
869
+ let parsed = parse_dart_source_strict(Path::new("lib/constructors.dart"), source)?;
870
+
871
+ assert!(!parsed.tree().root_node().has_error());
872
+ assert!(parsed.source().contains("Base.named()"));
873
+ assert!(parsed.source().contains("factory FactoryBox.redirect()"));
874
+
875
+ Ok(())
876
+ }
877
+
878
+ #[test]
879
+ fn compatibility_normalizer_never_changes_comments_or_strings() {
880
+ let source = r#"
881
+ class Example {
882
+ // new fake() {} .center ?value
883
+ /* nested /* new nested() {} */ .center */
884
+ static const text = "new quoted() {} .center ?value";
885
+ static const raw = r'''factory raw() {} .center ?value''';
886
+ new() {}
887
+ }
888
+ "#;
889
+
890
+ let Some(normalized) = normalize_modern_dart_compatibility(source) else {
891
+ panic!("code was not normalized");
892
+ };
893
+
894
+ assert!(normalized.contains("// new fake() {} .center ?value"));
895
+ assert!(normalized.contains("/* nested /* new nested() {} */ .center */"));
896
+ assert!(normalized.contains("\"new quoted() {} .center ?value\""));
897
+ assert!(normalized.contains("r'''factory raw() {} .center ?value'''"));
898
+ assert!(normalized.contains("Example() {}"));
899
+ }
900
+
671
901
  #[test]
672
902
  fn strict_parse_keeps_unrecoverable_syntax_errors() {
673
903
  let error = parse_dart_source_strict(Path::new("lib/bad.dart"), "class {")
@@ -202,10 +202,10 @@ fn collect_member_field_names(node: Node<'_>, source: &str, names: &mut Vec<Stri
202
202
  &["static_final_declaration", "initialized_identifier"],
203
203
  names,
204
204
  );
205
- if names.is_empty() {
206
- if let Some(identifier_list) = find_first_named_descendant(node, "identifier_list") {
207
- collect_direct_identifier_children(identifier_list, source, names);
208
- }
205
+ if names.is_empty()
206
+ && let Some(identifier_list) = find_first_named_descendant(node, "identifier_list")
207
+ {
208
+ collect_direct_identifier_children(identifier_list, source, names);
209
209
  }
210
210
  }
211
211
 
@@ -76,11 +76,11 @@ fn primary_constructor_headers(source: &str) -> Vec<PrimaryConstructorHeader> {
76
76
  };
77
77
  let declaration = source[name_start..name_end].to_owned();
78
78
  let mut header_cursor = skip_whitespace(source, name_end).unwrap_or(name_end);
79
- if source.as_bytes().get(header_cursor).copied() == Some(b'<') {
80
- if let Some(type_params_end) = matching_delimiter(source, header_cursor, b'<', b'>') {
81
- header_cursor =
82
- skip_whitespace(source, type_params_end + 1).unwrap_or(type_params_end + 1);
83
- }
79
+ if source.as_bytes().get(header_cursor).copied() == Some(b'<')
80
+ && let Some(type_params_end) = matching_delimiter(source, header_cursor, b'<', b'>')
81
+ {
82
+ header_cursor =
83
+ skip_whitespace(source, type_params_end + 1).unwrap_or(type_params_end + 1);
84
84
  }
85
85
  if source.as_bytes().get(header_cursor).copied() == Some(b'.') {
86
86
  let suffix_start =
@@ -20,14 +20,14 @@ fn collect_identifier_references(
20
20
  collect_string_interpolation_references(node, source, references);
21
21
  }
22
22
 
23
- if is_reference_identifier(node, source) {
24
- if let Ok(name) = node.utf8_text(source.as_bytes()) {
25
- references.push(IdentifierReference {
26
- name: name.to_owned(),
27
- qualifier: simple_member_qualifier(node, source),
28
- location: node.start_position().into(),
29
- });
30
- }
23
+ if is_reference_identifier(node, source)
24
+ && let Ok(name) = node.utf8_text(source.as_bytes())
25
+ {
26
+ references.push(IdentifierReference {
27
+ name: name.to_owned(),
28
+ qualifier: simple_member_qualifier(node, source),
29
+ location: node.start_position().into(),
30
+ });
31
31
  }
32
32
 
33
33
  let mut cursor = node.walk();
@@ -72,35 +72,35 @@ fn collect_raw_routes_in(
72
72
  parent_resolved: bool,
73
73
  routes: &mut Vec<DartRouteDeclaration>,
74
74
  ) {
75
- if is_object_constructor(node) {
76
- if let Some(route_kind) = raw_route_constructor_kind(node, source) {
77
- let next_parent = match route_kind {
78
- RawRouteKind::GoRoute => collect_go_route(
79
- node,
80
- source,
81
- constants,
82
- parent_path,
83
- parent_resolved,
84
- routes,
85
- ),
86
- RawRouteKind::RouteContainer => None,
87
- };
88
- let next_parent_resolved = match route_kind {
89
- RawRouteKind::GoRoute => next_parent.is_some(),
90
- RawRouteKind::RouteContainer => parent_resolved,
91
- };
92
- for child_routes_arg in route_child_argument_nodes(node, source) {
93
- collect_raw_routes_in(
94
- child_routes_arg,
95
- source,
96
- constants,
97
- next_parent.as_deref().or(parent_path),
98
- next_parent_resolved,
99
- routes,
100
- );
101
- }
102
- return;
75
+ if is_object_constructor(node)
76
+ && let Some(route_kind) = raw_route_constructor_kind(node, source)
77
+ {
78
+ let next_parent = match route_kind {
79
+ RawRouteKind::GoRoute => collect_go_route(
80
+ node,
81
+ source,
82
+ constants,
83
+ parent_path,
84
+ parent_resolved,
85
+ routes,
86
+ ),
87
+ RawRouteKind::RouteContainer => None,
88
+ };
89
+ let next_parent_resolved = match route_kind {
90
+ RawRouteKind::GoRoute => next_parent.is_some(),
91
+ RawRouteKind::RouteContainer => parent_resolved,
92
+ };
93
+ for child_routes_arg in route_child_argument_nodes(node, source) {
94
+ collect_raw_routes_in(
95
+ child_routes_arg,
96
+ source,
97
+ constants,
98
+ next_parent.as_deref().or(parent_path),
99
+ next_parent_resolved,
100
+ routes,
101
+ );
103
102
  }
103
+ return;
104
104
  }
105
105
 
106
106
  let mut cursor = node.walk();
@@ -235,19 +235,17 @@ fn collect_string_constants_in(
235
235
  node.kind(),
236
236
  "static_final_declaration" | "initialized_identifier"
237
237
  ) && is_const_string_declaration(node, source)
238
+ && let Some(name) = field_text(node, "name", source)
239
+ && let Some(value) = node.child_by_field_name("value").and_then(|value| {
240
+ value
241
+ .utf8_text(source.as_bytes())
242
+ .ok()
243
+ .and_then(unquote_dart_string)
244
+ })
238
245
  {
239
- if let Some(name) = field_text(node, "name", source) {
240
- if let Some(value) = node.child_by_field_name("value").and_then(|value| {
241
- value
242
- .utf8_text(source.as_bytes())
243
- .ok()
244
- .and_then(unquote_dart_string)
245
- }) {
246
- constants.insert(name.clone(), value.clone());
247
- if let Some(class_name) = containing_class_name(node, source) {
248
- constants.insert(format!("{class_name}.{name}"), value);
249
- }
250
- }
246
+ constants.insert(name.clone(), value.clone());
247
+ if let Some(class_name) = containing_class_name(node, source) {
248
+ constants.insert(format!("{class_name}.{name}"), value);
251
249
  }
252
250
  }
253
251
 
@@ -192,10 +192,10 @@ fn variable_names(node: Node<'_>, source: &str) -> Vec<String> {
192
192
  &mut names,
193
193
  );
194
194
 
195
- if names.is_empty() {
196
- if let Some(identifier_list) = find_first_named_descendant(node, "identifier_list") {
197
- collect_direct_identifier_children(identifier_list, source, &mut names);
198
- }
195
+ if names.is_empty()
196
+ && let Some(identifier_list) = find_first_named_descendant(node, "identifier_list")
197
+ {
198
+ collect_direct_identifier_children(identifier_list, source, &mut names);
199
199
  }
200
200
 
201
201
  names
@@ -218,10 +218,10 @@ fn collect_named_fields(
218
218
  owner_kinds: &[&str],
219
219
  names: &mut Vec<String>,
220
220
  ) {
221
- if owner_kinds.contains(&node.kind()) {
222
- if let Some(name) = field_text(node, "name", source) {
223
- names.push(name);
224
- }
221
+ if owner_kinds.contains(&node.kind())
222
+ && let Some(name) = field_text(node, "name", source)
223
+ {
224
+ names.push(name);
225
225
  }
226
226
 
227
227
  let mut cursor = node.walk();
@@ -13,10 +13,9 @@ fn quoted_dart_string_body(trimmed: &str) -> Option<(&str, bool)> {
13
13
  if let Some(raw) = trimmed
14
14
  .strip_prefix('r')
15
15
  .or_else(|| trimmed.strip_prefix('R'))
16
+ && let Some(quoted) = quoted_dart_string_body_without_prefix(raw)
16
17
  {
17
- if let Some(quoted) = quoted_dart_string_body_without_prefix(raw) {
18
- return Some((quoted, true));
19
- }
18
+ return Some((quoted, true));
20
19
  }
21
20
 
22
21
  quoted_dart_string_body_without_prefix(trimmed).map(|quoted| (quoted, false))
package/src/extract.rs CHANGED
@@ -557,10 +557,10 @@ fn push_variable_declarations(
557
557
  &mut names,
558
558
  );
559
559
 
560
- if names.is_empty() {
561
- if let Some(identifier_list) = find_first_named_descendant(node, "identifier_list") {
562
- collect_direct_identifier_children(identifier_list, source, &mut names);
563
- }
560
+ if names.is_empty()
561
+ && let Some(identifier_list) = find_first_named_descendant(node, "identifier_list")
562
+ {
563
+ collect_direct_identifier_children(identifier_list, source, &mut names);
564
564
  }
565
565
 
566
566
  declarations.extend(names.into_iter().map(|name| TopLevelDeclaration {
@@ -608,10 +608,10 @@ fn collect_named_fields(
608
608
  owner_kinds: &[&str],
609
609
  names: &mut Vec<String>,
610
610
  ) {
611
- if owner_kinds.contains(&node.kind()) {
612
- if let Some(name) = field_text(node, "name", source) {
613
- names.push(name);
614
- }
611
+ if owner_kinds.contains(&node.kind())
612
+ && let Some(name) = field_text(node, "name", source)
613
+ {
614
+ names.push(name);
615
615
  }
616
616
 
617
617
  let mut cursor = node.walk();
@@ -129,13 +129,12 @@ pub(super) fn add_part_dependency(
129
129
  });
130
130
  return;
131
131
  }
132
- if let Some(part) = files_by_path.get(&target_path).copied() {
133
- if let Some(relationship) =
132
+ if let Some(part) = files_by_path.get(&target_path).copied()
133
+ && let Some(relationship) =
134
134
  invalid_part_relationship(root, packages, library, part, specifier)
135
- {
136
- invalid_part_relationships.push(relationship);
137
- return;
138
- }
135
+ {
136
+ invalid_part_relationships.push(relationship);
137
+ return;
139
138
  }
140
139
  part_owners.insert(target_path.clone(), from_path.to_path_buf());
141
140