Skip to content

Commit f467292

Browse files
authored
Require Dart 2.19, update to latest lints
1 parent d2d82cd commit f467292

25 files changed

+158
-129
lines changed

pkgs/yaml_edit/.github/workflows/test-package.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ jobs:
4747
matrix:
4848
# Add macos-latest and/or windows-latest if relevant for this package.
4949
os: [ubuntu-latest]
50-
sdk: [2.12.0, stable, dev]
50+
sdk: [2.19.0, stable, dev]
5151
platform: [vm, chrome]
5252
steps:
5353
- uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c

pkgs/yaml_edit/CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
## 2.1.1
1+
## 2.1.1-dev
22

3-
- Update to work with an unreleased version of `package:yaml`.
3+
- Require Dart 2.19
44

55
## 2.1.0
66
- **Breaking** `wrapAsYamlNode(value, collectionStyle, scalarStyle)` will apply
@@ -9,7 +9,7 @@
99
While this may change the style of the YAML documents written by applications
1010
that rely on the old behavior, such YAML documents should still be valid.
1111
Hence, we hope it is reasonable to make this change in a minor release.
12-
- Fix for cases that can't be encodded correctedly with
12+
- Fix for cases that can't be encoded correctly with
1313
`scalarStyle: ScalarStyle.SINGLE_QUOTED`.
1414
- Fix YamlEditor `appendToList` and `insertIntoList` functions inserts new item into next yaml item
1515
rather than at end of list.

pkgs/yaml_edit/analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
include: package:lints/recommended.yaml
1+
include: package:dart_flutter_team_lints/analysis_options.yaml

pkgs/yaml_edit/lib/src/editor.dart

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import 'strings.dart';
1414
import 'utils.dart';
1515
import 'wrap.dart';
1616

