Skip to content

Commit

Permalink
Merge pull request #1662 from dart-lang/merge-yaml_edit-package
Browse files Browse the repository at this point in the history
Merge `package:yaml_edit`
  • Loading branch information
mosuem authored Dec 20, 2024
2 parents 27f829e + cc22c3d commit a04e631
Show file tree
Hide file tree
Showing 85 changed files with 8,974 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .github/ISSUE_TEMPLATE/yaml_edit.md
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"
---
6 changes: 5 additions & 1 deletion .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,4 +146,8 @@

'package:yaml':
- changed-files:
- any-glob-to-any-file: 'pkgs/yaml/**'
- any-glob-to-any-file: 'pkgs/yaml/**'

'package:yaml_edit':
- changed-files:
- any-glob-to-any-file: 'pkgs/yaml_edit/**'
91 changes: 91 additions & 0 deletions .github/workflows/yaml_edit.yaml
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ don't naturally belong to other topic monorepos (like
| [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) |
| [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) |
| [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) |
| [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) |

## Publishing automation

Expand Down
3 changes: 3 additions & 0 deletions pkgs/yaml_edit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.dart_tool/
/.packages
/pubspec.lock
95 changes: 95 additions & 0 deletions pkgs/yaml_edit/CHANGELOG.md
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.
26 changes: 26 additions & 0 deletions pkgs/yaml_edit/LICENSE
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.
61 changes: 61 additions & 0 deletions pkgs/yaml_edit/README.md
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.
8 changes: 8 additions & 0 deletions pkgs/yaml_edit/analysis_options.yaml
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
12 changes: 12 additions & 0 deletions pkgs/yaml_edit/example/example.dart
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);
}
28 changes: 28 additions & 0 deletions pkgs/yaml_edit/example/json2yaml.dart
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());
}
Loading

0 comments on commit a04e631

Please sign in to comment.