Skip to content

Commit

Permalink
update to the latest sdk; update lints (#68)
Browse files Browse the repository at this point in the history
  • Loading branch information
devoncarew authored Feb 23, 2024
1 parent 82ab64d commit 54884db
Show file tree
Hide file tree
Showing 13 changed files with 97 additions and 78 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ jobs:
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
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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`.
Expand Down
7 changes: 7 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions lib/src/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
12 changes: 6 additions & 6 deletions lib/src/errors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,11 @@ class PathError extends ArgumentError {
/// 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
Expand All @@ -70,7 +70,7 @@ class AliasException extends FormatException {
/// 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() {
Expand Down
60 changes: 31 additions & 29 deletions lib/src/list_mutations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import 'strings.dart';
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);
Expand Down Expand Up @@ -56,8 +57,8 @@ SourceEdit updateInList(
}
}

/// 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);
Expand All @@ -66,8 +67,8 @@ SourceEdit appendIntoList(YamlEditor yamlEdit, YamlList list, YamlNode item) {
}
}

/// 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);
Expand All @@ -85,8 +86,8 @@ SourceEdit insertInList(
}
}

/// 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];

Expand All @@ -97,17 +98,18 @@ SourceEdit removeInList(YamlEditor yamlEdit, YamlList list, int index) {
}
}

/// 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);
Expand Down Expand Up @@ -159,11 +161,11 @@ String _formatNewFlow(YamlList list, YamlNode item, [bool isLast = false]) {
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);
Expand All @@ -180,11 +182,11 @@ SourceEdit _insertInBlockList(
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);
Expand All @@ -202,11 +204,11 @@ SourceEdit _insertInFlowList(
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);
Expand Down Expand Up @@ -277,11 +279,11 @@ SourceEdit _removeFromBlockList(
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);
Expand Down
32 changes: 17 additions & 15 deletions lib/src/map_mutations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import 'strings.dart';
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) {
Expand All @@ -32,8 +32,8 @@ SourceEdit updateInMap(
}
}

/// 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);
Expand All @@ -46,7 +46,7 @@ SourceEdit removeInMap(YamlEditor yamlEdit, YamlMap map, Object? key) {
}
}

/// 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(
Expand Down Expand Up @@ -95,7 +95,7 @@ SourceEdit _addToBlockMap(
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(
Expand All @@ -120,9 +120,9 @@ SourceEdit _addToFlowMap(
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();
Expand Down Expand Up @@ -156,9 +156,9 @@ SourceEdit _replaceInBlockMap(
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;
Expand All @@ -167,8 +167,9 @@ SourceEdit _replaceInFlowMap(
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;
Expand Down Expand Up @@ -214,8 +215,9 @@ SourceEdit _removeFromBlockMap(
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;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/source_edit.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class SourceEdit {
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.
Expand Down
27 changes: 13 additions & 14 deletions lib/src/strings.dart
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@ String _tryYamlEncodeLiteral(
/// 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);
Expand All @@ -161,10 +161,10 @@ String _yamlEncodeFlowScalar(YamlNode value) {
/// 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,
Expand Down Expand Up @@ -207,10 +207,11 @@ String yamlEncodeBlockScalar(

/// 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;
Expand All @@ -231,8 +232,6 @@ String yamlEncodeFlowString(YamlNode value) {
}

/// 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,
Expand Down
7 changes: 4 additions & 3 deletions lib/src/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:source_span/source_span.dart';
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].
Expand Down Expand Up @@ -137,13 +138,13 @@ int getMapInsertionIndex(YamlMap map, Object newKey) {
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;
Expand Down
4 changes: 2 additions & 2 deletions lib/src/wrap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import 'package:yaml/yaml.dart';
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);
Expand Down
Loading

0 comments on commit 54884db

Please sign in to comment.