update to the latest sdk; update lints (#68)
diff --git a/.github/workflows/test-package.yml b/.github/workflows/test-package.yml
index dbdd56a..41d7696 100644
--- a/.github/workflows/test-package.yml
+++ b/.github/workflows/test-package.yml
@@ -47,7 +47,7 @@
matrix:
# Add macos-latest and/or windows-latest if relevant for this package.
os: [ubuntu-latest]
- sdk: [2.19.0, stable, dev]
+ sdk: ['3.0', stable, dev]
platform: [vm, chrome]
steps:
- uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7213676..9472abf 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,3 +1,7 @@
+## 2.2.1-wip
+
+- Require Dart 3.0
+
## 2.2.0
- Fix inconsistent line endings when inserting maps into a document using `\r\n`.
diff --git a/analysis_options.yaml b/analysis_options.yaml
index d978f81..937e7fe 100644
--- a/analysis_options.yaml
+++ b/analysis_options.yaml
@@ -1 +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
diff --git a/lib/src/editor.dart b/lib/src/editor.dart
index 9947d8f..be09f98 100644
--- a/lib/src/editor.dart
+++ b/lib/src/editor.dart
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.
import 'package:meta/meta.dart';
+import 'package:source_span/source_span.dart';
import 'package:yaml/yaml.dart';
import 'equality.dart';
diff --git a/lib/src/errors.dart b/lib/src/errors.dart
index 51c6243..0e60dd8 100644
--- a/lib/src/errors.dart
+++ b/lib/src/errors.dart
@@ -44,11 +44,11 @@
/// Exception thrown when the path contains an alias along the way.
///
/// When a path contains an aliased node, the behavior becomes less well-defined
-/// because we cannot be certain if the user wishes for the change to
-/// propagate throughout all the other aliased nodes, or if the user wishes
-/// for only that particular node to be modified. As such, [AliasError] reflects
-/// the detection that our change will impact an alias, and we do not intend
-/// on supporting such changes for the foreseeable future.
+/// because we cannot be certain if the user wishes for the change to propagate
+/// throughout all the other aliased nodes, or if the user wishes for only that
+/// particular node to be modified. As such, [AliasException] reflects the
+/// detection that our change will impact an alias, and we do not intend on
+/// supporting such changes for the foreseeable future.
@sealed
class AliasException extends FormatException {
/// The path that caused the error
@@ -70,7 +70,7 @@
/// Error thrown when an assertion about the YAML fails. Extends
/// [AssertionError] to override the [toString] method for pretty printing.
class _YamlAssertionError extends AssertionError {
- _YamlAssertionError(message) : super(message);
+ _YamlAssertionError(super.message);
@override
String toString() {
diff --git a/lib/src/list_mutations.dart b/lib/src/list_mutations.dart
index 1d02ded..a76f4bc 100644
--- a/lib/src/list_mutations.dart
+++ b/lib/src/list_mutations.dart
@@ -10,8 +10,9 @@
import 'utils.dart';
import 'wrap.dart';
-/// Returns a [SourceEdit] describing the change to be made on [yaml] to achieve
-/// the effect of setting the element at [index] to [newValue] when re-parsed.
+/// Returns a [SourceEdit] describing the change to be made on [yamlEdit] to
+/// achieve the effect of setting the element at [index] to [newValue] when
+/// re-parsed.
SourceEdit updateInList(
YamlEditor yamlEdit, YamlList list, int index, YamlNode newValue) {
RangeError.checkValueInInterval(index, 0, list.length - 1);
@@ -56,8 +57,8 @@
}
}
-/// Returns a [SourceEdit] describing the change to be made on [yaml] to achieve
-/// the effect of appending [item] to the list.
+/// Returns a [SourceEdit] describing the change to be made on [yamlEdit] to
+/// achieve the effect of appending [item] to the list.
SourceEdit appendIntoList(YamlEditor yamlEdit, YamlList list, YamlNode item) {
if (list.style == CollectionStyle.FLOW) {
return _appendToFlowList(yamlEdit, list, item);
@@ -66,8 +67,8 @@
}
}
-/// Returns a [SourceEdit] describing the change to be made on [yaml] to achieve
-/// the effect of inserting [item] to the list at [index].
+/// Returns a [SourceEdit] describing the change to be made on [yamlEdit] to
+/// achieve the effect of inserting [item] to the list at [index].
SourceEdit insertInList(
YamlEditor yamlEdit, YamlList list, int index, YamlNode item) {
RangeError.checkValueInInterval(index, 0, list.length);
@@ -85,8 +86,8 @@
}
}
-/// Returns a [SourceEdit] describing the change to be made on [yaml] to achieve
-/// the effect of removing the element at [index] when re-parsed.
+/// Returns a [SourceEdit] describing the change to be made on [yamlEdit] to
+/// achieve the effect of removing the element at [index] when re-parsed.
SourceEdit removeInList(YamlEditor yamlEdit, YamlList list, int index) {
final nodeToRemove = list.nodes[index];
@@ -97,17 +98,18 @@
}
}
-/// Returns a [SourceEdit] describing the change to be made on [yaml] to achieve
-/// the effect of addition [item] into [nodes], noting that this is a flow list.
+/// Returns a [SourceEdit] describing the change to be made on [yamlEdit] to
+/// achieve the effect of addition [item] into [list], noting that this is a
+/// flow list.
SourceEdit _appendToFlowList(
YamlEditor yamlEdit, YamlList list, YamlNode item) {
final valueString = _formatNewFlow(list, item, true);
return SourceEdit(list.span.end.offset - 1, 0, valueString);
}
-/// Returns a [SourceEdit] describing the change to be made on [yaml] to achieve
-/// the effect of addition [item] into [nodes], noting that this is a block
-/// list.
+/// Returns a [SourceEdit] describing the change to be made on [yamlEdit] to
+/// achieve the effect of addition [item] into [list], noting that this is a
+/// block list.
SourceEdit _appendToBlockList(
YamlEditor yamlEdit, YamlList list, YamlNode item) {
var formattedValue = _formatNewBlock(yamlEdit, list, item);
@@ -159,11 +161,11 @@
return valueString;
}
-/// Returns a [SourceEdit] describing the change to be made on [yaml] to achieve
-/// the effect of inserting [item] into [nodes] at [index], noting that this is
-/// a block list.
+/// Returns a [SourceEdit] describing the change to be made on [yamlEdit] to
+/// achieve the effect of inserting [item] into [list] at [index], noting that
+/// this is a block list.
///
-/// [index] should be non-negative and less than or equal to [length].
+/// [index] should be non-negative and less than or equal to `list.length`.
SourceEdit _insertInBlockList(
YamlEditor yamlEdit, YamlList list, int index, YamlNode item) {
RangeError.checkValueInInterval(index, 0, list.length);
@@ -180,11 +182,11 @@
return SourceEdit(start, 0, formattedValue);
}
-/// Returns a [SourceEdit] describing the change to be made on [yaml] to achieve
-/// the effect of inserting [item] into [nodes] at [index], noting that this is
-/// a flow list.
+/// Returns a [SourceEdit] describing the change to be made on [yamlEdit] to
+/// achieve the effect of inserting [item] into [list] at [index], noting that
+/// this is a flow list.
///
-/// [index] should be non-negative and less than or equal to [length].
+/// [index] should be non-negative and less than or equal to `list.length`.
SourceEdit _insertInFlowList(
YamlEditor yamlEdit, YamlList list, int index, YamlNode item) {
RangeError.checkValueInInterval(index, 0, list.length);
@@ -202,11 +204,11 @@
return SourceEdit(start, 0, formattedValue);
}
-/// Returns a [SourceEdit] describing the change to be made on [yaml] to achieve
-/// the effect of removing [nodeToRemove] from [nodes], noting that this is a
-/// block list.
+/// Returns a [SourceEdit] describing the change to be made on [yamlEdit] to
+/// achieve the effect of removing [nodeToRemove] from [list], noting that this
+/// is a block list.
///
-/// [index] should be non-negative and less than or equal to [length].
+/// [index] should be non-negative and less than or equal to `list.length`.
SourceEdit _removeFromBlockList(
YamlEditor yamlEdit, YamlList list, YamlNode nodeToRemove, int index) {
RangeError.checkValueInInterval(index, 0, list.length - 1);
@@ -277,11 +279,11 @@
return SourceEdit(start, end - start, '');
}
-/// Returns a [SourceEdit] describing the change to be made on [yaml] to achieve
-/// the effect of removing [nodeToRemove] from [nodes], noting that this is a
-/// flow list.
+/// Returns a [SourceEdit] describing the change to be made on [yamlEdit] to
+/// achieve the effect of removing [nodeToRemove] from [list], noting that this
+/// is a flow list.
///
-/// [index] should be non-negative and less than or equal to [length].
+/// [index] should be non-negative and less than or equal to `list.length`.
SourceEdit _removeFromFlowList(
YamlEditor yamlEdit, YamlList list, YamlNode nodeToRemove, int index) {
RangeError.checkValueInInterval(index, 0, list.length - 1);
diff --git a/lib/src/map_mutations.dart b/lib/src/map_mutations.dart
index 5ae82f3..321987f 100644
--- a/lib/src/map_mutations.dart
+++ b/lib/src/map_mutations.dart
@@ -11,7 +11,7 @@
import 'utils.dart';
import 'wrap.dart';
-/// Performs the string operation on [yaml] to achieve the effect of setting
+/// Performs the string operation on [yamlEdit] to achieve the effect of setting
/// the element at [key] to [newValue] when re-parsed.
SourceEdit updateInMap(
YamlEditor yamlEdit, YamlMap map, Object? key, YamlNode newValue) {
@@ -32,8 +32,8 @@
}
}
-/// Performs the string operation on [yaml] to achieve the effect of removing
-/// the element at [key] when re-parsed.
+/// Performs the string operation on [yamlEdit] to achieve the effect of
+/// removing the element at [key] when re-parsed.
SourceEdit removeInMap(YamlEditor yamlEdit, YamlMap map, Object? key) {
assert(containsKey(map, key));
final keyNode = getKeyNode(map, key);
@@ -46,7 +46,7 @@
}
}
-/// Performs the string operation on [yaml] to achieve the effect of adding
+/// Performs the string operation on [yamlEdit] to achieve the effect of adding
/// the [key]:[newValue] pair when reparsed, bearing in mind that this is a
/// block map.
SourceEdit _addToBlockMap(
@@ -95,7 +95,7 @@
return SourceEdit(offset, 0, formattedValue);
}
-/// Performs the string operation on [yaml] to achieve the effect of adding
+/// Performs the string operation on [yamlEdit] to achieve the effect of adding
/// the [key]:[newValue] pair when reparsed, bearing in mind that this is a flow
/// map.
SourceEdit _addToFlowMap(
@@ -120,9 +120,9 @@
return SourceEdit(insertionOffset, 0, '$keyString: $valueString, ');
}
-/// Performs the string operation on [yaml] to achieve the effect of replacing
-/// the value at [key] with [newValue] when reparsed, bearing in mind that this
-/// is a block map.
+/// Performs the string operation on [yamlEdit] to achieve the effect of
+/// replacing the value at [key] with [newValue] when reparsed, bearing in mind
+/// that this is a block map.
SourceEdit _replaceInBlockMap(
YamlEditor yamlEdit, YamlMap map, Object? key, YamlNode newValue) {
final yaml = yamlEdit.toString();
@@ -156,9 +156,9 @@
return SourceEdit(start, end - start, valueAsString);
}
-/// Performs the string operation on [yaml] to achieve the effect of replacing
-/// the value at [key] with [newValue] when reparsed, bearing in mind that this
-/// is a flow map.
+/// Performs the string operation on [yamlEdit] to achieve the effect of
+/// replacing the value at [key] with [newValue] when reparsed, bearing in mind
+/// that this is a flow map.
SourceEdit _replaceInFlowMap(
YamlEditor yamlEdit, YamlMap map, Object? key, YamlNode newValue) {
final valueSpan = map.nodes[key]!.span;
@@ -167,8 +167,9 @@
return SourceEdit(valueSpan.start.offset, valueSpan.length, valueString);
}
-/// Performs the string operation on [yaml] to achieve the effect of removing
-/// the [key] from the map, bearing in mind that this is a block map.
+/// Performs the string operation on [yamlEdit] to achieve the effect of
+/// removing the [keyNode] from the map, bearing in mind that this is a block
+/// map.
SourceEdit _removeFromBlockMap(
YamlEditor yamlEdit, YamlMap map, YamlNode keyNode, YamlNode valueNode) {
final keySpan = keyNode.span;
@@ -214,8 +215,9 @@
return SourceEdit(start, end - start, '');
}
-/// Performs the string operation on [yaml] to achieve the effect of removing
-/// the [key] from the map, bearing in mind that this is a flow map.
+/// Performs the string operation on [yamlEdit] to achieve the effect of
+/// removing the [keyNode] from the map, bearing in mind that this is a flow
+/// map.
SourceEdit _removeFromFlowMap(
YamlEditor yamlEdit, YamlMap map, YamlNode keyNode, YamlNode valueNode) {
var start = keyNode.span.start.offset;
diff --git a/lib/src/source_edit.dart b/lib/src/source_edit.dart
index bb70c2c..d177a19 100644
--- a/lib/src/source_edit.dart
+++ b/lib/src/source_edit.dart
@@ -73,7 +73,7 @@
return SourceEdit(offset, length, replacement);
}
- throw FormatException('Invalid JSON passed to SourceEdit');
+ throw const FormatException('Invalid JSON passed to SourceEdit');
}
/// Encodes this object as JSON-compatible structure.
diff --git a/lib/src/strings.dart b/lib/src/strings.dart
index 41994b9..7bcd5b4 100644
--- a/lib/src/strings.dart
+++ b/lib/src/strings.dart
@@ -131,10 +131,10 @@
/// Returns [value] with the necessary formatting applied in a flow context
/// if possible.
///
-/// If [value] is a [YamlScalar], we try to respect its [style] parameter where
-/// possible. Certain cases make this impossible (e.g. a plain string scalar
-/// that starts with '>'), in which case we will produce [value] with default
-/// styling options.
+/// If [value] is a [YamlScalar], we try to respect its [YamlScalar.style]
+/// parameter where possible. Certain cases make this impossible (e.g. a plain
+/// string scalar that starts with '>'), in which case we will produce [value]
+/// with default styling options.
String _yamlEncodeFlowScalar(YamlNode value) {
if (value is YamlScalar) {
assertValidScalar(value.value);
@@ -161,10 +161,10 @@
/// Returns [value] with the necessary formatting applied in a block context
/// if possible.
///
-/// If [value] is a [YamlScalar], we try to respect its [style] parameter where
-/// possible. Certain cases make this impossible (e.g. a folded string scalar
-/// 'null'), in which case we will produce [value] with default styling
-/// options.
+/// If [value] is a [YamlScalar], we try to respect its [YamlScalar.style]
+/// parameter where possible. Certain cases make this impossible (e.g. a folded
+/// string scalar 'null'), in which case we will produce [value] with default
+/// styling options.
String yamlEncodeBlockScalar(
YamlNode value,
int indentation,
@@ -207,10 +207,11 @@
/// Returns [value] with the necessary formatting applied in a flow context.
///
-/// If [value] is a [YamlNode], we try to respect its [style] parameter where
-/// possible. Certain cases make this impossible (e.g. a plain string scalar
-/// that starts with '>', a child having a block style parameters), in which
-/// case we will produce [value] with default styling options.
+/// If [value] is a [YamlNode], we try to respect its [YamlScalar.style]
+/// parameter where possible. Certain cases make this impossible (e.g. a plain
+/// string scalar that starts with '>', a child having a block style
+/// parameters), in which case we will produce [value] with default styling
+/// options.
String yamlEncodeFlowString(YamlNode value) {
if (value is YamlList) {
final list = value.nodes;
@@ -231,8 +232,6 @@
}
/// Returns [value] with the necessary formatting applied in a block context.
-///
-/// If [value] is a [YamlNode], we respect its [style] parameter.
String yamlEncodeBlockString(
YamlNode value,
int indentation,
diff --git a/lib/src/utils.dart b/lib/src/utils.dart
index a84db3c..a85a155 100644
--- a/lib/src/utils.dart
+++ b/lib/src/utils.dart
@@ -6,6 +6,7 @@
import 'package:yaml/yaml.dart';
import 'editor.dart';
+import 'wrap.dart';
/// Determines if [string] is dangerous by checking if parsing the plain string
/// can return a result different from [string].
@@ -137,13 +138,13 @@
return map.length;
}
-/// Returns the detected indentation step used in [yaml], or
-/// defaults to a value of `2` if no indentation step can be detected.
+/// Returns the detected indentation step used in [editor], or defaults to a
+/// value of `2` if no indentation step can be detected.
///
/// Indentation step is determined by the difference in indentation of the
/// first block-styled yaml collection in the second level as compared to the
/// top-level elements. In the case where there are multiple possible
-/// candidates, we choose the candidate closest to the start of [yaml].
+/// candidates, we choose the candidate closest to the start of [editor].
int getIndentation(YamlEditor editor) {
final node = editor.parseAt([]);
Iterable<YamlNode>? children;
diff --git a/lib/src/wrap.dart b/lib/src/wrap.dart
index 9d4b684..73f7751 100644
--- a/lib/src/wrap.dart
+++ b/lib/src/wrap.dart
@@ -11,8 +11,8 @@
import 'equality.dart';
import 'utils.dart';
-/// Returns a new [YamlMap] constructed by applying [update] onto the [nodes]
-/// of this [YamlMap].
+/// Returns a new [YamlMap] constructed by applying [update] onto the nodes of
+/// this [YamlMap].
YamlMap updatedYamlMap(YamlMap map, Function(Map) update) {
final dummyMap = deepEqualsMap();
dummyMap.addAll(map.nodes);
diff --git a/pubspec.yaml b/pubspec.yaml
index fd13841..272da40 100644
--- a/pubspec.yaml
+++ b/pubspec.yaml
@@ -1,13 +1,16 @@
name: yaml_edit
-version: 2.2.0
-description: A library for YAML manipulation with comment and whitespace preservation.
+version: 2.2.1-wip
+description: >-
+ A library for YAML manipulation with comment and whitespace preservation.
repository: https://github.com/dart-lang/yaml_edit
+
issue_tracker: https://github.com/dart-lang/yaml_edit/issues
+
topics:
- yaml
environment:
- sdk: ">=2.19.0 <3.0.0"
+ sdk: ^3.0.0
dependencies:
collection: ^1.15.0
@@ -16,7 +19,7 @@
yaml: ^3.1.0
dev_dependencies:
- coverage: # we only need format_coverage, don't care what version
- dart_flutter_team_lints: ^1.0.0
+ coverage: any # we only need format_coverage, don't care what version
+ dart_flutter_team_lints: ^2.0.0
path: ^1.8.0
test: ^1.17.12
diff --git a/test/test_utils.dart b/test/test_utils.dart
index 8a2be42..f60467d 100644
--- a/test/test_utils.dart
+++ b/test/test_utils.dart
@@ -20,7 +20,7 @@
expectDeepEquals(builderValue, expected);
}
-/// Asserts that [builder] has the same internal value as [expected].
+/// Asserts that [actual] has the same internal value as [expected].
void expectDeepEquals(Object? actual, Object expected) {
expect(
actual, predicate((actual) => deepEquals(actual, expected), '$expected'));
@@ -31,7 +31,7 @@
/// A matcher for functions that throw [PathError].
Matcher throwsPathError = throwsA(isA<PathError>());
-/// A matcher for functions that throw [AliasError].
+/// A matcher for functions that throw [AliasException].
Matcher throwsAliasException = throwsA(isA<AliasException>());
/// Enum to hold the possible modification methods.