Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable strict mode for all SDKs but dart #1163

Merged
merged 6 commits into from Dec 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 2 additions & 3 deletions dio/analysis_options.yaml
@@ -1,10 +1,9 @@
include: package:lints/recommended.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
language:
strict-casts: true
strict-inference: true
marandaneto marked this conversation as resolved.
Show resolved Hide resolved
strict-raw-types: true
errors:
# treat missing required parameters as a warning (not a hint)
Expand Down
4 changes: 4 additions & 0 deletions flutter/analysis_options.yaml
@@ -1,6 +1,10 @@
include: package:flutter_lints/flutter.yaml

analyzer:
language:
strict-casts: true
strict-inference: true
strict-raw-types: true
errors:
# treat missing required parameters as a warning (not a hint)
missing_required_param: error
Expand Down
2 changes: 1 addition & 1 deletion flutter/example/lib/main.dart
Expand Up @@ -683,5 +683,5 @@ class ThemeProvider extends ChangeNotifier {
}

Future<void> execute(String method) async {
await _channel.invokeMethod<void>(method);
await _channel.invokeMethod(method);
}
2 changes: 1 addition & 1 deletion flutter/lib/src/file_system_transport.dart
Expand Up @@ -18,7 +18,7 @@ class FileSystemTransport implements Transport {
// https://flutter.dev/docs/development/platform-integration/platform-channels#codec
final args = [Uint8List.fromList(envelopeData)];
try {
await _channel.invokeMethod<void>('captureEnvelope', args);
await _channel.invokeMethod('captureEnvelope', args);
} catch (exception, stackTrace) {
_options.logger(
SentryLevel.error,
Expand Down
10 changes: 6 additions & 4 deletions flutter/lib/src/integrations/load_contexts_integration.dart
Expand Up @@ -42,9 +42,10 @@ class _LoadContextsIntegrationEventProcessor extends EventProcessor {
@override
FutureOr<SentryEvent?> apply(SentryEvent event, {hint}) async {
try {
final infos = Map<String, dynamic>.from(
await (_channel.invokeMethod('loadContexts')),
);
final loadContexts = await _channel.invokeMethod('loadContexts');

final infos =
Map<String, dynamic>.from(loadContexts is Map ? loadContexts : {});
final contextsMap = infos['contexts'] as Map?;
if (contextsMap != null && contextsMap.isNotEmpty) {
final contexts = Contexts.fromJson(
Expand Down Expand Up @@ -138,7 +139,8 @@ class _LoadContextsIntegrationEventProcessor extends EventProcessor {
final breadcrumbsList = infos['breadcrumbs'] as List?;
if (breadcrumbsList != null && breadcrumbsList.isNotEmpty) {
final breadcrumbs = event.breadcrumbs ?? [];
final newBreadcrumbs = List<Map>.from(breadcrumbsList);
final newBreadcrumbs =
List<Map<dynamic, dynamic>>.from(breadcrumbsList);

for (final breadcrumb in newBreadcrumbs) {
final newBreadcrumb = Map<String, dynamic>.from(breadcrumb);
Expand Down
Expand Up @@ -41,8 +41,9 @@ class _LoadImageListIntegrationEventProcessor extends EventProcessor {
try {
// we call on every event because the loaded image list is cached
// and it could be changed on the Native side.
final loadImageList = await _channel.invokeMethod('loadImageList');
final imageList = List<Map<dynamic, dynamic>>.from(
await _channel.invokeMethod('loadImageList'),
loadImageList is List ? loadImageList : [],
);
return copyWithDebugImages(event, imageList);
} catch (exception, stackTrace) {
Expand Down
4 changes: 2 additions & 2 deletions flutter/lib/src/integrations/native_sdk_integration.dart
Expand Up @@ -18,7 +18,7 @@ class NativeSdkIntegration extends Integration<SentryFlutterOptions> {
return;
}
try {
await _channel.invokeMethod<void>('initNativeSdk', <String, dynamic>{
await _channel.invokeMethod('initNativeSdk', <String, dynamic>{
'dsn': options.dsn,
'debug': options.debug,
'environment': options.environment,
Expand Down Expand Up @@ -64,7 +64,7 @@ class NativeSdkIntegration extends Integration<SentryFlutterOptions> {
return;
}
try {
await _channel.invokeMethod<void>('closeNativeSdk');
await _channel.invokeMethod('closeNativeSdk');
} catch (exception, stackTrace) {
_options?.logger(
SentryLevel.fatal,
Expand Down
1 change: 1 addition & 0 deletions flutter/lib/src/sentry_asset_bundle.dart
Expand Up @@ -219,6 +219,7 @@ class SentryAssetBundle implements AssetBundle {

Future<ImmutableBuffer> _loadBuffer(String key) async {
try {
// ignore: return_of_invalid_type
return (_bundle as dynamic).loadBuffer(key);
} on NoSuchMethodError catch (_) {
// The loadBuffer method exists as of Flutter greater than 3.1
Expand Down
10 changes: 5 additions & 5 deletions flutter/lib/src/sentry_native_channel.dart
Expand Up @@ -138,8 +138,8 @@ class NativeAppStart {

factory NativeAppStart.fromJson(Map<String, dynamic> json) {
return NativeAppStart(
json['appStartTime'],
json['isColdStart'],
json['appStartTime'] as double,
json['isColdStart'] as bool,
);
}
}
Expand All @@ -153,9 +153,9 @@ class NativeFrames {

factory NativeFrames.fromJson(Map<String, dynamic> json) {
return NativeFrames(
json['totalFrames'],
json['slowFrames'],
json['frozenFrames'],
json['totalFrames'] as int,
json['slowFrames'] as int,
json['frozenFrames'] as int,
);
}
}
Expand Up @@ -33,7 +33,7 @@ void main() {

final throwable = exception ?? StateError('error');
final details = FlutterErrorDetails(
exception: throwable,
exception: throwable as Object,
silent: silent,
context: DiagnosticsNode.message('while handling a gesture'),
library: 'sentry',
Expand Down
Expand Up @@ -41,7 +41,7 @@ void main() {
'attachThreads': false,
'autoSessionTrackingIntervalMillis': 30000,
'dist': null,
'integrations': [],
'integrations': <String>[],
'packages': [
{'name': 'pub:sentry', 'version': sdkVersion}
],
Expand Down Expand Up @@ -149,7 +149,7 @@ void main() {
final options = createOptions();
await sut.call(NoOpHub(), options);

expect(options.sdk.integrations, []);
expect(options.sdk.integrations, <String>[]);

channel.setMethodCallHandler(null);
});
Expand Down
2 changes: 2 additions & 0 deletions flutter/test/mocks.dart
@@ -1,3 +1,5 @@
// ignore_for_file: inference_failure_on_function_return_type

import 'dart:async';

import 'package:flutter/services.dart';
Expand Down
2 changes: 1 addition & 1 deletion flutter/test/sentry_flutter_util.dart
Expand Up @@ -4,7 +4,7 @@ import 'package:sentry_flutter/src/file_system_transport.dart';

void testTransport({
required Transport transport,
required hasFileSystemTransport,
required bool hasFileSystemTransport,
}) {
expect(
transport is FileSystemTransport,
Expand Down
2 changes: 2 additions & 0 deletions flutter/test/sentry_native_channel_test.dart
@@ -1,3 +1,5 @@
// ignore_for_file: inference_failure_on_function_invocation

@TestOn('vm')

import 'package:flutter_test/flutter_test.dart';
Expand Down
6 changes: 3 additions & 3 deletions flutter/test/sentry_navigator_observer_test.dart
Expand Up @@ -15,7 +15,7 @@ import 'mocks.mocks.dart';
void main() {
late Fixture fixture;

PageRoute route(RouteSettings? settings) => PageRouteBuilder<void>(
PageRoute<dynamic> route(RouteSettings? settings) => PageRouteBuilder<void>(
pageBuilder: (_, __, ___) => Container(),
settings: settings,
);
Expand Down Expand Up @@ -92,7 +92,7 @@ void main() {
actualTransaction = scope.span as SentryTracer;
});

await Future.delayed(Duration(milliseconds: 500));
await Future<void>.delayed(Duration(milliseconds: 500));

expect(mockNativeChannel.numberOfEndNativeFramesCalls, 1);

Expand Down Expand Up @@ -569,7 +569,7 @@ void main() {
});

test('No RouteSettings', () {
PageRoute route() => PageRouteBuilder<void>(
PageRoute<dynamic> route() => PageRouteBuilder<void>(
pageBuilder: (_, __, ___) => Container(),
);

Expand Down
5 changes: 2 additions & 3 deletions logging/analysis_options.yaml
@@ -1,10 +1,9 @@
include: package:lints/recommended.yaml

analyzer:
strong-mode:
implicit-casts: false
implicit-dynamic: false
language:
strict-casts: true
strict-inference: true
strict-raw-types: true
errors:
# treat missing required parameters as a warning (not a hint)
Expand Down