Skip to content

Commit 77aeee4

Browse files
committed
Format according to dart 2.14
1 parent 1952873 commit 77aeee4

23 files changed

Lines changed: 854 additions & 404 deletions

.github/workflows/dart.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ jobs:
2626
runs-on: ubuntu-latest
2727

2828
container:
29-
image: google/dart:dev
29+
image: google/dart:2.14
3030

3131
steps:
3232
- uses: actions/checkout@v1
@@ -39,14 +39,14 @@ jobs:
3939
runs-on: ubuntu-latest
4040

4141
container:
42-
image: google/dart:dev
42+
image: google/dart:2.14
4343

4444
steps:
4545
- uses: actions/checkout@v1
4646
- name: Install dependencies
4747
run: pub get --no-precompile
4848
- name: lint
49-
run: dartanalyzer .
49+
run: dart analyze --fatal-infos
5050
- name: docs
5151
run: dartdoc .
5252
- name: Verify package completness

example/deep_pick_example.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,10 @@ Future<CounterApiStats> getStats() async {
168168
final int keys_created = pick(json, 'keys_created').asIntOrThrow();
169169
final int? keys_updated = pick(json, 'keys_updated').asIntOrNull();
170170
final String? version = pick(json, 'version').asStringOrNull();
171-
print('requests $requests, keys_created $keys_created, '
172-
'keys_updated: $keys_updated, version: "$version"');
171+
print(
172+
'requests $requests, keys_created $keys_created, '
173+
'keys_updated: $keys_updated, version: "$version"',
174+
);
173175

174176
// Parse the full object
175177
final CounterApiStats stats = CounterApiStats.fromPick(pick(json).required());

lib/src/pick.dart

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,18 @@ Pick pickFromJson(
3939
]) {
4040
final parsed = jsonDecode(json);
4141
return pick(
42-
parsed, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9);
42+
parsed,
43+
arg0,
44+
arg1,
45+
arg2,
46+
arg3,
47+
arg4,
48+
arg5,
49+
arg6,
50+
arg7,
51+
arg8,
52+
arg9,
53+
);
4354
}
4455

4556
/// Picks the value of a [json]-like dart data structure consisting of Maps,
@@ -126,8 +137,9 @@ Pick _drillDown(
126137
}
127138
if (data is Set && selector is int) {
128139
throw PickException(
129-
'Value at location ${path.sublist(0, path.length - 1)} is a Set, which is a unordered data structure. '
130-
"It's not possible to pick a value by using a index ($selector)");
140+
'Value at location ${path.sublist(0, path.length - 1)} is a Set, which is a unordered data structure. '
141+
"It's not possible to pick a value by using a index ($selector)",
142+
);
131143
}
132144
// can't drill down any more to find the exact location.
133145
return Pick.absent(path.length - 1, path: fullPath, context: context);
@@ -259,8 +271,9 @@ class Pick {
259271
final more = fromContext(requiredPickErrorHintKey).value as String?;
260272
final moreSegment = more == null ? '' : ' $more';
261273
throw PickException(
262-
'Expected a non-null value but location $debugParsingExit '
263-
'is ${isAbsent ? 'absent' : 'null'}.$moreSegment');
274+
'Expected a non-null value but location $debugParsingExit '
275+
'is ${isAbsent ? 'absent' : 'null'}.$moreSegment',
276+
);
264277
}
265278
return RequiredPick(value, path: path, context: context);
266279
}
@@ -324,7 +337,18 @@ class Pick {
324337
Object? arg8,
325338
]) {
326339
return pick(
327-
context, key, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
340+
context,
341+
key,
342+
arg0,
343+
arg1,
344+
arg2,
345+
arg3,
346+
arg4,
347+
arg5,
348+
arg6,
349+
arg7,
350+
arg8,
351+
);
328352
}
329353

330354
/// Returns a human readable String of the requested [path] and the actual

