Skip to content

Commit 1131914

Browse files
authored
Enable strict mode for all SDKs but dart (#1163)
1 parent 9811573 commit 1131914

16 files changed

+37
-27
lines changed

dio/analysis_options.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
include: package:lints/recommended.yaml
22

33
analyzer:
4-
strong-mode:
5-
implicit-casts: false
6-
implicit-dynamic: false
74
language:
5+
strict-casts: true
6+
strict-inference: true
87
strict-raw-types: true
98
errors:
109
# treat missing required parameters as a warning (not a hint)

flutter/analysis_options.yaml

+4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
include: package:flutter_lints/flutter.yaml
22

33
analyzer:
4+
language:
5+
strict-casts: true
6+
strict-inference: true
7+
strict-raw-types: true
48
errors:
59
# treat missing required parameters as a warning (not a hint)
610
missing_required_param: error

flutter/example/lib/main.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -683,5 +683,5 @@ class ThemeProvider extends ChangeNotifier {
683683
}
684684

685685
Future<void> execute(String method) async {
686-
await _channel.invokeMethod<void>(method);
686+
await _channel.invokeMethod(method);
687687
}

flutter/lib/src/file_system_transport.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class FileSystemTransport implements Transport {
1818
// https://flutter.dev/docs/development/platform-integration/platform-channels#codec
1919
final args = [Uint8List.fromList(envelopeData)];
2020
try {
21-
await _channel.invokeMethod<void>('captureEnvelope', args);
21+
await _channel.invokeMethod('captureEnvelope', args);
2222
} catch (exception, stackTrace) {
2323
_options.logger(
2424
SentryLevel.error,

flutter/lib/src/integrations/load_contexts_integration.dart

+6-4
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,10 @@ class _LoadContextsIntegrationEventProcessor extends EventProcessor {
4242
@override
4343
FutureOr<SentryEvent?> apply(SentryEvent event, {hint}) async {
4444
try {
45-
final infos = Map<String, dynamic>.from(
46-
await (_channel.invokeMethod('loadContexts')),
47-
);
45+
final loadContexts = await _channel.invokeMethod('loadContexts');
46+
47+
final infos =
48+
Map<String, dynamic>.from(loadContexts is Map ? loadContexts : {});
4849
final contextsMap = infos['contexts'] as Map?;
4950
if (contextsMap != null && contextsMap.isNotEmpty) {
5051
final contexts = Contexts.fromJson(
@@ -138,7 +139,8 @@ class _LoadContextsIntegrationEventProcessor extends EventProcessor {
138139
final breadcrumbsList = infos['breadcrumbs'] as List?;
139140
if (breadcrumbsList != null && breadcrumbsList.isNotEmpty) {
140141
final breadcrumbs = event.breadcrumbs ?? [];
141-
final newBreadcrumbs = List<Map>.from(breadcrumbsList);
142+
final newBreadcrumbs =
143+
List<Map<dynamic, dynamic>>.from(breadcrumbsList);
142144

143145
for (final breadcrumb in newBreadcrumbs) {
144146
final newBreadcrumb = Map<String, dynamic>.from(breadcrumb);

flutter/lib/src/integrations/load_image_list_integration.dart

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,9 @@ class _LoadImageListIntegrationEventProcessor extends EventProcessor {
4141
try {
4242
// we call on every event because the loaded image list is cached
4343
// and it could be changed on the Native side.
44+
final loadImageList = await _channel.invokeMethod('loadImageList');
4445
final imageList = List<Map<dynamic, dynamic>>.from(
45-
await _channel.invokeMethod('loadImageList'),
46+
loadImageList is List ? loadImageList : [],
4647
);
4748
return copyWithDebugImages(event, imageList);
4849
} catch (exception, stackTrace) {

flutter/lib/src/integrations/native_sdk_integration.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class NativeSdkIntegration extends Integration<SentryFlutterOptions> {
1818
return;
1919
}
2020
try {
21-
await _channel.invokeMethod<void>('initNativeSdk', <String, dynamic>{
21+
await _channel.invokeMethod('initNativeSdk', <String, dynamic>{
2222
'dsn': options.dsn,
2323
'debug': options.debug,
2424
'environment': options.environment,
@@ -64,7 +64,7 @@ class NativeSdkIntegration extends Integration<SentryFlutterOptions> {
6464
return;
6565
}
6666
try {
67-
await _channel.invokeMethod<void>('closeNativeSdk');
67+
await _channel.invokeMethod('closeNativeSdk');
6868
} catch (exception, stackTrace) {
6969
_options?.logger(
7070
SentryLevel.fatal,

flutter/lib/src/sentry_asset_bundle.dart

+1
Original file line numberDiff line numberDiff line change
@@ -219,6 +219,7 @@ class SentryAssetBundle implements AssetBundle {
219219

220220
Future<ImmutableBuffer> _loadBuffer(String key) async {
221221
try {
222+
// ignore: return_of_invalid_type
222223
return (_bundle as dynamic).loadBuffer(key);
223224
} on NoSuchMethodError catch (_) {
224225
// The loadBuffer method exists as of Flutter greater than 3.1

flutter/lib/src/sentry_native_channel.dart

+5-5
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ class NativeAppStart {
138138

139139
factory NativeAppStart.fromJson(Map<String, dynamic> json) {
140140
return NativeAppStart(
141-
json['appStartTime'],
142-
json['isColdStart'],
141+
json['appStartTime'] as double,
142+
json['isColdStart'] as bool,
143143
);
144144
}
145145
}
@@ -153,9 +153,9 @@ class NativeFrames {
153153

154154
factory NativeFrames.fromJson(Map<String, dynamic> json) {
155155
return NativeFrames(
156-
json['totalFrames'],
157-
json['slowFrames'],
158-
json['frozenFrames'],
156+
json['totalFrames'] as int,
157+
json['slowFrames'] as int,
158+
json['frozenFrames'] as int,
159159
);
160160
}
161161
}

flutter/test/integrations/flutter_error_integration_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ void main() {
3333

3434
final throwable = exception ?? StateError('error');
3535
final details = FlutterErrorDetails(
36-
exception: throwable,
36+
exception: throwable as Object,
3737
silent: silent,
3838
context: DiagnosticsNode.message('while handling a gesture'),
3939
library: 'sentry',

flutter/test/integrations/init_native_sdk_integration_test.dart

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void main() {
4141
'attachThreads': false,
4242
'autoSessionTrackingIntervalMillis': 30000,
4343
'dist': null,
44-
'integrations': [],
44+
'integrations': <String>[],
4545
'packages': [
4646
{'name': 'pub:sentry', 'version': sdkVersion}
4747
],
@@ -149,7 +149,7 @@ void main() {
149149
final options = createOptions();
150150
await sut.call(NoOpHub(), options);
151151

152-
expect(options.sdk.integrations, []);
152+
expect(options.sdk.integrations, <String>[]);
153153

154154
channel.setMethodCallHandler(null);
155155
});

flutter/test/mocks.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: inference_failure_on_function_return_type
2+
13
import 'dart:async';
24

35
import 'package:flutter/services.dart';

flutter/test/sentry_flutter_util.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'package:sentry_flutter/src/file_system_transport.dart';
44

55
void testTransport({
66
required Transport transport,
7-
required hasFileSystemTransport,
7+
required bool hasFileSystemTransport,
88
}) {
99
expect(
1010
transport is FileSystemTransport,

flutter/test/sentry_native_channel_test.dart

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// ignore_for_file: inference_failure_on_function_invocation
2+
13
@TestOn('vm')
24

35
import 'package:flutter_test/flutter_test.dart';

flutter/test/sentry_navigator_observer_test.dart

+3-3
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import 'mocks.mocks.dart';
1515
void main() {
1616
late Fixture fixture;
1717

18-
PageRoute route(RouteSettings? settings) => PageRouteBuilder<void>(
18+
PageRoute<dynamic> route(RouteSettings? settings) => PageRouteBuilder<void>(
1919
pageBuilder: (_, __, ___) => Container(),
2020
settings: settings,
2121
);
@@ -92,7 +92,7 @@ void main() {
9292
actualTransaction = scope.span as SentryTracer;
9393
});
9494

95-
await Future.delayed(Duration(milliseconds: 500));
95+
await Future<void>.delayed(Duration(milliseconds: 500));
9696

9797
expect(mockNativeChannel.numberOfEndNativeFramesCalls, 1);
9898

@@ -569,7 +569,7 @@ void main() {
569569
});
570570

571571
test('No RouteSettings', () {
572-
PageRoute route() => PageRouteBuilder<void>(
572+
PageRoute<dynamic> route() => PageRouteBuilder<void>(
573573
pageBuilder: (_, __, ___) => Container(),
574574
);
575575

logging/analysis_options.yaml

+2-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
include: package:lints/recommended.yaml
22

33
analyzer:
4-
strong-mode:
5-
implicit-casts: false
6-
implicit-dynamic: false
74
language:
5+
strict-casts: true
6+
strict-inference: true
87
strict-raw-types: true
98
errors:
109
# treat missing required parameters as a warning (not a hint)

0 commit comments

Comments
 (0)