-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix removal of last key from map in block-mode when value is empty. Fixes dart-lang/yaml_edit#55. When the value is empty the `SourceSpan` for the `YamlNode` representing the value in a map points to the colon. Example: ```yaml foo: bar: ``` The `YamlNode` for `foo.bar` has a value of `null` and starts and ends at the colon `:` following `bar`. This means that removal might leave the colon behind, which causes invalid YAML. We have the same issue when removing `foo.bar` from the following YAML document: ```yaml foo: baz: true bar: ``` However, in this case, we have a hack that ensures we always strip away the any comments that follows `bar`. We do this by deleting up-to the next newline. If we apply the same hack when removing `foo.bar` in the first example, then it works. One could argue that it works by accident, but it's kind of desired that trailing comments are removed, when the value they are trailing is removed.
- Loading branch information
Showing
15 changed files
with
114 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
TEST FOR ISSUE #55 -- https://github.com/dart-lang/yaml_edit/issues/55 | ||
--- | ||
name: sample | ||
version: 0.1.0 | ||
environment: | ||
sdk: ^3.0.0 | ||
dependencies: | ||
dev_dependencies: | ||
retry: | ||
--- | ||
- [remove, ['dev_dependencies', 'retry']] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
REMOVE KEY FROM MAP | ||
--- | ||
foo: true | ||
bar: false | ||
--- | ||
- [remove, [bar]] |
6 changes: 6 additions & 0 deletions
6
pkgs/yaml_edit/test/testdata/input/remove_key_with_trailing_comma.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
REMOVE KEY FROM MAP WITH TRAILING COMMA | ||
--- | ||
foo: true | ||
bar: false # remove this comment | ||
--- | ||
- [remove, [bar]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
REMOVE NESTED KEY FROM MAP | ||
--- | ||
A: true | ||
B: | ||
foo: true | ||
bar: true | ||
--- | ||
- [remove, [B, foo]] | ||
- [remove, [B, bar]] |
7 changes: 7 additions & 0 deletions
7
pkgs/yaml_edit/test/testdata/input/remove_nested_key_with_null.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
REMOVE NESTED KEY FROM MAP WITH NULL | ||
--- | ||
A: true | ||
B: | ||
foo: | ||
--- | ||
- [remove, [B, foo]] |
7 changes: 7 additions & 0 deletions
7
pkgs/yaml_edit/test/testdata/input/remove_nested_key_with_trailing_comma.test
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
REMOVE NESTED KEY FROM MAP WITH TRAILING COMMA | ||
--- | ||
A: true | ||
B: | ||
bar: false # remove this comment | ||
--- | ||
- [remove, [B, bar]] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
name: sample | ||
version: 0.1.0 | ||
environment: | ||
sdk: ^3.0.0 | ||
dependencies: | ||
dev_dependencies: | ||
retry: | ||
--- | ||
name: sample | ||
version: 0.1.0 | ||
environment: | ||
sdk: ^3.0.0 | ||
dependencies: | ||
dev_dependencies: | ||
{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
foo: true | ||
bar: false | ||
--- | ||
foo: true |
4 changes: 4 additions & 0 deletions
4
pkgs/yaml_edit/test/testdata/output/remove_key_with_trailing_comma.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
foo: true | ||
bar: false # remove this comment | ||
--- | ||
foo: true |
12 changes: 12 additions & 0 deletions
12
pkgs/yaml_edit/test/testdata/output/remove_nested_key.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
A: true | ||
B: | ||
foo: true | ||
bar: true | ||
--- | ||
A: true | ||
B: | ||
bar: true | ||
--- | ||
A: true | ||
B: | ||
{} |
7 changes: 7 additions & 0 deletions
7
pkgs/yaml_edit/test/testdata/output/remove_nested_key_with_null.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
A: true | ||
B: | ||
foo: | ||
--- | ||
A: true | ||
B: | ||
{} |
7 changes: 7 additions & 0 deletions
7
pkgs/yaml_edit/test/testdata/output/remove_nested_key_with_trailing_comma.golden
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
A: true | ||
B: | ||
bar: false # remove this comment | ||
--- | ||
A: true | ||
B: | ||
{} |