-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1662 from dart-lang/merge-yaml_edit-package
Merge `package:yaml_edit`
- Loading branch information
Showing
85 changed files
with
8,974 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
name: "package:yaml_edit" | ||
about: "Create a bug or file a feature request against package:yaml_edit." | ||
labels: "package:yaml_edit" | ||
--- |
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,91 @@ | ||
name: package:yaml_edit | ||
|
||
on: | ||
# Run on PRs and pushes to the default branch. | ||
push: | ||
branches: [ main ] | ||
paths: | ||
- '.github/workflows/yaml_edit.yaml' | ||
- 'pkgs/yaml_edit/**' | ||
pull_request: | ||
branches: [ main ] | ||
paths: | ||
- '.github/workflows/yaml_edit.yaml' | ||
- 'pkgs/yaml_edit/**' | ||
schedule: | ||
- cron: "0 0 * * 0" | ||
|
||
env: | ||
PUB_ENVIRONMENT: bot.github | ||
|
||
|
||
defaults: | ||
run: | ||
working-directory: pkgs/yaml_edit/ | ||
|
||
jobs: | ||
# Check code formatting and static analysis on a single OS (linux) | ||
# against Dart dev. | ||
analyze: | ||
runs-on: ubuntu-latest | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
sdk: [dev] | ||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | ||
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 | ||
with: | ||
sdk: ${{ matrix.sdk }} | ||
- id: install | ||
name: Install dependencies | ||
run: dart pub get | ||
- name: Check formatting | ||
run: dart format --output=none --set-exit-if-changed . | ||
if: always() && steps.install.outcome == 'success' | ||
- name: Analyze code | ||
run: dart analyze --fatal-infos | ||
if: always() && steps.install.outcome == 'success' | ||
|
||
# Run tests on a matrix consisting of two dimensions: | ||
# 1. OS: ubuntu-latest, (macos-latest, windows-latest) | ||
# 2. release channel: dev | ||
test: | ||
needs: analyze | ||
runs-on: ${{ matrix.os }} | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
# Add macos-latest and/or windows-latest if relevant for this package. | ||
os: [ubuntu-latest] | ||
sdk: ['3.1', stable, dev] | ||
platform: [vm, chrome] | ||
steps: | ||
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 | ||
- uses: dart-lang/setup-dart@e630b99d28a3b71860378cafdc2a067c71107f94 | ||
with: | ||
sdk: ${{ matrix.sdk }} | ||
- id: install | ||
name: Install dependencies | ||
run: dart pub get | ||
- name: Run tests on ${{ matrix.platform }} | ||
run: dart test --platform ${{ matrix.platform }} --coverage=./coverage | ||
if: always() && steps.install.outcome == 'success' | ||
# We don't collect code coverage from 2.12.0, because it doesn't work | ||
- name: Convert coverage to lcov | ||
run: dart run coverage:format_coverage -i ./coverage -o ./coverage/lcov.info --lcov --report-on lib/ | ||
if: always() && steps.install.outcome == 'success' && matrix.sdk != '2.12.0' | ||
- uses: coverallsapp/github-action@cfd0633edbd2411b532b808ba7a8b5e04f76d2c8 | ||
if: always() && steps.install.outcome == 'success' && matrix.sdk != '2.12.0' | ||
with: | ||
flag-name: os:${{ matrix.os }}/dart:${{ matrix.sdk }}/platform:${{ matrix.platform }} | ||
parallel: true | ||
|
||
report-coverage: | ||
needs: test | ||
if: ${{ always() }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: coverallsapp/github-action@cfd0633edbd2411b532b808ba7a8b5e04f76d2c8 | ||
with: | ||
parallel-finished: true |
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,3 @@ | ||
/.dart_tool/ | ||
/.packages | ||
/pubspec.lock |
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,95 @@ | ||
## 2.2.2 | ||
|
||
- Suppress warnings previously printed to `stdout` when parsing YAML internally. | ||
- Fix error thrown when inserting duplicate keys to different maps in the same | ||
list. | ||
([#69](https://github.com/dart-lang/yaml_edit/issues/69)) | ||
|
||
- Fix error thrown when inserting in nested list using `spliceList` method | ||
([#83](https://github.com/dart-lang/yaml_edit/issues/83)) | ||
|
||
- Fix error thrown when string has spaces when applying `ScalarStyle.FOLDED`. | ||
([#41](https://github.com/dart-lang/yaml_edit/issues/41)). Resolves | ||
([[#86](https://github.com/dart-lang/yaml_edit/issues/86)]). | ||
|
||
- Require Dart 3.1 | ||
|
||
- Move to `dart-lang/tools` monorepo. | ||
|
||
## 2.2.1 | ||
|
||
- Require Dart 3.0 | ||
- Fix removal of last key in blockmap when key has no value | ||
([#55](https://github.com/dart-lang/yaml_edit/issues/55)). | ||
|
||
## 2.2.0 | ||
|
||
- Fix inconsistent line endings when inserting maps into a document using `\r\n`. | ||
([#65](https://github.com/dart-lang/yaml_edit/issues/65)) | ||
|
||
- `AliasError` is changed to `AliasException` and exposed in the public API. | ||
|
||
All node-mutating methods on `YamlEditor`, i.e. `update()`, `appendToList()`, | ||
`prependToList()`, `insertIntoList()`, `spliceList()`, `remove()` will now | ||
throw an exception instead of an error when encountering an alias on the path | ||
to modify. | ||
|
||
This allows catching and handling when this is happening. | ||
|
||
## 2.1.1 | ||
|
||
- Require Dart 2.19 | ||
|
||
## 2.1.0 | ||
|
||
- **Breaking** `wrapAsYamlNode(value, collectionStyle, scalarStyle)` will apply | ||
`collectionStyle` and `scalarStyle` recursively when wrapping a children of | ||
`Map` and `List`. | ||
While this may change the style of the YAML documents written by applications | ||
that rely on the old behavior, such YAML documents should still be valid. | ||
Hence, we hope it is reasonable to make this change in a minor release. | ||
- Fix for cases that can't be encoded correctly with | ||
`scalarStyle: ScalarStyle.SINGLE_QUOTED`. | ||
- Fix YamlEditor `appendToList` and `insertIntoList` functions inserts new item into next yaml item | ||
rather than at end of list. | ||
([#23](https://github.com/dart-lang/yaml_edit/issues/23)) | ||
|
||
## 2.0.3 | ||
|
||
- Updated the value of the pubspec `repository` field. | ||
|
||
## 2.0.2 | ||
|
||
- Fix trailing whitespace after adding new key with block-value to map | ||
([#15](https://github.com/dart-lang/yaml_edit/issues/15)). | ||
- Updated `repository` and other meta-data in `pubspec.yaml`. | ||
|
||
## 2.0.1 | ||
|
||
- License changed to BSD, as this package is now maintained by the Dart team. | ||
- Fixed minor lints. | ||
|
||
## 2.0.0 | ||
|
||
- Migrated to null-safety. | ||
- API will no-longer return `null` in-place of a `YamlNode`, instead a | ||
`YamlNode` with `YamlNode.value == null` should be used. These are easily | ||
created with `wrapAsYamlNode(null)`. | ||
|
||
## 1.0.3 | ||
|
||
- Fixed bug in adding an empty map as a map value. | ||
|
||
## 1.0.2 | ||
|
||
- Throws an error if the final YAML after edit is not parsable. | ||
- Fixed bug in adding to empty map values, when it is followed by other content. | ||
|
||
## 1.0.1 | ||
|
||
- Updated behavior surrounding list and map removal. | ||
- Fixed bug in dealing with empty values. | ||
|
||
## 1.0.0 | ||
|
||
- Initial release. |
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,26 @@ | ||
Copyright 2020, the Dart project authors. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are | ||
met: | ||
* Redistributions of source code must retain the above copyright | ||
notice, this list of conditions and the following disclaimer. | ||
* Redistributions in binary form must reproduce the above | ||
copyright notice, this list of conditions and the following | ||
disclaimer in the documentation and/or other materials provided | ||
with the distribution. | ||
* Neither the name of Google LLC nor the names of its | ||
contributors may be used to endorse or promote products derived | ||
from this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
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,61 @@ | ||
[![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) | ||
[![pub package](https://img.shields.io/pub/v/yaml_edit.svg)](https://pub.dev/packages/yaml_edit) | ||
[![package publisher](https://img.shields.io/pub/publisher/yaml_edit.svg)](https://pub.dev/packages/yaml_edit/publisher) | ||
[![Coverage Status](https://coveralls.io/repos/github/dart-lang/yaml_edit/badge.svg)](https://coveralls.io/github/dart-lang/yaml_edit) | ||
|
||
A library for [YAML](https://yaml.org) manipulation while preserving comments. | ||
|
||
## Usage | ||
|
||
A simple usage example: | ||
|
||
```dart | ||
import 'package:yaml_edit/yaml_edit.dart'; | ||
void main() { | ||
final yamlEditor = YamlEditor('{YAML: YAML}'); | ||
yamlEditor.update(['YAML'], "YAML Ain't Markup Language"); | ||
print(yamlEditor); | ||
// Expected output: | ||
// {YAML: YAML Ain't Markup Language} | ||
} | ||
``` | ||
|
||
### Example: Converting JSON to YAML (block formatted) | ||
|
||
```dart | ||
void main() { | ||
final jsonString = r''' | ||
{ | ||
"key": "value", | ||
"list": [ | ||
"first", | ||
"second", | ||
"last entry in the list" | ||
], | ||
"map": { | ||
"multiline": "this is a fairly long string with\nline breaks..." | ||
} | ||
} | ||
'''; | ||
final jsonValue = json.decode(jsonString); | ||
// Convert jsonValue to YAML | ||
final yamlEditor = YamlEditor(''); | ||
yamlEditor.update([], jsonValue); | ||
print(yamlEditor.toString()); | ||
} | ||
``` | ||
|
||
## Testing | ||
|
||
Testing is done in two strategies: Unit testing (`/test/editor_test.dart`) and | ||
Golden testing (`/test/golden_test.dart`). More information on Golden testing | ||
and the input/output format can be found at `/test/testdata/README.md`. | ||
|
||
These tests are automatically run with `pub run test`. | ||
|
||
## Limitations | ||
|
||
1. Users are not allowed to define tags in the modifications. | ||
2. Map keys will always be added in the flow style. |
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,8 @@ | ||
include: package:dart_flutter_team_lints/analysis_options.yaml | ||
|
||
analyzer: | ||
errors: | ||
inference_failure_on_collection_literal: ignore | ||
inference_failure_on_function_invocation: ignore | ||
inference_failure_on_function_return_type: ignore | ||
inference_failure_on_instance_creation: ignore |
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 @@ | ||
import 'package:yaml_edit/yaml_edit.dart'; | ||
|
||
void main() { | ||
final doc = YamlEditor(''' | ||
- 0 # comment 0 | ||
- 1 # comment 1 | ||
- 2 # comment 2 | ||
'''); | ||
doc.remove([1]); | ||
|
||
print(doc); | ||
} |
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,28 @@ | ||
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file | ||
// for details. All rights reserved. Use of this source code is governed by a | ||
// BSD-style license that can be found in the LICENSE file. | ||
|
||
import 'dart:convert' show json; | ||
|
||
import 'package:yaml_edit/yaml_edit.dart'; | ||
|
||
void main() { | ||
final jsonString = r''' | ||
{ | ||
"key": "value", | ||
"list": [ | ||
"first", | ||
"second", | ||
"last entry in the list" | ||
], | ||
"map": { | ||
"multiline": "this is a fairly long string with\nline breaks..." | ||
} | ||
} | ||
'''; | ||
final jsonValue = json.decode(jsonString); | ||
|
||
final yamlEditor = YamlEditor(''); | ||
yamlEditor.update([], jsonValue); | ||
print(yamlEditor.toString()); | ||
} |
Oops, something went wrong.