Skip to content

Commit a04e631

Browse files
authored
Merge pull request #1662 from dart-lang/merge-yaml_edit-package
Merge `package:yaml_edit`
2 parents 27f829e + cc22c3d commit a04e631

File tree

85 files changed

+8974
-1
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

85 files changed

+8974
-1
lines changed

.github/ISSUE_TEMPLATE/yaml_edit.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
name: "package:yaml_edit"
3+
about: "Create a bug or file a feature request against package:yaml_edit."
4+
labels: "package:yaml_edit"
5+
---

.github/labeler.yml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,4 +146,8 @@
146146

147147
'package:yaml':
148148
- changed-files:
149-
- any-glob-to-any-file: 'pkgs/yaml/**'
149+
- any-glob-to-any-file: 'pkgs/yaml/**'
150+
151+
'package:yaml_edit':
152+
- changed-files:
153+
- any-glob-to-any-file: 'pkgs/yaml_edit/**'

.github/workflows/yaml_edit.yaml

Lines changed: 91 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,91 @@
1+
name: package:yaml_edit
2+
3+
on:
4+
# Run on PRs and pushes to the default branch.
5+
push:
6+
branches: [ main ]
7+
paths:
8+
- '.github/workflows/yaml_edit.yaml'
9+
- 'pkgs/yaml_edit/**'
10+
pull_request:
11+
branches: [ main ]
12+
paths:
13+
- '.github/workflows/yaml_edit.yaml'
14+
- 'pkgs/yaml_edit/**'
15+
schedule:
16+
- cron: "0 0 * * 0"
17+
18+
env:
19+
PUB_ENVIRONMENT: bot.github
20+
21+
22+
defaults:
23+
run:
24+
working-directory: pkgs/yaml_edit/
25+
26+
jobs:
27+
# Check code formatting and static analysis on a single OS (linux)
28+
# against Dart dev.
29+
analyze:
30+
runs-on: ubuntu-latest
31+
strategy:
32+
fail-fast: false
33+
matrix:
34+
sdk: [dev]
35+
steps:
36+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
37+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
38+
with:
39+
sdk: ${{ matrix.sdk }}
40+
- id: install
41+
name: Install dependencies
42+
run: dart pub get
43+
- name: Check formatting
44+
run: dart format --output=none --set-exit-if-changed .
45+
if: always() && steps.install.outcome == 'success'
46+
- name: Analyze code
47+
run: dart analyze --fatal-infos
48+
if: always() && steps.install.outcome == 'success'
49+
50+
# Run tests on a matrix consisting of two dimensions:
51+
# 1. OS: ubuntu-latest, (macos-latest, windows-latest)
52+
# 2. release channel: dev
53+
test:
54+
needs: analyze
55+
runs-on: ${{ matrix.os }}
56+
strategy:
57+
fail-fast: false
58+
matrix:
59+
# Add macos-latest and/or windows-latest if relevant for this package.
60+
os: [ubuntu-latest]
61+
sdk: ['3.1', stable, dev]
62+
platform: [vm, chrome]
63+
steps:
64+
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683
65+
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94
66+
with:
67+
sdk: ${{ matrix.sdk }}
68+
- id: install
69+
name: Install dependencies
70+
run: dart pub get
71+
- name: Run tests on ${{ matrix.platform }}
72+
run: dart test --platform ${{ matrix.platform }} --coverage=./coverage
73+
if: always() && steps.install.outcome == 'success'
74+
# We don't collect code coverage from 2.12.0, because it doesn't work
75+
- name: Convert coverage to lcov
76+
run: dart run coverage:format_coverage -i ./coverage -o ./coverage/lcov.info --lcov --report-on lib/
77+
if: always() && steps.install.outcome == 'success' && matrix.sdk != '2.12.0'
78+
- uses: coverallsapp/github-action@cfd0633edbd2411b532b808ba7a8b5e04f76d2c8
79+
if: always() && steps.install.outcome == 'success' && matrix.sdk != '2.12.0'
80+
with:
81+
flag-name: os:${{ matrix.os }}/dart:${{ matrix.sdk }}/platform:${{ matrix.platform }}
82+
parallel: true
83+
84+
report-coverage:
85+
needs: test
86+
if: ${{ always() }}
87+
runs-on: ubuntu-latest
88+
steps:
89+
- uses: coverallsapp/github-action@cfd0633edbd2411b532b808ba7a8b5e04f76d2c8
90+
with:
91+
parallel-finished: true

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ don't naturally belong to other topic monorepos (like
5050
| [unified_analytics](pkgs/unified_analytics/) | A package for logging analytics for all Dart and Flutter related tooling to Google Analytics. | [![package issues](https://img.shields.io/badge/package:unified_analytics-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Aunified_analytics) | [![pub package](https://img.shields.io/pub/v/unified_analytics.svg)](https://pub.dev/packages/unified_analytics) |
5151
| [watcher](pkgs/watcher/) | Monitor directories and send notifications when the contents change. | [![package issues](https://img.shields.io/badge/package:watcher-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Awatcher) | [![pub package](https://img.shields.io/pub/v/watcher.svg)](https://pub.dev/packages/watcher) |
5252
| [yaml](pkgs/yaml/) | A parser for YAML, a human-friendly data serialization standard | [![package issues](https://img.shields.io/badge/package:yaml-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Ayaml) | [![pub package](https://img.shields.io/pub/v/yaml.svg)](https://pub.dev/packages/yaml) |
53+
| [yaml_edit](pkgs/yaml_edit/) | A library for YAML manipulation with comment and whitespace preservation. | [![package issues](https://img.shields.io/badge/package:yaml_edit-4774bc)](https://github.com/dart-lang/tools/issues?q=is%3Aissue+is%3Aopen+label%3Apackage%3Ayaml_edit) | [![pub package](https://img.shields.io/pub/v/yaml_edit.svg)](https://pub.dev/packages/yaml_edit) |
5354

5455
## Publishing automation
5556

pkgs/yaml_edit/.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/.dart_tool/
2+
/.packages
3+
/pubspec.lock

pkgs/yaml_edit/CHANGELOG.md

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
## 2.2.2
2+
3+
- Suppress warnings previously printed to `stdout` when parsing YAML internally.
4+
- Fix error thrown when inserting duplicate keys to different maps in the same
5+
list.
6+
([#69](https://github.com/dart-lang/yaml_edit/issues/69))
7+
8+
- Fix error thrown when inserting in nested list using `spliceList` method
9+
([#83](https://github.com/dart-lang/yaml_edit/issues/83))
10+
11+
- Fix error thrown when string has spaces when applying `ScalarStyle.FOLDED`.
12+
([#41](https://github.com/dart-lang/yaml_edit/issues/41)). Resolves
13+
([[#86](https://github.com/dart-lang/yaml_edit/issues/86)]).
14+
15+
- Require Dart 3.1
16+
17+
- Move to `dart-lang/tools` monorepo.
18+
19+
## 2.2.1
20+
21+
- Require Dart 3.0
22+
- Fix removal of last key in blockmap when key has no value
23+
([#55](https://github.com/dart-lang/yaml_edit/issues/55)).
24+
25+
## 2.2.0
26+
27+
- Fix inconsistent line endings when inserting maps into a document using `\r\n`.
28+
([#65](https://github.com/dart-lang/yaml_edit/issues/65))
29+
30+
- `AliasError` is changed to `AliasException` and exposed in the public API.
31+
32+
All node-mutating methods on `YamlEditor`, i.e. `update()`, `appendToList()`,
33+
`prependToList()`, `insertIntoList()`, `spliceList()`, `remove()` will now
34+
throw an exception instead of an error when encountering an alias on the path
35+
to modify.
36+
37+
This allows catching and handling when this is happening.
38+
39+
## 2.1.1
40+
41+
- Require Dart 2.19
42+
43+
## 2.1.0
44+
45+
- **Breaking** `wrapAsYamlNode(value, collectionStyle, scalarStyle)` will apply
46+
`collectionStyle` and `scalarStyle` recursively when wrapping a children of
47+
`Map` and `List`.
48+
While this may change the style of the YAML documents written by applications
49+
that rely on the old behavior, such YAML documents should still be valid.
50+
Hence, we hope it is reasonable to make this change in a minor release.
51+
- Fix for cases that can't be encoded correctly with
52+
`scalarStyle: ScalarStyle.SINGLE_QUOTED`.
53+
- Fix YamlEditor `appendToList` and `insertIntoList` functions inserts new item into next yaml item
54+
rather than at end of list.
55+
([#23](https://github.com/dart-lang/yaml_edit/issues/23))
56+
57+
## 2.0.3
58+
59+
- Updated the value of the pubspec `repository` field.
60+
61+
## 2.0.2
62+
63+
- Fix trailing whitespace after adding new key with block-value to map
64+
([#15](https://github.com/dart-lang/yaml_edit/issues/15)).
65+
- Updated `repository` and other meta-data in `pubspec.yaml`.
66+
67+
## 2.0.1
68+
69+
- License changed to BSD, as this package is now maintained by the Dart team.
70+
- Fixed minor lints.
71+
72+
## 2.0.0
73+
74+
- Migrated to null-safety.
75+
- API will no-longer return `null` in-place of a `YamlNode`, instead a
76+
`YamlNode` with `YamlNode.value == null` should be used. These are easily
77+
created with `wrapAsYamlNode(null)`.
78+
79+
## 1.0.3
80+
81+
- Fixed bug in adding an empty map as a map value.
82+
83+
## 1.0.2
84+
85+
- Throws an error if the final YAML after edit is not parsable.
86+
- Fixed bug in adding to empty map values, when it is followed by other content.
87+
88+
## 1.0.1
89+
90+
- Updated behavior surrounding list and map removal.
91+
- Fixed bug in dealing with empty values.
92+
93+
## 1.0.0
94+
95+
- Initial release.

pkgs/yaml_edit/LICENSE

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
Copyright 2020, the Dart project authors.
2+
3+
Redistribution and use in source and binary forms, with or without
4+
modification, are permitted provided that the following conditions are
5+
met:
6+
* Redistributions of source code must retain the above copyright
7+
notice, this list of conditions and the following disclaimer.
8+
* Redistributions in binary form must reproduce the above
9+
copyright notice, this list of conditions and the following
10+
disclaimer in the documentation and/or other materials provided
11+
with the distribution.
12+
* Neither the name of Google LLC nor the names of its
13+
contributors may be used to endorse or promote products derived
14+
from this software without specific prior written permission.
15+
16+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17+
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18+
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19+
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20+
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21+
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22+
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23+
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24+
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25+
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

pkgs/yaml_edit/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
[![Dart CI](https://github.com/dart-lang/yaml_edit/actions/workflows/test-package.yml/badge.svg)](https://github.com/dart-lang/yaml_edit/actions/workflows/test-package.yml)
2+
[![pub package](https://img.shields.io/pub/v/yaml_edit.svg)](https://pub.dev/packages/yaml_edit)
3+
[![package publisher](https://img.shields.io/pub/publisher/yaml_edit.svg)](https://pub.dev/packages/yaml_edit/publisher)
4+
[![Coverage Status](https://coveralls.io/repos/github/dart-lang/yaml_edit/badge.svg)](https://coveralls.io/github/dart-lang/yaml_edit)
5+
6+
A library for [YAML](https://yaml.org) manipulation while preserving comments.
7+
8+
## Usage
9+
10+
A simple usage example:
11+
12+
```dart
13+
import 'package:yaml_edit/yaml_edit.dart';
14+
15+
void main() {
16+
final yamlEditor = YamlEditor('{YAML: YAML}');
17+
yamlEditor.update(['YAML'], "YAML Ain't Markup Language");
18+
print(yamlEditor);
19+
// Expected output:
20+
// {YAML: YAML Ain't Markup Language}
21+
}
22+
```
23+
24+
### Example: Converting JSON to YAML (block formatted)
25+
26+
```dart
27+
void main() {
28+
final jsonString = r'''
29+
{
30+
"key": "value",
31+
"list": [
32+
"first",
33+
"second",
34+
"last entry in the list"
35+
],
36+
"map": {
37+
"multiline": "this is a fairly long string with\nline breaks..."
38+
}
39+
}
40+
''';
41+
final jsonValue = json.decode(jsonString);
42+
43+
// Convert jsonValue to YAML
44+
final yamlEditor = YamlEditor('');
45+
yamlEditor.update([], jsonValue);
46+
print(yamlEditor.toString());
47+
}
48+
```
49+
50+
## Testing
51+
52+
Testing is done in two strategies: Unit testing (`/test/editor_test.dart`) and
53+
Golden testing (`/test/golden_test.dart`). More information on Golden testing
54+
and the input/output format can be found at `/test/testdata/README.md`.
55+
56+
These tests are automatically run with `pub run test`.
57+
58+
## Limitations
59+
60+
1. Users are not allowed to define tags in the modifications.
61+
2. Map keys will always be added in the flow style.

pkgs/yaml_edit/analysis_options.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
include: package:dart_flutter_team_lints/analysis_options.yaml
2+
3+
analyzer:
4+
errors:
5+
inference_failure_on_collection_literal: ignore
6+
inference_failure_on_function_invocation: ignore
7+
inference_failure_on_function_return_type: ignore
8+
inference_failure_on_instance_creation: ignore

pkgs/yaml_edit/example/example.dart

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import 'package:yaml_edit/yaml_edit.dart';
2+
3+
void main() {
4+
final doc = YamlEditor('''
5+
- 0 # comment 0
6+
- 1 # comment 1
7+
- 2 # comment 2
8+
''');
9+
doc.remove([1]);
10+
11+
print(doc);
12+
}

0 commit comments

Comments
 (0)