Skip to content

Commit 8c39dd2

Browse files
authoredMay 16, 2023
Require Dart 3 and latest analyzer (google#1319)
1 parent d8d41af commit 8c39dd2

File tree

15 files changed

+236
-152
lines changed

15 files changed

+236
-152
lines changed
 

‎.github/workflows/dart.yml

Lines changed: 187 additions & 91 deletions
Large diffs are not rendered by default.

‎_test_yaml/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: _test_yaml
22
publish_to: none
33

44
environment:
5-
sdk: '>=2.19.0 <3.0.0'
5+
sdk: ^3.0.0
66

77
dev_dependencies:
88
_json_serial_shared_test:

‎analysis_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ linter:
1515
- cancel_subscriptions
1616
- cascade_invocations
1717
- comment_references
18+
- invalid_case_patterns
1819
- join_return_with_assignment
1920
- literal_only_boolean_expressions
2021
- missing_whitespace_between_adjacent_strings
@@ -27,6 +28,8 @@ linter:
2728
- prefer_relative_imports
2829
- sort_child_properties_last
2930
- test_types_in_equals
31+
- type_literal_in_constant_pattern
32+
- unnecessary_breaks
3033
- unsafe_html
3134
- use_full_hex_values_for_flutter_colors
3235
- use_string_buffers

‎example/pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: example
22
publish_to: none
33

44
environment:
5-
sdk: '>=2.19.0 <3.0.0'
5+
sdk: ^3.0.0
66

77
dependencies:
88
json_annotation: ^4.8.0

‎json_serializable/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 6.7.0-dev
2+
3+
- Require Dart 3.0
4+
- Require `analyzer: ^5.12.0`
5+
16
## 6.6.2
27

38
- Better handling of `Object?` or `dynamic` as `fromJson` constructor param.

‎json_serializable/lib/src/decode_helper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CreateFactoryResult {
2121
CreateFactoryResult(this.output, this.usedFields);
2222
}
2323

24-
abstract class DecodeHelper implements HelperCore {
24+
mixin DecodeHelper implements HelperCore {
2525
CreateFactoryResult createFactory(
2626
Map<String, FieldElement> accessibleFields,
2727
Map<String, String> unavailableReasons,

‎json_serializable/lib/src/encoder_helper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import 'type_helpers/generic_factory_helper.dart';
1313
import 'type_helpers/json_converter_helper.dart';
1414
import 'unsupported_type_error.dart';
1515

16-
abstract class EncodeHelper implements HelperCore {
16+
mixin EncodeHelper implements HelperCore {
1717
String _fieldAccess(FieldElement field) => '$_toJsonParamName.${field.name}';
1818

1919
String createPerFieldToJson(Set<FieldElement> accessibleFieldSet) {

‎json_serializable/lib/src/type_helpers/json_helper.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ TypeParameterType _decodeHelper(
181181
final funcParamType = type.normalParameterTypes.single;
182182

183183
if ((funcParamType.isDartCoreObject && funcParamType.isNullableType) ||
184-
funcParamType.isDynamic) {
184+
funcParamType is DynamicType) {
185185
return funcReturnType as TypeParameterType;
186186
}
187187
}
@@ -204,7 +204,7 @@ TypeParameterType _encodeHelper(
204204
final type = param.type;
205205

206206
if (type is FunctionType &&
207-
(type.returnType.isDartCoreObject || type.returnType.isDynamic) &&
207+
(type.returnType.isDartCoreObject || type.returnType is DynamicType) &&
208208
type.normalParameterTypes.length == 1) {
209209
final funcParamType = type.normalParameterTypes.single;
210210

‎json_serializable/lib/src/type_helpers/map_helper.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class MapHelper extends TypeHelper<TypeHelperContextWithConfig> {
6868

6969
_checkSafeKeyType(expression, keyArg);
7070

71-
final valueArgIsAny = valueArg.isDynamic ||
71+
final valueArgIsAny = valueArg is DynamicType ||
7272
(valueArg.isDartCoreObject && valueArg.isNullableType);
7373
final isKeyStringable = _isKeyStringable(keyArg);
7474

@@ -114,7 +114,7 @@ class MapHelper extends TypeHelper<TypeHelperContextWithConfig> {
114114
if (keyArg.isEnum) {
115115
keyUsage = context.deserialize(keyArg, _keyParam).toString();
116116
} else if (context.config.anyMap &&
117-
!(keyArg.isDartCoreObject || keyArg.isDynamic)) {
117+
!(keyArg.isDartCoreObject || keyArg is DynamicType)) {
118118
keyUsage = '$_keyParam as String';
119119
} else if (context.config.anyMap &&
120120
keyArg.isDartCoreObject &&
@@ -157,7 +157,7 @@ bool _isKeyStringable(DartType keyType) =>
157157
void _checkSafeKeyType(String expression, DartType keyArg) {
158158
// We're not going to handle converting key types at the moment
159159
// So the only safe types for key are dynamic/Object/String/enum
160-
if (keyArg.isDynamic ||
160+
if (keyArg is DynamicType ||
161161
(!keyArg.isNullableType &&
162162
(keyArg.isDartCoreObject ||
163163
coreStringTypeChecker.isExactlyType(keyArg) ||

‎json_serializable/lib/src/type_helpers/value_helper.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class ValueHelper extends TypeHelper {
2121
TypeHelperContext context,
2222
) {
2323
if (targetType.isDartCoreObject ||
24-
targetType.isDynamic ||
24+
targetType is DynamicType ||
2525
simpleJsonTypeChecker.isAssignableFromType(targetType)) {
2626
return expression;
2727
}
@@ -39,7 +39,7 @@ class ValueHelper extends TypeHelper {
3939
if (targetType.isDartCoreObject && !targetType.isNullableType) {
4040
final question = defaultProvided ? '?' : '';
4141
return '$expression as Object$question';
42-
} else if (targetType.isDartCoreObject || targetType.isDynamic) {
42+
} else if (targetType.isDartCoreObject || targetType is DynamicType) {
4343
// just return it as-is. We'll hope it's safe.
4444
return expression;
4545
} else if (targetType.isDartCoreDouble) {

‎json_serializable/lib/src/utils.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ String typeToCode(
207207
DartType type, {
208208
bool forceNullable = false,
209209
}) {
210-
if (type.isDynamic) {
210+
if (type is DynamicType) {
211211
return 'dynamic';
212212
} else if (type is InterfaceType) {
213213
return [

‎json_serializable/pubspec.yaml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
name: json_serializable
2-
version: 6.6.2
2+
version: 6.7.0-dev
33
description: >-
44
Automatically generate code for converting to and from JSON by annotating
55
Dart classes.
66
repository: https://github.com/google/json_serializable.dart/tree/master/json_serializable
77
environment:
8-
sdk: '>=2.19.0 <3.0.0'
8+
sdk: ^3.0.0
99
topics:
1010
- json
1111
- build-runner
1212
- json-serializable
1313
- codegen
1414

1515
dependencies:
16-
analyzer: ^5.2.0
16+
analyzer: ^5.12.0
1717
async: ^2.8.0
1818
build: ^2.0.0
1919
build_config: '>=0.4.4 <2.0.0'
@@ -26,7 +26,7 @@ dependencies:
2626
path: ^1.8.0
2727
pub_semver: ^2.0.0
2828
pubspec_parse: ^1.0.0
29-
source_gen: ^1.0.0
29+
source_gen: ^1.3.2
3030
source_helper: ^1.3.0
3131

3232
dev_dependencies:

‎json_serializable/test/config_test.dart

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -118,24 +118,18 @@ void main() {
118118
config[entry.key] = entry.value;
119119

120120
String lastLine;
121-
switch (entry.key) {
122-
case 'field_rename':
123-
lastLine =
124-
'`42` is not one of the supported values: none, kebab, snake, '
125-
'pascal, screamingSnake';
126-
break;
127-
case 'constructor':
128-
lastLine = "type 'int' is not a subtype of type 'String?' in type "
129-
'cast';
130-
break;
131-
case 'create_to_json':
132-
lastLine = "type 'int' is not a subtype of type 'bool?' in type "
133-
'cast';
134-
break;
135-
default:
136-
lastLine =
137-
"type 'int' is not a subtype of type 'bool?' in type cast";
138-
}
121+
lastLine = switch (entry.key) {
122+
'field_rename' =>
123+
'`42` is not one of the supported values: none, kebab, snake, '
124+
'pascal, screamingSnake',
125+
'constructor' =>
126+
"type 'int' is not a subtype of type 'String?' in type "
127+
'cast',
128+
'create_to_json' =>
129+
"type 'int' is not a subtype of type 'bool?' in type "
130+
'cast',
131+
_ => "type 'int' is not a subtype of type 'bool?' in type cast"
132+
};
139133

140134
final matcher = isA<StateError>().having(
141135
(v) => v.message,

‎json_serializable/test/kitchen_sink/kitchen_sink_yaml_test.dart

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -74,23 +74,14 @@ Matcher _getMatcher(bool checked, String? expectedKey, bool checkedAssignment) {
7474
);
7575

7676
if (checkedAssignment) {
77-
switch (expectedKey) {
78-
case 'validatedPropertyNo42':
79-
innerMatcher = isStateError;
80-
break;
81-
case 'no-42':
82-
innerMatcher = isArgumentError;
83-
break;
84-
case 'strictKeysObject':
85-
innerMatcher = _isAUnrecognizedKeysException('bob');
86-
break;
87-
case 'intIterable':
88-
case 'datetime-iterable':
89-
innerMatcher = isTypeError;
90-
break;
91-
default:
92-
throw StateError('Not expected! - $expectedKey');
93-
}
77+
innerMatcher = switch (expectedKey) {
78+
'validatedPropertyNo42' => isStateError,
79+
'no-42' => isArgumentError,
80+
'strictKeysObject' => _isAUnrecognizedKeysException('bob'),
81+
'intIterable' => isTypeError,
82+
'datetime-iterable' => isTypeError,
83+
_ => throw StateError('Not expected! - $expectedKey')
84+
};
9485
}
9586
}
9687

‎json_serializable/tool/readme_builder.dart

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -59,16 +59,11 @@ class _ReadmeBuilder extends Builder {
5959
final memberName = match.group(3);
6060
final linkContent = '[`$className${memberName ?? ''}`]';
6161
String linkValue;
62-
switch (context) {
63-
case 'core':
64-
linkValue = _coreTypeUri(className);
65-
break;
66-
case 'ja':
67-
linkValue = jsonAnnotationUri(className, memberName?.substring(1));
68-
break;
69-
default:
70-
linkValue = 'https://unknown.com/$context/$className';
71-
}
62+
linkValue = switch (context) {
63+
'core' => _coreTypeUri(className),
64+
'ja' => jsonAnnotationUri(className, memberName?.substring(1)),
65+
_ => 'https://unknown.com/$context/$className'
66+
};
7267
foundClasses[linkContent] = linkValue;
7368
return linkContent;
7469
}

0 commit comments

Comments
 (0)