Skip to content

Commit

Permalink
Fix for pubspec edits when removing a line between entries.
Browse files Browse the repository at this point in the history
Change-Id: Ie4a74e70f836b8f20631d2cd1cac8c962554d3d3
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/362840
Commit-Queue: Keerti Parthasarathy <[email protected]>
Reviewed-by: Brian Wilkerson <[email protected]>
  • Loading branch information
keertip authored and Commit Queue committed Apr 15, 2024
1 parent e067bf7 commit 0199e9d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,14 @@ class PubspecFixGenerator {
// Go through entries and remove each one.
for (var dep in removeDevDeps) {
MapEntry<dynamic, YamlNode>? currentEntry, nextEntry, prevEntry;
for (var entry in section.nodes.entries) {
var length = section.nodes.entries.length;
for (int i = 0; i < length; i++) {
var entry = section.nodes.entries.elementAt(i);
if (entry.key.value == dep) {
currentEntry = entry;
continue;
}
if (currentEntry != null) {
nextEntry = entry;
if (i + 1 < length) {
nextEntry = section.nodes.entries.elementAt(i + 1);
}
break;
}
prevEntry = entry;
Expand Down Expand Up @@ -240,7 +241,17 @@ class PubspecFixGenerator {
var endOffset = nextEntry == null
? currentEntry.value.span.end.offset
: (nextEntry.key as YamlNode).span.start.offset;

// If entry in the middle of two other entries that are not to be
// removed, delete the line.
if (prevEntry != null &&
nextEntry != null &&
!removeDevDeps.contains(prevEntry.key.value) &&
!removeDevDeps.contains(nextEntry.key.value)) {
var line = (currentEntry.key as YamlNode).span.start.line;
startOffset = lineInfo.lineStarts[line];
var nextLine = (nextEntry.key as YamlNode).span.start.line;
endOffset = lineInfo.lineStarts[nextLine];
}
if (edit == null) {
edit = _Range(startOffset, endOffset);
} else if (edit.endOffset > startOffset) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,9 +149,6 @@ void bad() {

@reflectiveTest
class PubspecFixTest extends BulkFixProcessorTest {
@FailingTest(
reason: 'TODO(keertip: Fix issue with deletes where the entry to'
'be removed is in between entries.')
Future<void> test_delete_change() async {
var content = '''
name: test
Expand Down

0 comments on commit 0199e9d

Please sign in to comment.