17-
/// An interface for modififying [YAML][1] documents while preserving comments
17+
/// An interface for modifying [YAML][1] documents while preserving comments
1818
/// and whitespaces.
1919
///
2020
/// YAML parsing is supported by `package:yaml`, and modifications are performed
@@ -124,7 +124,7 @@ class YamlEditor {
124124
if (visited.add(node)) {
125125
if (node is YamlMap) {
126126
node.nodes.forEach((key, value) {
127-
collectAliases(key);
127+
collectAliases(key as YamlNode);
128128
collectAliases(value);
129129
});
130130
} else if (node is YamlList) {
@@ -194,7 +194,8 @@ class YamlEditor {
194194
/// Sets [value] in the [path].
195195
///
196196
/// There is a subtle difference between [update] and [remove] followed by
197-
/// an [insertIntoList], because [update] preserves comments at the same level.
197+
/// an [insertIntoList], because [update] preserves comments at the same
198+
/// level.
198199
///
199200
/// Throws a [ArgumentError] if [path] is invalid.
200201
///
@@ -291,8 +292,8 @@ class YamlEditor {
291292

292293
/// Prepends [value] to the list at [path].
293294
///
294-
/// Throws a [ArgumentError] if the element at the given path is not a [YamlList]
295-
/// or if the path is invalid.
295+
/// Throws a [ArgumentError] if the element at the given path is not a
296+
/// [YamlList] or if the path is invalid.
296297
///
297298
/// **Example:**
298299
/// ```dart
@@ -354,11 +355,11 @@ class YamlEditor {
354355

355356
final nodesToRemove = list.nodes.getRange(index, index + deleteCount);
356357

357-
/// Perform addition of elements before removal to avoid scenarioes where
358-
/// a block list gets emptied out to {} to avoid changing collection styles
359-
/// where possible.
358+
// Perform addition of elements before removal to avoid scenarios where
359+
// a block list gets emptied out to {} to avoid changing collection styles
360+
// where possible.
360361

361-
/// Reverse [values] and insert them.
362+
// Reverse [values] and insert them.
362363
final reversedValues = values.toList().reversed;
363364
for (final value in reversedValues) {
364365
insertIntoList(path, index, value);
@@ -512,7 +513,9 @@ class YamlEditor {
512513
final keyList = node.keys.toList();
513514
for (var i = 0; i < node.length; i++) {
514515
final updatedPath = [...path, keyList[i]];
515-
if (_aliases.contains(keyList[i])) throw AliasError(path, keyList[i]);
516+
if (_aliases.contains(keyList[i])) {
517+
throw AliasError(path, keyList[i] as YamlNode);
518+
}
516519
_assertNoChildAlias(updatedPath, node.nodes[keyList[i]]);
517520
}
518521
}
@@ -604,8 +607,11 @@ class YamlEditor {
604607
if (tree is YamlMap) {
605608
return updatedYamlMap(
606609
tree,
607-
(nodes) => nodes[keyOrIndex] = _deepModify(nodes[keyOrIndex], path,
608-
path.take(subPath.length + 1), expectedNode));
610+
(nodes) => nodes[keyOrIndex] = _deepModify(
611+
nodes[keyOrIndex] as YamlNode,
612+
path,
613+
path.take(subPath.length + 1),
614+
expectedNode));
609615
}
610616

611617
/// Should not ever reach here.

pkgs/yaml_edit/lib/src/equality.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ int deepHashCode(Object? value) {
8080
} else if (value is Iterable) {
8181
return const IterableEquality().hash(value.map(deepHashCode));
8282
} else if (value is YamlScalar) {
83-
return value.value.hashCode;
83+
return (value.value as Object?).hashCode;
8484
}
8585

8686
return value.hashCode;
@@ -97,7 +97,7 @@ YamlNode? getNextKeyNode(YamlMap map, Object? key) {
9797
final keyIterator = map.nodes.keys.iterator;
9898
while (keyIterator.moveNext()) {
9999
if (deepEquals(keyIterator.current, key) && keyIterator.moveNext()) {
100-
return keyIterator.current;
100+
return keyIterator.current as YamlNode?;
101101
}
102102
}
103103

pkgs/yaml_edit/lib/src/errors.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,11 +59,11 @@ class AliasError extends UnsupportedError {
5959

6060
AliasError(this.path, this.anchor)
6161
: super('Encountered an alias node along $path! '
62-
'Alias nodes are nodes that refer to a previously serialized nodes, '
63-
'and are denoted by either the "*" or the "&" indicators in the '
64-
'original YAML. As the resulting behavior of mutations on these '
65-
'nodes is not well-defined, the operation will not be supported '
66-
'by this library.\n\n'
62+
'Alias nodes are nodes that refer to a previously serialized '
63+
'nodes, and are denoted by either the "*" or the "&" indicators in '
64+
'the original YAML. As the resulting behavior of mutations on '
65+
'these nodes is not well-defined, the operation will not be '
66+
'supported by this library.\n\n'
6767
'${anchor.span.message('The alias was first defined here.')}');
6868
}
6969

pkgs/yaml_edit/lib/src/list_mutations.dart

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,15 @@ SourceEdit updateInList(
3838
if ((newValue is List && (newValue as List).isNotEmpty) ||
3939
(newValue is Map && (newValue as Map).isNotEmpty)) {
4040
valueString = valueString.substring(indentation);
41-
} else if (isCollection(currValue) &&
42-
getStyle(currValue) == CollectionStyle.BLOCK) {
41+
} else if (currValue.collectionStyle == CollectionStyle.BLOCK) {
4342
valueString += lineEnding;
4443
}
4544

4645
var end = getContentSensitiveEnd(currValue);
4746
if (end <= offset) {
4847
offset++;
4948
end = offset;
50-
valueString = ' ' + valueString;
49+
valueString = ' $valueString';
5150
}
5251

5352
return SourceEdit(offset, end - offset, valueString);
@@ -107,14 +106,16 @@ SourceEdit _appendToFlowList(
107106
}
108107

109108
/// Returns a [SourceEdit] describing the change to be made on [yaml] to achieve
110-
/// the effect of addition [item] into [nodes], noting that this is a block list.
109+
/// the effect of addition [item] into [nodes], noting that this is a block
110+
/// list.
111111
SourceEdit _appendToBlockList(
112112
YamlEditor yamlEdit, YamlList list, YamlNode item) {
113113
var formattedValue = _formatNewBlock(yamlEdit, list, item);
114114
final yaml = yamlEdit.toString();
115115
var offset = list.span.end.offset;
116116

117-
// Adjusts offset to after the trailing newline of the last entry, if it exists
117+
// Adjusts offset to after the trailing newline of the last entry, if it
118+
// exists
118119
if (list.isNotEmpty) {
119120
final lastValueSpanEnd = list.nodes.last.span.end.offset;
120121
final nextNewLineIndex = yaml.indexOf('\n', lastValueSpanEnd - 1);
@@ -139,7 +140,7 @@ String _formatNewBlock(YamlEditor yamlEdit, YamlList list, YamlNode item) {
139140
if (isCollection(item) && !isFlowYamlCollectionNode(item) && !isEmpty(item)) {
140141
valueString = valueString.substring(newIndentation);
141142
}
142-
final indentedHyphen = ' ' * listIndentation + '- ';
143+
final indentedHyphen = '${' ' * listIndentation}- ';
143144

144145
return '$indentedHyphen$valueString$lineEnding';
145146
}

pkgs/yaml_edit/lib/src/map_mutations.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@ SourceEdit _addToBlockMap(
8787
if (isCollection(newValue) &&
8888
!isFlowYamlCollectionNode(newValue) &&
8989
!isEmpty(newValue)) {
90-
formattedValue += '$keyString:' + lineEnding + valueString + lineEnding;
90+
formattedValue += '$keyString:$lineEnding$valueString$lineEnding';
9191
} else {
92-
formattedValue += '$keyString: ' + valueString + lineEnding;
92+
formattedValue += '$keyString: $valueString$lineEnding';
9393
}
9494

9595
return SourceEdit(offset, 0, formattedValue);
@@ -141,7 +141,7 @@ SourceEdit _replaceInBlockMap(
141141

142142
if (!valueAsString.startsWith(lineEnding)) {
143143
// prepend whitespace to ensure there is space after colon.
144-
valueAsString = ' ' + valueAsString;
144+
valueAsString = ' $valueAsString';
145145
}
146146

147147
/// +1 accounts for the colon

pkgs/yaml_edit/lib/src/source_edit.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@ import 'package:meta/meta.dart';
1515
/// ```
1616
/// foo: barbar
1717
/// ```
18-
/// will be represented by `SourceEdit(offset: 4, length: 3, replacement: 'bar')`
18+
/// will be represented by
19+
/// `SourceEdit(offset: 4, length: 3, replacement: 'bar')`
1920
@sealed
2021
class SourceEdit {
2122
/// The offset from the start of the string where the modification begins.

pkgs/yaml_edit/lib/src/strings.dart

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
// BSD-style license that can be found in the LICENSE file.
44

55
import 'package:yaml/yaml.dart';
6+
67
import 'utils.dart';
78

89
/// Given [value], tries to format it into a plain string recognizable by YAML.
@@ -100,9 +101,9 @@ String _tryYamlEncodeFolded(String string, int indentation, String lineEnding) {
100101
final removedPortion = string.substring(trimmedString.length);
101102

102103
if (removedPortion.contains('\n')) {
103-
result = '>+\n' + ' ' * indentation;
104+
result = '>+\n${' ' * indentation}';
104105
} else {
105-
result = '>-\n' + ' ' * indentation;
106+
result = '>-\n${' ' * indentation}';
106107
}
107108

108109
/// Duplicating the newline for folded strings preserves it in YAML.
@@ -131,15 +132,15 @@ String _tryYamlEncodeLiteral(
131132
/// if possible.
132133
///
133134
/// If [value] is a [YamlScalar], we try to respect its [style] parameter where
134-
/// possible. Certain cases make this impossible (e.g. a plain string scalar that
135-
/// starts with '>'), in which case we will produce [value] with default styling
136-
/// options.
135+
/// possible. Certain cases make this impossible (e.g. a plain string scalar
136+
/// that starts with '>'), in which case we will produce [value] with default
137+
/// styling options.
137138
String _yamlEncodeFlowScalar(YamlNode value) {
138139
if (value is YamlScalar) {
139140
assertValidScalar(value.value);
140141

141-
if (value.value is String) {
142-
final val = value.value as String;
142+
final val = value.value;
143+
if (val is String) {
143144
if (_hasUnprintableCharacters(val) ||
144145
value.style == ScalarStyle.DOUBLE_QUOTED) {
145146
return _yamlEncodeDoubleQuoted(val);
@@ -172,8 +173,8 @@ String yamlEncodeBlockScalar(
172173
if (value is YamlScalar) {
173174
assertValidScalar(value.value);
174175

175-
if (value.value is String) {
176-
final val = value.value as String;
176+
final val = value.value;
177+
if (val is String) {
177178
if (_hasUnprintableCharacters(val)) {
178179
return _yamlEncodeDoubleQuoted(val);
179180
}
@@ -215,15 +216,15 @@ String yamlEncodeFlowString(YamlNode value) {
215216
final list = value.nodes;
216217

217218
final safeValues = list.map(yamlEncodeFlowString);
218-
return '[' + safeValues.join(', ') + ']';
219+
return '[${safeValues.join(', ')}]';
219220
} else if (value is YamlMap) {
220221
final safeEntries = value.nodes.entries.map((entry) {
221-
final safeKey = yamlEncodeFlowString(entry.key);
222+
final safeKey = yamlEncodeFlowString(entry.key as YamlNode);
222223
final safeValue = yamlEncodeFlowString(entry.value);
223224
return '$safeKey: $safeValue';
224225
});
225226

226-
return '{' + safeEntries.join(', ') + '}';
227+
return '{${safeEntries.join(', ')}}';
227228
}
228229

229230
return _yamlEncodeFlowScalar(value);
@@ -244,7 +245,7 @@ String yamlEncodeBlockString(
244245
final newIndentation = indentation + additionalIndentation;
245246

246247
if (value is YamlList) {
247-
if (value.isEmpty) return ' ' * indentation + '[]';
248+
if (value.isEmpty) return '${' ' * indentation}[]';
248249

249250
Iterable<String> safeValues;
250251

@@ -257,26 +258,26 @@ String yamlEncodeBlockString(
257258
valueString = valueString.substring(newIndentation);
258259
}
259260

260-
return ' ' * indentation + '- $valueString';
261+
return '${' ' * indentation}- $valueString';
261262
});
262263

263264
return safeValues.join(lineEnding);
264265
} else if (value is YamlMap) {
265-
if (value.isEmpty) return ' ' * indentation + '{}';
266+
if (value.isEmpty) return '${' ' * indentation}{}';
266267

267268
return value.nodes.entries.map((entry) {
268-
final safeKey = yamlEncodeFlowString(entry.key);
269+
final safeKey = yamlEncodeFlowString(entry.key as YamlNode);
269270
final formattedKey = ' ' * indentation + safeKey;
270271
final formattedValue =
271272
yamlEncodeBlockString(entry.value, newIndentation, lineEnding);
272273

273274
/// Empty collections are always encoded in flow-style, so new-line must
274275
/// be avoided
275276
if (isCollection(entry.value) && !isEmpty(entry.value)) {
276-
return formattedKey + ':\n' + formattedValue;
277+
return '$formattedKey:\n$formattedValue';
277278
}
278279

279-
return formattedKey + ': ' + formattedValue;
280+
return '$formattedKey: $formattedValue';
280281
}).join(lineEnding);
281282
}
282283

0 commit comments

Comments
 (0)