lib/src/pick_bool.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ extension BoolPick on Pick {
3131
if (value == 'false') return false;
3232
}
3333
throw PickException(
34-
'Type ${value.runtimeType} of $debugParsingExit can not be casted to bool');
34+
'Type ${value.runtimeType} of $debugParsingExit can not be casted to bool',
35+
);
3536
}
3637

3738
@Deprecated('Use .asBoolOrThrow()')
@@ -41,8 +42,10 @@ extension BoolPick on Pick {
4142
///
4243
/// {@macro Pick.asBool}
4344
bool asBoolOrThrow() {
44-
withContext(requiredPickErrorHintKey,
45-
'Use asBoolOrNull() when the value may be null/absent at some point (bool?).');
45+
withContext(
46+
requiredPickErrorHintKey,
47+
'Use asBoolOrNull() when the value may be null/absent at some point (bool?).',
48+
);
4649
return _parse();
4750
}
4851

lib/src/pick_datetime.dart

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ extension NullableDateTimePick on Pick {
108108
}
109109

110110
throw PickException(
111-
'Type ${value.runtimeType} of $debugParsingExit can not be parsed as DateTime using $format');
111+
'Type ${value.runtimeType} of $debugParsingExit can not be parsed as DateTime using $format',
112+
);
112113
}
113114

114115
// without format, try all formats
@@ -120,7 +121,8 @@ extension NullableDateTimePick on Pick {
120121
}
121122

122123
throw PickException(
123-
'Type ${value.runtimeType} of $debugParsingExit can not be parsed as DateTime');
124+
'Type ${value.runtimeType} of $debugParsingExit can not be parsed as DateTime',
125+
);
124126
}
125127

126128
/// Parses the picked [value] as ISO 8601 String to [DateTime] or throws
@@ -129,8 +131,10 @@ extension NullableDateTimePick on Pick {
129131
///
130132
/// {@macro Pick.asDateTime}
131133
DateTime asDateTimeOrThrow({PickDateFormat? format}) {
132-
withContext(requiredPickErrorHintKey,
133-
'Use asDateTimeOrNull() when the value may be null/absent at some point (DateTime?).');
134+
withContext(
135+
requiredPickErrorHintKey,
136+
'Use asDateTimeOrNull() when the value may be null/absent at some point (DateTime?).',
137+
);
134138
return _parse(format: format);
135139
}
136140

@@ -160,7 +164,8 @@ extension NullableDateTimePick on Pick {
160164
// not using HttpDate.parse because it is not available in the browsers
161165
try {
162166
final rfc1123Regex = RegExp(
163-
r'^\s*(\S{3}),\s*(\d+)\s*(\S{3})\s*(\d+)\s+(\d+):(\d+):(\d+)\s*GMT');
167+
r'^\s*(\S{3}),\s*(\d+)\s*(\S{3})\s*(\d+)\s+(\d+):(\d+):(\d+)\s*GMT',
168+
);
164169
final match = rfc1123Regex.firstMatch(value)!;
165170
final day = int.parse(match.group(2)!);
166171
final month = _months[match.group(3)!]!;
@@ -200,7 +205,8 @@ extension NullableDateTimePick on Pick {
200205
if (value is! String) return null;
201206
try {
202207
final rfc850Regex = RegExp(
203-
r'^\s*(\S+),\s*(\d+)-(\S{3})-(\d+)\s+(\d+):(\d+):(\d+)\s*(GMT|UT)');
208+
r'^\s*(\S+),\s*(\d+)-(\S{3})-(\d+)\s+(\d+):(\d+):(\d+)\s*(GMT|UT)',
209+
);
204210
final match = rfc850Regex.firstMatch(value)!;
205211
final day = int.parse(match.group(2)!);
206212
final month = _months[match.group(3)!]!;

lib/src/pick_double.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,18 @@ extension NullableDoublePick on Pick {
5656
}
5757
}
5858
throw PickException(
59-
'Type ${value.runtimeType} of $debugParsingExit can not be parsed as double');
59+
'Type ${value.runtimeType} of $debugParsingExit can not be parsed as double',
60+
);
6061
}
6162

