Skip to content

Commit 952da66

Browse files
authored
[ffigen] Enable strict types (#1330)
Stop inferring dynamic type arguments. This PR makes `ConfigValue` default to `Object?` as it already was doing in various places. And `Map` to `Map<dynamic, dynamic>` as it already was in various places.
1 parent e108fcd commit 952da66

File tree

5 files changed

+40
-32
lines changed

5 files changed

+40
-32
lines changed

pkgs/ffi/analysis_options.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
include: package:dart_flutter_team_lints/analysis_options.yaml
22

33
analyzer:
4+
errors:
5+
todo: ignore
46
language:
57
strict-casts: true
68
strict-inference: true
9+
strict-raw-types: true
710

811
linter:
912
rules:

pkgs/ffigen/analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ analyzer:
1919
language:
2020
strict-casts: true
2121
strict-inference: true
22+
strict-raw-types: true
2223

2324
linter:
2425
rules:

pkgs/ffigen/lib/src/config_provider/config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ class Config {
748748
);
749749
}
750750

751-
bool _libraryImportsPredefinedValidation(ConfigValue node) {
751+
bool _libraryImportsPredefinedValidation(ConfigValue<Object?> node) {
752752
if (node.value is YamlMap) {
753753
return (node.value as YamlMap).keys.where((key) {
754754
if (strings.predefinedLibraryImports.containsKey(key)) {

pkgs/ffigen/lib/src/config_provider/config_spec.dart

Lines changed: 30 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// Copyright (c) 2023, the Dart project authors. Please see the AUTHORS file
2+
// for details. All rights reserved. Use of this source code is governed by a
3+
// BSD-style license that can be found in the LICENSE file.
4+
15
import 'package:logging/logging.dart';
26
import 'package:yaml/yaml.dart';
37

@@ -28,7 +32,7 @@ abstract class ConfigSpec<TE extends Object?, RE extends Object?> {
2832
String? schemaDescription;
2933

3034
/// Custom validation hook, called post validation if successful.
31-
bool Function(ConfigValue node)? customValidation;
35+
bool Function(ConfigValue<Object?> node)? customValidation;
3236

3337
/// Used to transform the payload to another type before passing to parent
3438
/// nodes and [result].
@@ -44,9 +48,9 @@ abstract class ConfigSpec<TE extends Object?, RE extends Object?> {
4448
required this.result,
4549
});
4650

47-
bool _validateNode(ConfigValue o, {bool log = true});
51+
bool _validateNode(ConfigValue<Object?> o, {bool log = true});
4852

49-
ConfigValue<RE> _extractNode(ConfigValue o);
53+
ConfigValue<RE> _extractNode(ConfigValue<Object?> o);
5054

5155
/// ConfigSpec objects should call [_getJsonRefOrSchemaNode] instead to get
5256
/// the child json schema.
@@ -82,7 +86,7 @@ abstract class ConfigSpec<TE extends Object?, RE extends Object?> {
8286
/// all underlying ConfigSpecs if valid.
8387
/// Should ideally only be called if [validate] returns True. Throws
8488
/// [ConfigSpecExtractionError] if any validation fails.
85-
ConfigValue extract(dynamic value) {
89+
ConfigValue<Object?> extract(dynamic value) {
8690
return _extractNode(ConfigValue(path: [], value: value));
8791
}
8892
}
@@ -159,7 +163,7 @@ class ConfigValue<TE> {
159163
}
160164

161165
class ConfigSpecExtractionError extends Error {
162-
final ConfigValue? item;
166+
final ConfigValue<Object?>? item;
163167
final String message;
164168
ConfigSpecExtractionError(this.item, [this.message = 'Invalid ConfigSpec']);
165169

@@ -216,8 +220,8 @@ class HeterogeneousMapConfigSpec<CE extends Object?, RE extends Object?>
216220
allKeys = {for (final kv in entries) kv.key};
217221

218222
@override
219-
bool _validateNode(ConfigValue o, {bool log = true}) {
220-
if (!o.checkType<Map>(log: log)) {
223+
bool _validateNode(ConfigValue<Object?> o, {bool log = true}) {
224+
if (!o.checkType<Map<dynamic, dynamic>>(log: log)) {
221225
return false;
222226
}
223227

@@ -266,7 +270,7 @@ class HeterogeneousMapConfigSpec<CE extends Object?, RE extends Object?>
266270
return result;
267271
}
268272

269-
dynamic _getAllDefaults(ConfigValue o) {
273+
dynamic _getAllDefaults(ConfigValue<Object?> o) {
270274
final result = <dynamic, CE>{};
271275
for (final entry in entries) {
272276
final path = [...o.path, entry.key];
@@ -298,8 +302,8 @@ class HeterogeneousMapConfigSpec<CE extends Object?, RE extends Object?>
298302
}
299303

300304
@override
301-
ConfigValue<RE> _extractNode(ConfigValue o) {
302-
if (!o.checkType<Map>(log: false)) {
305+
ConfigValue<RE> _extractNode(ConfigValue<Object?> o) {
306+
if (!o.checkType<Map<dynamic, dynamic>>(log: false)) {
303307
throw ConfigSpecExtractionError(o);
304308
}
305309

@@ -405,8 +409,8 @@ class MapConfigSpec<CE extends Object?, RE extends Object?>
405409
});
406410

407411
@override
408-
bool _validateNode(ConfigValue o, {bool log = true}) {
409-
if (!o.checkType<Map>(log: log)) {
412+
bool _validateNode(ConfigValue<Object?> o, {bool log = true}) {
413+
if (!o.checkType<Map<dynamic, dynamic>>(log: log)) {
410414
return false;
411415
}
412416

@@ -457,8 +461,8 @@ class MapConfigSpec<CE extends Object?, RE extends Object?>
457461
}
458462

459463
@override
460-
ConfigValue<RE> _extractNode(ConfigValue o) {
461-
if (!o.checkType<Map>(log: false)) {
464+
ConfigValue<RE> _extractNode(ConfigValue<Object?> o) {
465+
if (!o.checkType<Map<dynamic, dynamic>>(log: false)) {
462466
throw ConfigSpecExtractionError(o);
463467
}
464468

@@ -522,7 +526,7 @@ class ListConfigSpec<CE extends Object?, RE extends Object?>
522526
});
523527

524528
@override
525-
bool _validateNode(ConfigValue o, {bool log = true}) {
529+
bool _validateNode(ConfigValue<Object?> o, {bool log = true}) {
526530
if (!o.checkType<YamlList>(log: log)) {
527531
return false;
528532
}
@@ -544,7 +548,7 @@ class ListConfigSpec<CE extends Object?, RE extends Object?>
544548
}
545549

546550
@override
547-
ConfigValue<RE> _extractNode(ConfigValue o) {
551+
ConfigValue<RE> _extractNode(ConfigValue<Object?> o) {
548552
if (!o.checkType<YamlList>(log: false)) {
549553
throw ConfigSpecExtractionError(o);
550554
}
@@ -591,7 +595,7 @@ class StringConfigSpec<RE extends Object?> extends ConfigSpec<String, RE> {
591595
}) : _regexp = pattern == null ? null : RegExp(pattern, dotAll: true);
592596

593597
@override
594-
bool _validateNode(ConfigValue o, {bool log = true}) {
598+
bool _validateNode(ConfigValue<Object?> o, {bool log = true}) {
595599
if (!o.checkType<String>(log: log)) {
596600
return false;
597601
}
@@ -610,7 +614,7 @@ class StringConfigSpec<RE extends Object?> extends ConfigSpec<String, RE> {
610614
}
611615

612616
@override
613-
ConfigValue<RE> _extractNode(ConfigValue o) {
617+
ConfigValue<RE> _extractNode(ConfigValue<Object?> o) {
614618
if (!o.checkType<String>(log: false)) {
615619
throw ConfigSpecExtractionError(o);
616620
}
@@ -642,7 +646,7 @@ class IntConfigSpec<RE extends Object?> extends ConfigSpec<int, RE> {
642646
});
643647

644648
@override
645-
bool _validateNode(ConfigValue o, {bool log = true}) {
649+
bool _validateNode(ConfigValue<Object?> o, {bool log = true}) {
646650
if (!o.checkType<int>(log: log)) {
647651
return false;
648652
}
@@ -653,7 +657,7 @@ class IntConfigSpec<RE extends Object?> extends ConfigSpec<int, RE> {
653657
}
654658

655659
@override
656-
ConfigValue<RE> _extractNode(ConfigValue o) {
660+
ConfigValue<RE> _extractNode(ConfigValue<Object?> o) {
657661
if (!o.checkType<int>(log: false)) {
658662
throw ConfigSpecExtractionError(o);
659663
}
@@ -688,7 +692,7 @@ class EnumConfigSpec<CE extends Object?, RE extends Object?>
688692
});
689693

690694
@override
691-
bool _validateNode(ConfigValue o, {bool log = true}) {
695+
bool _validateNode(ConfigValue<Object?> o, {bool log = true}) {
692696
if (!allowedValues.contains(o.value)) {
693697
if (log) {
694698
_logger.severe(
@@ -704,7 +708,7 @@ class EnumConfigSpec<CE extends Object?, RE extends Object?>
704708
}
705709

706710
@override
707-
ConfigValue<RE> _extractNode(ConfigValue o) {
711+
ConfigValue<RE> _extractNode(ConfigValue<Object?> o) {
708712
if (!allowedValues.contains(o.value)) {
709713
throw ConfigSpecExtractionError(o);
710714
}
@@ -735,7 +739,7 @@ class BoolConfigSpec<RE> extends ConfigSpec<bool, RE> {
735739
});
736740

737741
@override
738-
bool _validateNode(ConfigValue o, {bool log = true}) {
742+
bool _validateNode(ConfigValue<Object?> o, {bool log = true}) {
739743
if (!o.checkType<bool>(log: log)) {
740744
return false;
741745
}
@@ -746,7 +750,7 @@ class BoolConfigSpec<RE> extends ConfigSpec<bool, RE> {
746750
}
747751

748752
@override
749-
ConfigValue<RE> _extractNode(ConfigValue o) {
753+
ConfigValue<RE> _extractNode(ConfigValue<Object?> o) {
750754
if (!o.checkType<bool>(log: false)) {
751755
throw ConfigSpecExtractionError(o);
752756
}
@@ -784,7 +788,7 @@ class OneOfConfigSpec<TE extends Object?, RE extends Object?>
784788
});
785789

786790
@override
787-
bool _validateNode(ConfigValue o, {bool log = true}) {
791+
bool _validateNode(ConfigValue<Object?> o, {bool log = true}) {
788792
// Running first time with no logs.
789793
for (final spec in childConfigSpecs) {
790794
if (spec._validateNode(o, log: false)) {
@@ -806,7 +810,7 @@ class OneOfConfigSpec<TE extends Object?, RE extends Object?>
806810
}
807811

808812
@override
809-
ConfigValue<RE> _extractNode(ConfigValue o) {
813+
ConfigValue<RE> _extractNode(ConfigValue<Object?> o) {
810814
for (final spec in childConfigSpecs) {
811815
if (spec._validateNode(o, log: false)) {
812816
return o

pkgs/objective_c/example/pubspec.lock

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ packages:
203203
dependency: transitive
204204
description:
205205
name: test_api
206-
sha256: "5b8a98dafc4d5c4c9c72d8b31ab2b23fc13422348d2997120294d3bac86b4ddb"
206+
sha256: "664d3a9a64782fcdeb83ce9c6b39e78fd2971d4e37827b9b06c3aa1edc5e760c"
207207
url: "https://pub.dev"
208208
source: hosted
209-
version: "0.7.2"
209+
version: "0.7.3"
210210
vector_math:
211211
dependency: transitive
212212
description:
@@ -219,10 +219,10 @@ packages:
219219
dependency: transitive
220220
description:
221221
name: vm_service
222-
sha256: "360c4271613beb44db559547d02f8b0dc044741d0eeb9aa6ccdb47e8ec54c63a"
222+
sha256: f652077d0bdf60abe4c1f6377448e8655008eef28f128bc023f7b5e8dfeb48fc
223223
url: "https://pub.dev"
224224
source: hosted
225-
version: "14.2.3"
225+
version: "14.2.4"
226226
yaml:
227227
dependency: transitive
228228
description:
@@ -232,5 +232,5 @@ packages:
232232
source: hosted
233233
version: "3.1.2"
234234
sdks:
235-
dart: ">=3.3.0 <4.0.0"
235+
dart: ">=3.4.0 <4.0.0"
236236
flutter: ">=3.18.0-18.0.pre.54"

0 commit comments

Comments
 (0)