Repository navigation
feat: export ErrorListener and ErrorCollector from yaml.dart #2551
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
2784d34
feat: export ErrorListener and ErrorCollector from yaml.dart
kevmoo 80cf4dd
style: remove blank line between package imports in yaml_test.dart
kevmoo 6e02416
feat(yaml): annotate internal constructors with @internal
kevmoo d818bcb
fix(yaml): add nodoc to internal constructor and deprecate subclassing
kevmoo e6eb496
Merge remote-tracking branch 'origin/main' into yaml-export-error-lis…
kevmoo 40384a8
fix: revert unintentional formatting changes to non-yaml packages fro…
kevmoo 1cfd3c7
fix(yaml): remove Deprecated.subclass to preserve compatibility with …
kevmoo File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 |
|---|---|---|
|
|
@@ -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'; | ||
|
|
@@ -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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This breaks
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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._(); | ||
|
|
@@ -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._(); | ||
|
|
@@ -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); | ||
|
|
||
This file contains hidden or 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 hidden or 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 hidden or 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,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 ':'"), | ||
| ); | ||
| }); | ||
| } |
This file contains hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.