Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consume until end of document if there is no newline when removing from #76

Merged
merged 1 commit into from
May 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions lib/src/map_mutations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,9 @@ SourceEdit _removeFromBlockMap(
// because there is no value (e.g. `key: \n`). Because [valueNode.span] in
// such cases point to the colon `:`.
end = nextNewLine;
} else {
// Remove everything until the end of the document, if there is no newline
end = yaml.length;
}
return SourceEdit(start, end - start, '{}');
}
Expand All @@ -201,6 +204,9 @@ SourceEdit _removeFromBlockMap(
final nextNewLine = yaml.indexOf(lineEnding, end);
if (nextNewLine != -1) {
end = nextNewLine + lineEnding.length;
} else {
// Remove everything until the end of the document, if there is no newline
end = yaml.length;
}

final nextNode = getNextKeyNode(map, keyNode);
Expand Down
24 changes: 24 additions & 0 deletions test/remove_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,30 @@ b:
c: 3
'''));
});

test('issue #55 reopend', () {
final doc = YamlEditor('''name: sample
version: 0.1.0
environment:
sdk: ^3.0.0
dependencies:
retry: ^3.1.2
dev_dependencies:
retry:''');
doc.remove(['dev_dependencies']);
});

test('issue #55 reopend, variant 2', () {
final doc = YamlEditor('''name: sample
version: 0.1.0
environment:
sdk: ^3.0.0
dependencies:
retry: ^3.1.2
dev_dependencies:
retry:''');
doc.remove(['dev_dependencies', 'retry']);
});
});

group('flow map', () {
Expand Down