Skip to content

Commit

Permalink
Merge package:yaml_edit into the tools monorepo
Browse files Browse the repository at this point in the history
  • Loading branch information
mosuem committed Dec 11, 2024
2 parents 5590447 + 86982d0 commit 98701e1
Show file tree
Hide file tree
Showing 86 changed files with 9,035 additions and 0 deletions.
15 changes: 15 additions & 0 deletions pkgs/yaml_edit/.github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Dependabot configuration file.
# See https://docs.github.com/en/code-security/dependabot/dependabot-version-updates
version: 2

updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
labels:
- autosubmit
groups:
github-actions:
patterns:
- "*"
37 changes: 37 additions & 0 deletions pkgs/yaml_edit/.github/workflows/no-response.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# A workflow to close issues where the author hasn't responded to a request for
# more information; see https://github.com/actions/stale.

name: No Response

# Run as a daily cron.
on:
schedule:
# Every day at 8am
- cron: '0 8 * * *'

# All permissions not specified are set to 'none'.
permissions:
issues: write
pull-requests: write

jobs:
no-response:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'dart-lang' }}
steps:
- uses: actions/stale@28ca1036281a5e5922ead5184a1bbf96e5fc984e
with:
# Don't automatically mark inactive issues+PRs as stale.
days-before-stale: -1
# Close needs-info issues and PRs after 14 days of inactivity.
days-before-close: 14
stale-issue-label: "needs-info"
close-issue-message: >
Without additional information we're not able to resolve this issue.
Feel free to add more info or respond to any questions above and we
can reopen the case. Thanks for your contribution!
stale-pr-label: "needs-info"
close-pr-message: >
Without additional information we're not able to resolve this PR.
Feel free to add more info or respond to any questions above.
Thanks for your contribution!
17 changes: 17 additions & 0 deletions pkgs/yaml_edit/.github/workflows/post_summaries.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
name: Comment on the pull request

on:
# Trigger this workflow after the Publish workflow completes. This workflow
# will have permissions to do things like create comments on the PR, even if
# the original workflow couldn't.
workflow_run:
workflows:
- Publish
types:
- completed

jobs:
upload:
uses: dart-lang/ecosystem/.github/workflows/post_summaries.yaml@main
permissions:
pull-requests: write
16 changes: 16 additions & 0 deletions pkgs/yaml_edit/.github/workflows/publish.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# A CI configuration to auto-publish pub packages.

name: Publish

on:
pull_request:
branches: [ main ]
push:
tags: [ 'v[0-9]+.[0-9]+.[0-9]+' ]

jobs:
publish:
if: ${{ github.repository_owner == 'dart-lang' }}
uses: dart-lang/ecosystem/.github/workflows/publish.yaml@main
with:
write-comments: false
80 changes: 80 additions & 0 deletions pkgs/yaml_edit/.github/workflows/test-package.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
name: Dart CI

on:
# Run on PRs and pushes to the default branch.
push:
branches: [ main ]
pull_request:
branches: [ main ]
schedule:
- cron: "0 0 * * 0"

env:
PUB_ENVIRONMENT: bot.github

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
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
93 changes: 93 additions & 0 deletions pkgs/yaml_edit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
## 2.2.2-wip

- 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

## 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);
}
Loading

0 comments on commit 98701e1

Please sign in to comment.