6263
/// Returns the picked [value] as [double] or throws
6364
///
6465
/// {@macro Pick.asDouble}
6566
double asDoubleOrThrow() {
66-
withContext(requiredPickErrorHintKey,
67-
'Use asDoubleOrNull() when the value may be null/absent at some point (double?).');
67+
withContext(
68+
requiredPickErrorHintKey,
69+
'Use asDoubleOrNull() when the value may be null/absent at some point (double?).',
70+
);
6871
return _parse();
6972
}
7073

lib/src/pick_int.dart

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ extension NullableIntPick on Pick {
1717
final value = required().value;
1818
if (roundDouble && truncateDouble) {
1919
throw PickException(
20-
'[roundDouble] and [truncateDouble] can not be true at the same time');
20+
'[roundDouble] and [truncateDouble] can not be true at the same time',
21+
);
2122
}
2223
if (value is int) {
2324
return value;
@@ -36,15 +37,18 @@ extension NullableIntPick on Pick {
3637
}
3738

3839
throw PickException(
39-
'Type ${value.runtimeType} of $debugParsingExit can not be parsed as int, set [roundDouble] or [truncateDouble] to parse from double');
40+
'Type ${value.runtimeType} of $debugParsingExit can not be parsed as int, set [roundDouble] or [truncateDouble] to parse from double',
41+
);
4042
}
4143

4244
/// Returns the picked [value] as [int] or throws
4345
///
4446
/// {@macro Pick.asInt}
4547
int asIntOrThrow({bool roundDouble = false, bool truncateDouble = false}) {
46-
withContext(requiredPickErrorHintKey,
47-
'Use asIntOrNull() when the value may be null/absent at some point (int?).');
48+
withContext(
49+
requiredPickErrorHintKey,
50+
'Use asIntOrNull() when the value may be null/absent at some point (int?).',
51+
);
4852
return _parse(roundDouble, truncateDouble);
4953
}
5054

