Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions pkgs/yaml/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## 3.2.0-wip

* Export `ErrorListener` and `ErrorCollector` from `package:yaml/yaml.dart`.
* Mark internal constructors in `YamlDocument`, `YamlMap`, `YamlList`, and
`YamlScalar` with `@internal`.

## 3.1.4

* Improve recovery for list entries without `-` prefix. When recovering, provide
Expand Down
4 changes: 4 additions & 0 deletions pkgs/yaml/lib/src/yaml_document.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

import 'dart:collection';

import 'package:meta/meta.dart';
import 'package:source_span/source_span.dart';

import 'yaml_node.dart';
Expand All @@ -33,6 +34,9 @@ class YamlDocument {
final bool endImplicit;

/// Users of the library should not use this constructor.
///
/// @nodoc
@internal
Comment thread
kevmoo marked this conversation as resolved.
Resolved
YamlDocument.internal(this.contents, this.span, this.versionDirective,
List<TagDirective> tagDirectives,
{this.startImplicit = false, this.endImplicit = false})
Expand Down
5 changes: 5 additions & 0 deletions pkgs/yaml/lib/src/yaml_node.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import 'dart:collection' as collection;

import 'package:collection/collection.dart';
import 'package:meta/meta.dart';
import 'package:source_span/source_span.dart';

import 'event.dart';
Expand Down Expand Up @@ -86,6 +87,7 @@ class YamlMap extends YamlNode with collection.MapMixin, UnmodifiableMapMixin {
YamlMapWrapper(dartMap, sourceUrl, style: style);

/// Users of the library should not use this constructor.
@internal

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This breaks package:analyzer because this rule is enforced in google3.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#2576 will remove them for now.

YamlMap.internal(Map<dynamic, YamlNode> nodes, super.span, this.style)
: nodes = UnmodifiableMapView<dynamic, YamlNode>(nodes),
super._();
Expand Down Expand Up @@ -136,6 +138,7 @@ class YamlList extends YamlNode with collection.ListMixin {
YamlListWrapper(dartList, sourceUrl, style: style);

/// Users of the library should not use this constructor.
@internal
YamlList.internal(List<YamlNode> nodes, super.span, this.style)
: nodes = UnmodifiableListView<YamlNode>(nodes),
super._();
Expand Down Expand Up @@ -170,11 +173,13 @@ class YamlScalar extends YamlNode {
}

/// Users of the library should not use this constructor.
@internal
YamlScalar.internal(this.value, ScalarEvent scalar)
: style = scalar.style,
super._(scalar.span);

/// Users of the library should not use this constructor.
@internal
YamlScalar.internalWithSpan(this.value, SourceSpan span)
: style = ScalarStyle.ANY,
super._(span);
Expand Down
1 change: 1 addition & 0 deletions pkgs/yaml/lib/yaml.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'src/yaml_document.dart';
import 'src/yaml_exception.dart';
import 'src/yaml_node.dart';

export 'src/error_listener.dart';
export 'src/style.dart';
export 'src/utils.dart' show YamlWarningCallback, yamlWarningCallback;
export 'src/yaml_document.dart';
Expand Down
3 changes: 2 additions & 1 deletion pkgs/yaml/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: yaml
version: 3.1.4
version: 3.2.0-wip
description: A parser for YAML, a human-friendly data serialization standard
repository: https://github.com/dart-lang/tools/tree/main/pkgs/yaml
issue_tracker: https://github.com/dart-lang/tools/labels/package%3Ayaml
Expand All @@ -13,6 +13,7 @@ environment:

dependencies:
collection: ^1.15.0
meta: ^1.9.0
source_span: ^1.8.0
string_scanner: ^1.2.0

Expand Down
72 changes: 72 additions & 0 deletions pkgs/yaml/test/error_listener_test.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// Copyright (c) 2024, 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 'package:test/test.dart';
import 'package:yaml/yaml.dart';

class _CustomErrorListener implements ErrorListener {
final List<String> messages = [];

@override
void onError(YamlException error) {
messages.add(error.message);
}
}

void main() {
const invalidYamlWithMissingPrefix = '''
linter:
rules:
- annotate_overrides
alway
''';

test('ErrorCollector collects errors during recovery parsing', () {
final collector = ErrorCollector();
final result = loadYaml(
invalidYamlWithMissingPrefix,
recover: true,
errorListener: collector,
);

expect(
result,
equals({
'linter': {
'rules': ['annotate_overrides', 'alway'],
},
}),
);
expect(collector.errors, hasLength(1));
expect(
collector.errors.first.message,
contains("Expected ':'"),
);
});

test(
'custom ErrorListener implementation receives errors during recovery '
'parsing', () {
final listener = _CustomErrorListener();
final result = loadYaml(
invalidYamlWithMissingPrefix,
recover: true,
errorListener: listener,
);

expect(
result,
equals({
'linter': {
'rules': ['annotate_overrides', 'alway'],
},
}),
);
expect(listener.messages, hasLength(1));
expect(
listener.messages.first,
contains("Expected ':'"),
);
});
}
1 change: 0 additions & 1 deletion pkgs/yaml/test/yaml_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
// ignore_for_file: avoid_dynamic_calls

import 'package:test/test.dart';
import 'package:yaml/src/error_listener.dart';
import 'package:yaml/yaml.dart';
Comment thread
kevmoo marked this conversation as resolved.
Resolved

import 'utils.dart';
Expand Down
Loading