From 510dc9f3b0c82476fa506828111e3c4ebef6b569 Mon Sep 17 00:00:00 2001 From: Lukas Klingsbo Date: Wed, 17 Jun 2026 13:47:03 +0200 Subject: [PATCH] chore(supabase_lints): enable avoid-unnecessary-nullable return-type and parameters Fix the non-breaking sites and enable both rules: - _parseMediaType returns a non-null MediaType (parse never returns null). - _widgetsBindingInstance returns a non-null WidgetsBinding; callers drop the now-redundant null-aware access. - _initSupabaseAuthClient takes a required non-null autoRefreshToken (the only caller always passes AuthClientOptions.autoRefreshToken, a bool). - The platform_io condPlatform/condPlatformVersion/condRuntimeVersion getters are non-null (the IO implementation never returns null; the stub stays nullable for web). Two sites keep an inline ignore because their nullability is required: local_storage_stub.accessToken must match the web implementation's String?, and _copyWithType's headers parameter relies on null to fall back to the existing headers. --- packages/postgrest/lib/src/raw_postgrest_builder.dart | 1 + packages/storage_client/lib/src/fetch.dart | 2 +- packages/supabase/lib/src/platform_io.dart | 6 +++--- packages/supabase/lib/src/supabase_client.dart | 2 +- packages/supabase_flutter/lib/src/local_storage_stub.dart | 1 + packages/supabase_flutter/lib/src/platform_io.dart | 6 +++--- packages/supabase_flutter/lib/src/supabase_auth.dart | 6 +++--- packages/supabase_lints/lib/analysis_options.yaml | 2 -- 8 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/postgrest/lib/src/raw_postgrest_builder.dart b/packages/postgrest/lib/src/raw_postgrest_builder.dart index ca2b5f756..e0ec63f6e 100644 --- a/packages/postgrest/lib/src/raw_postgrest_builder.dart +++ b/packages/postgrest/lib/src/raw_postgrest_builder.dart @@ -21,6 +21,7 @@ class RawPostgrestBuilder extends PostgrestBuilder { /// Very similar to [_copyWith], but allows changing the generics, therefore [_converter] is omitted RawPostgrestBuilder _copyWithType({ Uri? url, + // ignore: avoid-unnecessary-nullable-parameters Headers? headers, String? schema, HttpMethod? method, diff --git a/packages/storage_client/lib/src/fetch.dart b/packages/storage_client/lib/src/fetch.dart index fd2393f78..64556563c 100644 --- a/packages/storage_client/lib/src/fetch.dart +++ b/packages/storage_client/lib/src/fetch.dart @@ -23,7 +23,7 @@ class Fetch { return code >= 200 && code <= 299; } - MediaType? _parseMediaType(String path) { + MediaType _parseMediaType(String path) { final mime = lookupMimeType(path); return MediaType.parse(mime ?? 'application/octet-stream'); } diff --git a/packages/supabase/lib/src/platform_io.dart b/packages/supabase/lib/src/platform_io.dart index 5747360b9..28ca25d1e 100644 --- a/packages/supabase/lib/src/platform_io.dart +++ b/packages/supabase/lib/src/platform_io.dart @@ -1,7 +1,7 @@ import 'dart:io'; -String? get condPlatform => Platform.operatingSystem; +String get condPlatform => Platform.operatingSystem; -String? get condPlatformVersion => Platform.operatingSystemVersion; +String get condPlatformVersion => Platform.operatingSystemVersion; -String? get condRuntimeVersion => Platform.version.split(' ').first; +String get condRuntimeVersion => Platform.version.split(' ').first; diff --git a/packages/supabase/lib/src/supabase_client.dart b/packages/supabase/lib/src/supabase_client.dart index 007480f1b..dbd9d2333 100644 --- a/packages/supabase/lib/src/supabase_client.dart +++ b/packages/supabase/lib/src/supabase_client.dart @@ -289,7 +289,7 @@ class SupabaseClient { } GoTrueClient _initSupabaseAuthClient({ - bool? autoRefreshToken, + required bool autoRefreshToken, required GotrueAsyncStorage? gotrueAsyncStorage, required AuthFlowType authFlowType, }) { diff --git a/packages/supabase_flutter/lib/src/local_storage_stub.dart b/packages/supabase_flutter/lib/src/local_storage_stub.dart index 29522b4b0..76a9a5d76 100644 --- a/packages/supabase_flutter/lib/src/local_storage_stub.dart +++ b/packages/supabase_flutter/lib/src/local_storage_stub.dart @@ -1,6 +1,7 @@ // coverage:ignore-file bool hasAccessToken(String _) => throw UnimplementedError(); +// ignore: avoid-unnecessary-nullable-return-type String? accessToken(String _) => throw UnimplementedError(); void removePersistedSession(String _) => throw UnimplementedError(); diff --git a/packages/supabase_flutter/lib/src/platform_io.dart b/packages/supabase_flutter/lib/src/platform_io.dart index 5747360b9..28ca25d1e 100644 --- a/packages/supabase_flutter/lib/src/platform_io.dart +++ b/packages/supabase_flutter/lib/src/platform_io.dart @@ -1,7 +1,7 @@ import 'dart:io'; -String? get condPlatform => Platform.operatingSystem; +String get condPlatform => Platform.operatingSystem; -String? get condPlatformVersion => Platform.operatingSystemVersion; +String get condPlatformVersion => Platform.operatingSystemVersion; -String? get condRuntimeVersion => Platform.version.split(' ').first; +String get condRuntimeVersion => Platform.version.split(' ').first; diff --git a/packages/supabase_flutter/lib/src/supabase_auth.dart b/packages/supabase_flutter/lib/src/supabase_auth.dart index 6d8211990..0f1efb656 100644 --- a/packages/supabase_flutter/lib/src/supabase_auth.dart +++ b/packages/supabase_flutter/lib/src/supabase_auth.dart @@ -49,7 +49,7 @@ import 'package:url_launcher/url_launcher.dart'; /// - Deep link handling is skipped on web (`kIsWeb`) because the browser /// handles URL-based redirects directly. class SupabaseAuth with WidgetsBindingObserver { - static WidgetsBinding? get _widgetsBindingInstance => WidgetsBinding.instance; + static WidgetsBinding get _widgetsBindingInstance => WidgetsBinding.instance; late LocalStorage _localStorage; @@ -115,7 +115,7 @@ class SupabaseAuth with WidgetsBindingObserver { // ignore: invalid_use_of_internal_member .notifyAllSubscribers(AuthChangeEvent.initialSession); } - _widgetsBindingInstance?.addObserver(this); + _widgetsBindingInstance.addObserver(this); if (options.detectSessionInUri) { await _startDeeplinkObserver(); @@ -150,7 +150,7 @@ class SupabaseAuth with WidgetsBindingObserver { } _authSubscription?.cancel(); _stopDeeplinkObserver(); - _widgetsBindingInstance?.removeObserver(this); + _widgetsBindingInstance.removeObserver(this); } @override diff --git a/packages/supabase_lints/lib/analysis_options.yaml b/packages/supabase_lints/lib/analysis_options.yaml index d0f3e0fa4..fadbf4b6a 100644 --- a/packages/supabase_lints/lib/analysis_options.yaml +++ b/packages/supabase_lints/lib/analysis_options.yaml @@ -28,8 +28,6 @@ dcm: avoid-throw-in-catch-block: false avoid-unassigned-stream-subscriptions: false avoid-unconditional-break: false - avoid-unnecessary-nullable-parameters: false - avoid-unnecessary-nullable-return-type: false avoid-unnecessary-reassignment: false avoid-unsafe-collection-methods: false avoid-unused-parameters: false