lib/src/pick_let.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,10 @@ extension NullableLet on Pick {
3535
/// pick(json, 'users', 0).letOrThrow((pick) => User.fromJson(pick.asMap()));
3636
/// ```
3737
R letOrThrow<R>(R Function(RequiredPick pick) block) {
38-
withContext(requiredPickErrorHintKey,
39-
'Use letOrNull() when the value may be null/absent at some point.');
38+
withContext(
39+
requiredPickErrorHintKey,
40+
'Use letOrNull() when the value may be null/absent at some point.',
41+
);
4042
return block(required());
4143
}
4244

lib/src/pick_list.dart

Lines changed: 31 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,13 @@ import 'package:deep_pick/src/pick.dart';
33
extension NullableListPick on Pick {
44
@Deprecated('Use .asListOrThrow()')
55
List<T> asList<T>([T Function(Pick)? map]) {
6-
return asListOrThrow((it) {
7-
final mapFn = map ?? (Pick it) => it.value as T;
8-
return mapFn(it.nullable());
9-
}, whenNull: (it) => it.value as T);
6+
return asListOrThrow(
7+
(it) {
8+
final mapFn = map ?? (Pick it) => it.value as T;
9+
return mapFn(it.nullable());
10+
},
11+
whenNull: (it) => it.value as T,
12+
);
1013
}
1114

1215
/// Returns the items of the [List] as list, mapped each item with [map]
@@ -48,8 +51,10 @@ extension NullableListPick on Pick {
4851
/// );
4952
/// ```
5053
/// {@endtemplate}
51-
List<T> _parse<T>(T Function(RequiredPick) map,
52-
{T Function(Pick pick)? whenNull}) {
54+
List<T> _parse<T>(
55+
T Function(RequiredPick) map, {
56+
T Function(Pick pick)? whenNull,
57+
}) {
5358
final value = required().value;
5459
if (value is List) {
5560
final result = <T>[];
@@ -73,33 +78,41 @@ extension NullableListPick on Pick {
7378
} catch (e) {
7479
// ignore: avoid_print
7580
print(
76-
'whenNull at location $debugParsingExit index: $index crashed instead of returning a $T');
81+
'whenNull at location $debugParsingExit index: $index crashed instead of returning a $T',
82+
);
7783
rethrow;
7884
}
7985
}
8086
return result;
8187
}
8288
throw PickException(
83-
'Type ${value.runtimeType} of $debugParsingExit can not be casted to List<dynamic>');
89+
'Type ${value.runtimeType} of $debugParsingExit can not be casted to List<dynamic>',
90+
);
8491
}
8592

8693
/// Returns the picked [value] as [List]. This method throws when [value] is
8794
/// not a `List` or [isAbsent]
8895
///
8996
/// {@macro Pick.asList}
90-
List<T> asListOrThrow<T>(T Function(RequiredPick) map,
91-
{T Function(Pick pick)? whenNull}) {
92-
withContext(requiredPickErrorHintKey,
93-
'Use asListOrEmpty()/asListOrNull() when the value may be null/absent at some point (List<$T>?).');
97+
List<T> asListOrThrow<T>(
98+
T Function(RequiredPick) map, {
99+
T Function(Pick pick)? whenNull,
100+
}) {
101+
withContext(
102+
requiredPickErrorHintKey,
103+
'Use asListOrEmpty()/asListOrNull() when the value may be null/absent at some point (List<$T>?).',
104+
);
94105
return _parse(map, whenNull: whenNull);
95106
}
96107

97108
/// Returns the picked [value] as [List] or an empty list when the `value`
98109
/// isn't a [List] or [isAbsent].
99110
///
100111
/// {@macro Pick.asList}
101-
List<T> asListOrEmpty<T>(T Function(RequiredPick) map,
102-
{T Function(Pick pick)? whenNull}) {
112+
List<T> asListOrEmpty<T>(
113+
T Function(RequiredPick) map, {
114+
T Function(Pick pick)? whenNull,
115+
}) {
103116
if (value == null) return <T>[];
104117
if (value is! List) return <T>[];
105118
return _parse(map, whenNull: whenNull);
@@ -109,8 +122,10 @@ extension NullableListPick on Pick {
109122
/// isn't a [List] or [isAbsent].
110123
///
111124
/// {@macro Pick.asList}
112-
List<T>? asListOrNull<T>(T Function(RequiredPick) map,
113-
{T Function(Pick pick)? whenNull}) {
125+
List<T>? asListOrNull<T>(
126+
T Function(RequiredPick) map, {
127+
T Function(Pick pick)? whenNull,
128+
}) {
114129
if (value == null) return null;
115130
if (value is! List) return null;
116131
return _parse(map, whenNull: whenNull);

lib/src/pick_map.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,19 @@ extension NullableMapPick on Pick {
4747
return Map.of(view);
4848
}
4949
throw PickException(
50-
'Type ${value.runtimeType} of $debugParsingExit can not be casted to Map<dynamic, dynamic>');
50+
'Type ${value.runtimeType} of $debugParsingExit can not be casted to Map<dynamic, dynamic>',
51+
);
5152
}
5253

5354
/// Returns the picked [value] as [Map]. This method throws when [value] is
5455
/// not a [Map] or [isAbsent]
5556
///
5657
/// {@macro Pick.asMap}
5758
Map<RK, RV> asMapOrThrow<RK, RV>() {
58-
withContext(requiredPickErrorHintKey,
59-
'Use asMapOrEmpty()/asMapOrNull() when the value may be null/absent at some point (Map<$RK, $RV>?).');
59+
withContext(
60+
requiredPickErrorHintKey,
61+
'Use asMapOrEmpty()/asMapOrNull() when the value may be null/absent at some point (Map<$RK, $RV>?).',
62+
);
6063
return _parse();
6164
}
6265

0 commit comments

Comments
 (0)