Enforce no_dynamic_calls (#7216)
diff --git a/packages/analysis_options.yaml b/packages/analysis_options.yaml index 9682889..1c202bc 100644 --- a/packages/analysis_options.yaml +++ b/packages/analysis_options.yaml
@@ -1,9 +1,13 @@ include: package:flutter_lints/flutter.yaml analyzer: - #language: - #strict-inference: true # 34 issues - #strict-raw-types: true # 103 issues + language: + # strict-casts: true # Over 300 issues; mostly parsing JSON + # Enabling strict-inference requires adding type annotations to a bunch of + # silly locations; namely `Future.delayed`. Does not seem pragmatic right + # now. + # strict-inference: true # 34 issues + # strict-raw-types: true # Over 100 issues. errors: # treat missing required parameters as a warning (not a hint) missing_required_param: warning @@ -34,6 +38,7 @@ - avoid_classes_with_only_static_members # - avoid_double_and_int_checks # only useful when targeting JS runtime - avoid_empty_else + - avoid_dynamic_calls - avoid_field_initializers_in_const_classes - avoid_function_literals_in_foreach_calls - avoid_init_to_null
diff --git a/packages/devtools_app/lib/src/screens/debugger/program_explorer_model.dart b/packages/devtools_app/lib/src/screens/debugger/program_explorer_model.dart index 85cd5db..13293c2 100644 --- a/packages/devtools_app/lib/src/screens/debugger/program_explorer_model.dart +++ b/packages/devtools_app/lib/src/screens/debugger/program_explorer_model.dart
@@ -330,7 +330,7 @@ final node = _createChild(function.name, function); _buildCodeNodes(function, node); } - for (final field in object.fields ?? []) { + for (final field in object.fields ?? <FieldRef>[]) { _createChild(field.name, field); } _sortEntriesByType();
diff --git a/packages/devtools_app/lib/src/screens/profiler/cpu_profile_model.dart b/packages/devtools_app/lib/src/screens/profiler/cpu_profile_model.dart index c2c150d..29981fb 100644 --- a/packages/devtools_app/lib/src/screens/profiler/cpu_profile_model.dart +++ b/packages/devtools_app/lib/src/screens/profiler/cpu_profile_model.dart
@@ -1295,7 +1295,7 @@ } } -extension CpuSamplesExtension on vm_service.CpuSamples { +extension on vm_service.CpuSamples { Map<String, dynamic> generateStackFramesJson({ required String isolateId, int kRootId = 0,
diff --git a/packages/devtools_app/lib/src/screens/vm_developer/object_inspector/object_store.dart b/packages/devtools_app/lib/src/screens/vm_developer/object_inspector/object_store.dart index 184f817..23440ef 100644 --- a/packages/devtools_app/lib/src/screens/vm_developer/object_inspector/object_store.dart +++ b/packages/devtools_app/lib/src/screens/vm_developer/object_inspector/object_store.dart
@@ -49,7 +49,10 @@ VoidCallback? onPressed, }) { return VmServiceObjectLink( - object: data.value, + // TODO(srawlins): What type is `data` at runtime? If cast to `int`, no + // tests fail, but that can't be right... + // ignore: avoid-dynamic + object: (data as dynamic).value, onTap: onTap, ); }
diff --git a/packages/devtools_app/lib/src/shared/diagnostics/variable_factory.dart b/packages/devtools_app/lib/src/shared/diagnostics/variable_factory.dart index de8fcf2..cec7fe0 100644 --- a/packages/devtools_app/lib/src/shared/diagnostics/variable_factory.dart +++ b/packages/devtools_app/lib/src/shared/diagnostics/variable_factory.dart
@@ -342,18 +342,19 @@ // representation. final hasPrimitiveKey = associations.fold<bool>( false, - (p, e) => p || isPrimitiveInstanceKind(e.key.kind), + (p, e) => p || isPrimitiveInstanceKind((e.key as InstanceRef).kind), ); for (var i = 0; i < associations.length; i++) { final association = associations[i]; + final associationKey = association.key; - if (association.key is! InstanceRef) { + if (associationKey is! InstanceRef) { continue; } if (hasPrimitiveKey) { variables.add( DartObjectNode.fromValue( - name: association.key.valueAsString, + name: associationKey.valueAsString, value: association.value, isolateRef: isolateRef, ), @@ -361,7 +362,7 @@ } else { final key = DartObjectNode.fromValue( name: '[key]', - value: association.key, + value: associationKey, isolateRef: isolateRef, artificialName: true, );
diff --git a/packages/devtools_extensions/example/packages_with_extensions/foo/packages/foo_devtools_extension/lib/src/service_extension_example.dart b/packages/devtools_extensions/example/packages_with_extensions/foo/packages/foo_devtools_extension/lib/src/service_extension_example.dart index 5eee027..91aaff4 100644 --- a/packages/devtools_extensions/example/packages_with_extensions/foo/packages/foo_devtools_extension/lib/src/service_extension_example.dart +++ b/packages/devtools_extensions/example/packages_with_extensions/foo/packages/foo_devtools_extension/lib/src/service_extension_example.dart
@@ -98,7 +98,8 @@ try { final response = await serviceManager .callServiceExtensionOnMainIsolate('ext.foo.getAllThings'); - things.value = response.json?['things'].cast<String>() ?? []; + final responseThings = response.json?['things'] as List<String>?; + things.value = responseThings ?? <String>[]; } catch (e) { print('Error fetching all things: $e'); }
diff --git a/packages/devtools_test/lib/src/integration_test/integration_test_utils.dart b/packages/devtools_test/lib/src/integration_test/integration_test_utils.dart index 8573307..52842cc 100644 --- a/packages/devtools_test/lib/src/integration_test/integration_test_utils.dart +++ b/packages/devtools_test/lib/src/integration_test/integration_test_utils.dart
@@ -18,7 +18,14 @@ /// Required to have multiple test cases in a file. Future<void> resetHistory() async { // ignore: avoid-dynamic, necessary here. - await (ui.PlatformDispatcher.instance.views.single as dynamic).resetHistory(); + await (ui.PlatformDispatcher.instance.views.single + as dynamic /* EngineFlutterWindow */) + // This dynamic call is necessary as `EngineFlutterWindow` is declared in + // the web-specific implementation of the Flutter Engine, at + // `lib/web_ui/lib/src/engine/window.dart` in the Flutter engine + // repository. + // ignore: avoid_dynamic_calls + .resetHistory(); } Future<void> pumpAndConnectDevTools(