From 651acbf0fc4bfffe408b055476b67709ca05e827 Mon Sep 17 00:00:00 2001 From: naipaka Date: Mon, 2 Dec 2024 13:31:28 +0900 Subject: [PATCH] build: Update lint package dependencies and integrate custom linting across packages --- .cspell/flutter-words.txt | 3 + example/pubspec.yaml | 6 +- .../analysis_options.yaml | 3 + .../example/pubspec.yaml | 2 +- .../lib/src/apple_authenticator.dart | 26 +++++-- .../lib/src/auth_exception.dart | 14 ++++ .../lib/src/authenticatable.dart | 34 +++++---- .../lib/src/authenticator.dart | 3 +- .../lib/src/google_authenticator.dart | 16 +++- .../lib/src/phone_authenticator.dart | 37 +++++++-- .../lib/src/signing_method.dart | 7 ++ .../lib/src/user_extension.dart | 6 ++ packages/altfire_authenticator/pubspec.yaml | 3 +- .../analysis_options.yaml | 3 + .../altfire_configurator/example/pubspec.yaml | 4 +- .../altfire_configurator/lib/src/config.dart | 1 + .../lib/src/configurator.dart | 4 + packages/altfire_configurator/pubspec.yaml | 3 +- packages/altfire_lints/analysis_options.yaml | 3 + packages/altfire_lints/lib/altfire_lints.dart | 1 + .../lib/src/lints/dispose_config.dart | 5 +- packages/altfire_lints/pubspec.yaml | 7 +- packages/altfire_lints_test/pubspec.yaml | 4 +- .../altfire_messenger/analysis_options.yaml | 3 + .../example/analysis_options.yaml | 2 + .../altfire_messenger/example/pubspec.yaml | 3 +- .../altfire_messenger/lib/src/messenger.dart | 23 ++++-- packages/altfire_messenger/pubspec.yaml | 3 +- .../test/src/messenger_test.dart | 75 +++++++++++-------- .../altfire_tracker/analysis_options.yaml | 3 + packages/altfire_tracker/example/pubspec.yaml | 3 +- packages/altfire_tracker/lib/src/tracker.dart | 1 + packages/altfire_tracker/pubspec.yaml | 3 +- 33 files changed, 227 insertions(+), 87 deletions(-) diff --git a/.cspell/flutter-words.txt b/.cspell/flutter-words.txt index 1649354..12049af 100644 --- a/.cspell/flutter-words.txt +++ b/.cspell/flutter-words.txt @@ -27,6 +27,9 @@ Podfile postbootstrap postclean pubspec +Reauthenticates +reauthenticating +reauthentication Reorderable revenuecat riverpod diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 2c675d5..161a6c6 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -21,9 +21,7 @@ dependencies: dev_dependencies: altfire_lints: path: ../packages/altfire_lints - altive_lints: ^1.10.0 - custom_lint: ^0.6.4 + altive_lints: ^1.16.0 + custom_lint: ^0.7.0 flutter_test: sdk: flutter - -flutter: diff --git a/packages/altfire_authenticator/analysis_options.yaml b/packages/altfire_authenticator/analysis_options.yaml index 4446f0e..871c1ec 100644 --- a/packages/altfire_authenticator/analysis_options.yaml +++ b/packages/altfire_authenticator/analysis_options.yaml @@ -1 +1,4 @@ include: package:altive_lints/altive_lints.yaml +analyzer: + plugins: + - custom_lint \ No newline at end of file diff --git a/packages/altfire_authenticator/example/pubspec.yaml b/packages/altfire_authenticator/example/pubspec.yaml index 3cc67c8..4c4f15e 100644 --- a/packages/altfire_authenticator/example/pubspec.yaml +++ b/packages/altfire_authenticator/example/pubspec.yaml @@ -14,7 +14,7 @@ dependencies: sdk: flutter dev_dependencies: - altive_lints: ^1.10.0 + altive_lints: ^1.16.0 flutter_test: sdk: flutter diff --git a/packages/altfire_authenticator/lib/src/apple_authenticator.dart b/packages/altfire_authenticator/lib/src/apple_authenticator.dart index 2c1f720..e42ba9e 100644 --- a/packages/altfire_authenticator/lib/src/apple_authenticator.dart +++ b/packages/altfire_authenticator/lib/src/apple_authenticator.dart @@ -4,38 +4,52 @@ import 'package:flutter/foundation.dart'; import '../altfire_authenticator.dart'; import 'authenticatable.dart'; +/// AppleAuthenticator is a class that implements the Authenticatable interface +/// to provide authentication using Apple Sign-In with Firebase. +/// +/// This class handles the authentication process for Apple Sign-In, including +/// signing in, reauthenticating, linking, and unlinking the Apple provider. +/// +/// It uses the FirebaseAuth instance to perform authentication operations. +/// +/// Example usage: +/// ```dart +/// final appleAuthenticator = AppleAuthenticator(FirebaseAuth.instance); +/// final userCredential = await appleAuthenticator.signIn(); +/// ``` class AppleAuthenticator implements Authenticatable { + /// Creates a new instance of AppleAuthenticator with + /// the provided FirebaseAuth instance. AppleAuthenticator(this._auth); final FirebaseAuth _auth; - final authProvider = AppleAuthProvider(); + final _authProvider = AppleAuthProvider(); User get _user => _auth.currentUser!; - /// 既にAppleでサインイン済みなら`true` @override bool get alreadySigned => _auth.currentUser?.hasAppleSigning ?? false; @override Future signIn([AuthCredential? credential]) async { if (kIsWeb) { - final userCredential = await _auth.signInWithPopup(authProvider); + final userCredential = await _auth.signInWithPopup(_authProvider); return userCredential; } else { - final userCredential = await _auth.signInWithProvider(authProvider); + final userCredential = await _auth.signInWithProvider(_authProvider); return userCredential; } } @override Future reauthenticate([AuthCredential? credential]) async { - return _auth.currentUser!.reauthenticateWithProvider(authProvider); + return _auth.currentUser!.reauthenticateWithProvider(_authProvider); } @override Future link([AuthCredential? credential]) async { - return _user.linkWithProvider(authProvider); + return _user.linkWithProvider(_authProvider); } @override diff --git a/packages/altfire_authenticator/lib/src/auth_exception.dart b/packages/altfire_authenticator/lib/src/auth_exception.dart index 057c471..68468e5 100644 --- a/packages/altfire_authenticator/lib/src/auth_exception.dart +++ b/packages/altfire_authenticator/lib/src/auth_exception.dart @@ -26,30 +26,44 @@ sealed class AuthException implements Exception { } } +/// Error class indicating that authentication was cancelled. class AuthCancelled implements AuthException { + /// Creates a new instance of AuthCancelled. const AuthCancelled(); } +/// Error class indicating that recent sign-in is required. class AuthRequiresRecentSignIn implements AuthException { + /// Creates a new instance of AuthRequiresRecentSignIn. const AuthRequiresRecentSignIn(); } +/// Error class indicating that the phone number is invalid. class AuthInvalidPhoneNumber implements AuthException { + /// Creates a new instance of AuthInvalidPhoneNumber. const AuthInvalidPhoneNumber(); } +/// Error class indicating that the credential is already in use. class AuthCredentialAlreadyInUse implements AuthException { + /// Creates a new instance of AuthCredentialAlreadyInUse. const AuthCredentialAlreadyInUse(); } +/// Error class indicating that the network request failed. class AuthFailedNetworkRequest implements AuthException { + /// Creates a new instance of AuthFailedNetworkRequest. const AuthFailedNetworkRequest(); } +/// Error class indicating an undefined error. class AuthUndefinedError implements AuthException { + /// Creates a new instance of AuthUndefinedError. const AuthUndefinedError(); } +/// Error class indicating that sign-in is required. class AuthRequiresSignIn implements AuthException { + /// Creates a new instance of AuthRequiresSignIn. const AuthRequiresSignIn(); } diff --git a/packages/altfire_authenticator/lib/src/authenticatable.dart b/packages/altfire_authenticator/lib/src/authenticatable.dart index 2d25a74..9fe6e51 100644 --- a/packages/altfire_authenticator/lib/src/authenticatable.dart +++ b/packages/altfire_authenticator/lib/src/authenticatable.dart @@ -1,30 +1,36 @@ import 'package:firebase_auth/firebase_auth.dart'; +/// Interface for authenticatable classes. +/// +/// This interface defines the methods required for authentication operations +/// such as sign-in, reauthentication, linking, and unlinking. +/// +/// Implementing classes should provide concrete implementations for methods. abstract class Authenticatable { - /// すでにサインイン済みかどうか。 + /// Whether the user is already signed in. bool get alreadySigned; - /// サインイン。 + /// Signs in the user. /// - /// 電話番号認証ではサインイン処理が2STEPに分かれており、 - /// [AuthCredential]を外から渡す必要があるため、 - /// オプショナル引数として[AuthCredential]を受け取る形にしている。 + /// For phone number authentication, the sign-in process is divided into + /// two steps, and an [AuthCredential] needs to be provided from outside. + /// Therefore, it is accepted as an optional argument. Future signIn([AuthCredential? credential]); - /// 再認証する。 + /// Reauthenticates the user. /// - /// 電話番号認証ではサインイン処理が2STEPに分かれており、 - /// [AuthCredential]を外から渡す必要があるため、 - /// オプショナル引数として[AuthCredential]を受け取る形にしている。 + /// For phone number authentication, the reauthentication process is divided + /// into two steps, and an [AuthCredential] needs to be provided from outside. + /// Therefore, it is accepted as an optional argument. Future reauthenticate([AuthCredential? credential]); - /// ユーザーにAppleを紐付ける。 + /// Links the user with an Apple account. /// - /// 電話番号認証ではサインイン処理が2STEPに分かれており、 - /// [AuthCredential]を外から渡す必要があるため、 - /// オプショナル引数として[AuthCredential]を受け取る形にしている。 + /// For phone number authentication, the linking process is divided into + /// two steps, and an [AuthCredential] needs to be provided from outside. + /// Therefore, it is accepted as an optional argument. Future link([AuthCredential? credential]); - /// Apple IDをリンク解除。 + /// Unlinks the user's Apple ID. Future unlink(); } diff --git a/packages/altfire_authenticator/lib/src/authenticator.dart b/packages/altfire_authenticator/lib/src/authenticator.dart index c1012b5..c78cb18 100644 --- a/packages/altfire_authenticator/lib/src/authenticator.dart +++ b/packages/altfire_authenticator/lib/src/authenticator.dart @@ -8,6 +8,7 @@ import 'phone_authenticator.dart'; /// [Authenticator] is a wrapper class for [FirebaseAuth]. class Authenticator { + /// Creates a new instance of [Authenticator]. Authenticator({ FirebaseAuth? auth, AppleAuthenticator? appleAuthenticator, @@ -141,7 +142,7 @@ class Authenticator { } else if (_appleAuth.alreadySigned) { return _appleAuth.reauthenticate(); } else { - throw UnimplementedError('未対応のSigningMethodがあります。'); + throw UnimplementedError('Reauthentication is not implemented.'); } } diff --git a/packages/altfire_authenticator/lib/src/google_authenticator.dart b/packages/altfire_authenticator/lib/src/google_authenticator.dart index 4bbc87e..44a071f 100644 --- a/packages/altfire_authenticator/lib/src/google_authenticator.dart +++ b/packages/altfire_authenticator/lib/src/google_authenticator.dart @@ -4,12 +4,26 @@ import 'package:google_sign_in/google_sign_in.dart'; import '../altfire_authenticator.dart'; import 'authenticatable.dart'; +/// GoogleAuthenticator is a class that implements the Authenticatable interface +/// to provide authentication using Google Sign-In with Firebase. +/// +/// This class handles the authentication process for Google Sign-In, including +/// signing in, reauthenticating, linking, and unlinking the Google provider. +/// +/// It uses the FirebaseAuth instance to perform authentication operations. +/// +/// Example usage: +/// ```dart +/// final googleAuthenticator = GoogleAuthenticator(FirebaseAuth.instance); +/// final userCredential = await googleAuthenticator.signIn(); +/// ``` class GoogleAuthenticator implements Authenticatable { + /// Creates a new instance of GoogleAuthenticator with GoogleAuthenticator(this._auth); final FirebaseAuth _auth; - final GoogleSignIn _googleSignIn = GoogleSignIn(); + final _googleSignIn = GoogleSignIn(); User get _user => _auth.currentUser!; diff --git a/packages/altfire_authenticator/lib/src/phone_authenticator.dart b/packages/altfire_authenticator/lib/src/phone_authenticator.dart index a644c0d..7852402 100644 --- a/packages/altfire_authenticator/lib/src/phone_authenticator.dart +++ b/packages/altfire_authenticator/lib/src/phone_authenticator.dart @@ -3,18 +3,47 @@ import 'package:firebase_auth/firebase_auth.dart'; import '../altfire_authenticator.dart'; import 'authenticatable.dart'; +/// PhoneAuthenticator is a class that implements the Authenticatable interface +/// to provide authentication using phone number verification with Firebase. +/// +/// This class handles the authentication process for phone number verification, +/// including verifying the phone number, signing in, reauthenticating, linking, +/// and unlinking the phone provider. +/// +/// It uses the FirebaseAuth instance to perform authentication operations. +/// +/// Example usage: +/// ```dart +/// final phoneAuthenticator = PhoneAuthenticator(FirebaseAuth.instance); +/// await phoneAuthenticator.verifyPhoneNumber( +/// phoneNumber: '+1234567890', +/// verificationCompleted: (credential) async { +/// final userCredential = await phoneAuthenticator.signIn(credential); +/// }, +/// verificationFailed: (exception) { +/// print('Failed to verify phone number: $exception'); +/// }, +/// codeSent: (verificationId, forceResendingToken) { +/// print('Verification code sent to phone number'); +/// }, +/// codeAutoRetrievalTimeout: (verificationId) { +/// print('Verification code auto-retrieval timed out'); +/// }, +/// ); +/// ``` class PhoneAuthenticator implements Authenticatable { + /// Creates a new instance of PhoneAuthenticator with + /// the provided FirebaseAuth instance. PhoneAuthenticator(this._auth); final FirebaseAuth _auth; User get _user => _auth.currentUser!; - /// 既に電話番号でサインイン済みなら`true` @override bool get alreadySigned => _auth.currentUser?.hasPhoneSigning ?? false; - /// 電話番号を検証し認証コードを送信する。 + /// Verifies the phone number and sends a verification code. Future verifyPhoneNumber({ required String phoneNumber, required void Function(PhoneAuthCredential credential) @@ -33,7 +62,6 @@ class PhoneAuthenticator implements Authenticatable { ); } - /// SMS認証コードを使ってサインインする。 @override Future signIn([AuthCredential? credential]) async { if (credential == null) { @@ -42,7 +70,6 @@ class PhoneAuthenticator implements Authenticatable { return _auth.signInWithCredential(credential); } - /// 電話番号認証で再認証する。 @override Future reauthenticate([AuthCredential? credential]) { if (credential == null) { @@ -51,7 +78,6 @@ class PhoneAuthenticator implements Authenticatable { return _user.reauthenticateWithCredential(credential); } - /// 電話番号認証を連携する。 @override Future link([AuthCredential? credential]) { if (credential == null) { @@ -60,7 +86,6 @@ class PhoneAuthenticator implements Authenticatable { return _user.linkWithCredential(credential); } - /// 電話番号認証の連携を解除する。 @override Future unlink() { return _user.unlink(SigningMethod.phone.providerId); diff --git a/packages/altfire_authenticator/lib/src/signing_method.dart b/packages/altfire_authenticator/lib/src/signing_method.dart index aac18c1..5b3d4fd 100644 --- a/packages/altfire_authenticator/lib/src/signing_method.dart +++ b/packages/altfire_authenticator/lib/src/signing_method.dart @@ -1,11 +1,18 @@ import 'package:firebase_auth/firebase_auth.dart'; +/// Enum class for identifying the method of authentication. enum SigningMethod { + /// Apple authentication. apple, + + /// Google authentication. google, + + /// Phone number authentication. phone, ; + /// Returns the provider ID corresponding to the authentication method. String get providerId { switch (this) { case SigningMethod.apple: diff --git a/packages/altfire_authenticator/lib/src/user_extension.dart b/packages/altfire_authenticator/lib/src/user_extension.dart index 15528a8..cefda9f 100644 --- a/packages/altfire_authenticator/lib/src/user_extension.dart +++ b/packages/altfire_authenticator/lib/src/user_extension.dart @@ -1,12 +1,18 @@ import '../altfire_authenticator.dart'; +/// Extension methods for the [User] class. extension UserExtension on User { + /// Whether the user has a Google account. bool get hasGoogleSigning => providerData.any( (userInfo) => userInfo.providerId == SigningMethod.google.providerId, ); + + /// Whether the user has an Apple account. bool get hasAppleSigning => providerData.any( (userInfo) => userInfo.providerId == SigningMethod.apple.providerId, ); + + /// Whether the user has a phone number. bool get hasPhoneSigning => providerData.any( (userInfo) => userInfo.providerId == SigningMethod.phone.providerId, ); diff --git a/packages/altfire_authenticator/pubspec.yaml b/packages/altfire_authenticator/pubspec.yaml index 7f6b3a9..d05cfd1 100644 --- a/packages/altfire_authenticator/pubspec.yaml +++ b/packages/altfire_authenticator/pubspec.yaml @@ -21,6 +21,7 @@ dependencies: google_sign_in: ^6.2.1 dev_dependencies: - altive_lints: ^1.10.0 + altive_lints: ^1.16.0 + custom_lint: ^0.7.0 flutter_test: sdk: flutter diff --git a/packages/altfire_configurator/analysis_options.yaml b/packages/altfire_configurator/analysis_options.yaml index 4446f0e..871c1ec 100644 --- a/packages/altfire_configurator/analysis_options.yaml +++ b/packages/altfire_configurator/analysis_options.yaml @@ -1 +1,4 @@ include: package:altive_lints/altive_lints.yaml +analyzer: + plugins: + - custom_lint \ No newline at end of file diff --git a/packages/altfire_configurator/example/pubspec.yaml b/packages/altfire_configurator/example/pubspec.yaml index 232c7e2..4972f27 100644 --- a/packages/altfire_configurator/example/pubspec.yaml +++ b/packages/altfire_configurator/example/pubspec.yaml @@ -17,8 +17,8 @@ dependencies: dev_dependencies: altfire_lints: path: ../../altfire_lints - altive_lints: ^1.10.0 - custom_lint: ^0.6.4 + altive_lints: ^1.16.0 + custom_lint: ^0.7.0 flutter: uses-material-design: true diff --git a/packages/altfire_configurator/lib/src/config.dart b/packages/altfire_configurator/lib/src/config.dart index 8e58ff3..f6ebf53 100644 --- a/packages/altfire_configurator/lib/src/config.dart +++ b/packages/altfire_configurator/lib/src/config.dart @@ -3,6 +3,7 @@ import 'dart:async'; /// A class that holds the value of a parameter fetched from a remote. /// It also provides a Stream of updated parameter information. class Config { + /// Creates a new instance of [Config]. Config({ required T value, required StreamSubscription? subscription, diff --git a/packages/altfire_configurator/lib/src/configurator.dart b/packages/altfire_configurator/lib/src/configurator.dart index 5225555..dd6a4e3 100644 --- a/packages/altfire_configurator/lib/src/configurator.dart +++ b/packages/altfire_configurator/lib/src/configurator.dart @@ -65,24 +65,28 @@ class Configurator { return onConfigUpdated.where((config) => config.updatedKeys.contains(key)); } + /// Get the value of the parameter of type [String]. @visibleForTesting String getString(String key) { final value = _rc.getString(key); return value; } + /// Get the value of the parameter of type [int]. @visibleForTesting int getInt(String key) { final value = _rc.getInt(key); return value; } + /// Get the value of the parameter of type [double]. @visibleForTesting double getDouble(String key) { final value = _rc.getDouble(key); return value; } + /// Get the value of the parameter of type [bool]. @visibleForTesting bool getBool(String key) { final value = _rc.getBool(key); diff --git a/packages/altfire_configurator/pubspec.yaml b/packages/altfire_configurator/pubspec.yaml index 31db947..0373ea6 100644 --- a/packages/altfire_configurator/pubspec.yaml +++ b/packages/altfire_configurator/pubspec.yaml @@ -19,6 +19,7 @@ dependencies: meta: ^1.12.0 dev_dependencies: - altive_lints: ^1.10.0 + altive_lints: ^1.16.0 + custom_lint: ^0.7.0 flutter_test: sdk: flutter diff --git a/packages/altfire_lints/analysis_options.yaml b/packages/altfire_lints/analysis_options.yaml index 4446f0e..871c1ec 100644 --- a/packages/altfire_lints/analysis_options.yaml +++ b/packages/altfire_lints/analysis_options.yaml @@ -1 +1,4 @@ include: package:altive_lints/altive_lints.yaml +analyzer: + plugins: + - custom_lint \ No newline at end of file diff --git a/packages/altfire_lints/lib/altfire_lints.dart b/packages/altfire_lints/lib/altfire_lints.dart index eb9a965..92aee17 100644 --- a/packages/altfire_lints/lib/altfire_lints.dart +++ b/packages/altfire_lints/lib/altfire_lints.dart @@ -2,6 +2,7 @@ import 'package:custom_lint_builder/custom_lint_builder.dart'; import 'src/lints/dispose_config.dart'; +/// Plugin for the AltFire lints. PluginBase createPlugin() => _AltFirePlugin(); class _AltFirePlugin extends PluginBase { diff --git a/packages/altfire_lints/lib/src/lints/dispose_config.dart b/packages/altfire_lints/lib/src/lints/dispose_config.dart index 23cf4a7..676cec0 100644 --- a/packages/altfire_lints/lib/src/lints/dispose_config.dart +++ b/packages/altfire_lints/lib/src/lints/dispose_config.dart @@ -5,6 +5,7 @@ import 'package:custom_lint_builder/custom_lint_builder.dart'; /// LintRule to ensure that Config instances are disposed. class DisposeConfig extends DartLintRule { + /// Default constructor. const DisposeConfig() : super(code: _code); static const _code = LintCode( @@ -90,7 +91,7 @@ class DisposeConfig extends DartLintRule { } if (!isDisposed) { - reporter.reportErrorForNode(_code, field); + reporter.atNode(field, _code); } } }); @@ -138,7 +139,7 @@ class DisposeConfig extends DartLintRule { } } if (!isDisposed) { - reporter.reportErrorForNode(_code, node); + reporter.atNode(node, _code); } } }); diff --git a/packages/altfire_lints/pubspec.yaml b/packages/altfire_lints/pubspec.yaml index 066f4de..bdfd4d9 100644 --- a/packages/altfire_lints/pubspec.yaml +++ b/packages/altfire_lints/pubspec.yaml @@ -12,10 +12,11 @@ environment: sdk: ^3.0.0 dependencies: - analyzer: ^6.4.1 + analyzer: ^6.7.0 analyzer_plugin: ^0.11.3 - custom_lint_builder: ^0.6.4 + custom_lint_builder: ^0.7.0 dev_dependencies: - altive_lints: ^1.10.0 + altive_lints: ^1.16.0 + custom_lint: ^0.7.0 \ No newline at end of file diff --git a/packages/altfire_lints_test/pubspec.yaml b/packages/altfire_lints_test/pubspec.yaml index e70867d..f45d0d3 100644 --- a/packages/altfire_lints_test/pubspec.yaml +++ b/packages/altfire_lints_test/pubspec.yaml @@ -13,7 +13,7 @@ dependencies: dev_dependencies: altfire_lints: path: ../altfire_lints - altive_lints: ^1.10.0 - custom_lint: ^0.6.4 + altive_lints: ^1.16.0 + custom_lint: ^0.7.0 flutter_test: sdk: flutter diff --git a/packages/altfire_messenger/analysis_options.yaml b/packages/altfire_messenger/analysis_options.yaml index 4446f0e..871c1ec 100644 --- a/packages/altfire_messenger/analysis_options.yaml +++ b/packages/altfire_messenger/analysis_options.yaml @@ -1 +1,4 @@ include: package:altive_lints/altive_lints.yaml +analyzer: + plugins: + - custom_lint \ No newline at end of file diff --git a/packages/altfire_messenger/example/analysis_options.yaml b/packages/altfire_messenger/example/analysis_options.yaml index efff296..fed7589 100644 --- a/packages/altfire_messenger/example/analysis_options.yaml +++ b/packages/altfire_messenger/example/analysis_options.yaml @@ -1 +1,3 @@ include: ../../../example/analysis_options.yaml +exclude: + - "**/firebase_options_*.dart" diff --git a/packages/altfire_messenger/example/pubspec.yaml b/packages/altfire_messenger/example/pubspec.yaml index 556b8ad..068e99c 100644 --- a/packages/altfire_messenger/example/pubspec.yaml +++ b/packages/altfire_messenger/example/pubspec.yaml @@ -14,7 +14,8 @@ dependencies: sdk: flutter dev_dependencies: - altive_lints: ^1.10.0 + altive_lints: ^1.16.0 + custom_lint: ^0.7.0 flutter_test: sdk: flutter diff --git a/packages/altfire_messenger/lib/src/messenger.dart b/packages/altfire_messenger/lib/src/messenger.dart index 274900f..08594e4 100644 --- a/packages/altfire_messenger/lib/src/messenger.dart +++ b/packages/altfire_messenger/lib/src/messenger.dart @@ -11,6 +11,7 @@ import 'package:timezone/data/latest.dart' as tz; /// It exposes methods for sending and receiving notifications, displaying /// in-app messages, and managing settings related to these functions. class Messenger { + /// Creates a new instance of Messenger. Messenger({ FirebaseMessaging? messaging, FlutterLocalNotificationsPlugin? notifications, @@ -55,7 +56,8 @@ class Messenger { /// Activated when a message is tapped and the app is opened. /// - /// This listener handles the event when the app is brought to foreground via a notification tap. + /// This listener handles the event when the app is brought to foreground + /// via a notification tap. void onMessageOpenedApp(ValueChanged onData) { FirebaseMessaging.onMessageOpenedApp.listen(onData); } @@ -69,14 +71,17 @@ class Messenger { FirebaseMessaging.onBackgroundMessage(handler); } - /// Returns the initial message when the app is opened from a terminated state. + /// Returns the initial message when the app is opened + /// from a terminated state. /// - /// This is useful for handling messages that were received while the app was closed. + /// This is useful for handling messages that were received + /// while the app was closed. Future getInitialMessage() { return _messaging.getInitialMessage(); } - /// Returns the latest FCM token that can be used for device specific messages. + /// Returns the latest FCM token that can be used + /// for device specific messages. Future getToken() { return _messaging.getToken(); } @@ -143,7 +148,8 @@ class Messenger { /// Executes when a notification is tapped while the app is in the foreground. /// - /// Parses the payload to JSON and triggers the provided callback with the data. + /// Parses the payload to JSON and triggers the provided + /// callback with the data. @visibleForTesting Future onForegroundNotificationTapped({ required NotificationResponse notificationResponse, @@ -159,7 +165,8 @@ class Messenger { /// Displays a notification with customizable settings. /// - /// Can specify the notification channel, description, icon, and color among others. + /// Can specify the notification channel, description, icon, + /// and color among others. Future showNotification({ required String channelId, required String channelName, @@ -181,9 +188,9 @@ class Messenger { color: color, ); - final iOSPlatformChannelSpecifics = DarwinNotificationDetails(); + const iOSPlatformChannelSpecifics = DarwinNotificationDetails(); - final macOSPlatformChannelSpecifics = DarwinNotificationDetails(); + const macOSPlatformChannelSpecifics = DarwinNotificationDetails(); final platformChannelSpecifics = NotificationDetails( android: androidPlatformChannelSpecifics, diff --git a/packages/altfire_messenger/pubspec.yaml b/packages/altfire_messenger/pubspec.yaml index 05d61b2..a1f15d9 100644 --- a/packages/altfire_messenger/pubspec.yaml +++ b/packages/altfire_messenger/pubspec.yaml @@ -21,7 +21,8 @@ dependencies: timezone: ^0.9.4 dev_dependencies: - altive_lints: ^1.10.0 + altive_lints: ^1.16.0 + custom_lint: ^0.7.0 flutter_test: sdk: flutter mocktail: ^1.0.4 diff --git a/packages/altfire_messenger/test/src/messenger_test.dart b/packages/altfire_messenger/test/src/messenger_test.dart index 55b2d60..f51f40c 100644 --- a/packages/altfire_messenger/test/src/messenger_test.dart +++ b/packages/altfire_messenger/test/src/messenger_test.dart @@ -22,7 +22,7 @@ void main() { group('Messenger', () { setUpAll(() { registerFallbackValue( - InitializationSettings( + const InitializationSettings( android: AndroidInitializationSettings(''), iOS: DarwinInitializationSettings( requestAlertPermission: false, @@ -65,7 +65,7 @@ void main() { }); test( - 'getNotificationSettings should call getNotificationSettings on messaging', + '''getNotificationSettings should call getNotificationSettings on messaging''', () async { final messaging = MockFirebaseMessaging(); final messenger = Messenger(messaging: messaging); @@ -131,11 +131,13 @@ void main() { notifications: notifications, ); - when(() => notifications.initialize( - any(), - onDidReceiveNotificationResponse: - any(named: 'onDidReceiveNotificationResponse'), - )).thenAnswer((_) async => true); + when( + () => notifications.initialize( + any(), + onDidReceiveNotificationResponse: + any(named: 'onDidReceiveNotificationResponse'), + ), + ).thenAnswer((_) async => true); await messenger.initializeNotifications( androidDefaultIcon: 'test_icon', @@ -147,11 +149,18 @@ void main() { verify( () => notifications.initialize( any( - that: predicate((InitializationSettings settings) => - settings.android?.defaultIcon == 'test_icon' && - settings.iOS?.requestAlertPermission == true && - settings.iOS?.requestBadgePermission == true && - settings.iOS?.requestSoundPermission == true), + that: predicate( + (InitializationSettings settings) { + final iosSettings = settings.iOS; + if (iosSettings == null) { + return false; + } + return settings.android?.defaultIcon == 'test_icon' && + iosSettings.requestAlertPermission && + iosSettings.requestBadgePermission && + iosSettings.requestSoundPermission; + }, + ), ), onDidReceiveNotificationResponse: any(named: 'onDidReceiveNotificationResponse'), @@ -168,17 +177,15 @@ void main() { notifications: notifications, ); final mockResponse = MockNotificationResponse(); - final mockPayload = '{"key": "value"}'; + const mockPayload = '{"key": "value"}'; when(() => mockResponse.payload).thenReturn(mockPayload); final completer = Completer>(); - messenger.onForegroundNotificationTapped( + await messenger.onForegroundNotificationTapped( notificationResponse: mockResponse, - onNotificationTapped: (map) { - completer.complete(map); - }, + onNotificationTapped: completer.complete, ); final result = await completer.future; @@ -193,19 +200,23 @@ void main() { notifications: notifications, ); - when(() => notifications.show( - any(), - any(), - any(), - any(), - payload: any(named: 'payload'), - )).thenAnswer((_) async {}); + when( + () => notifications.show( + any(), + any(), + any(), + any(), + payload: any(named: 'payload'), + ), + ).thenAnswer((_) async {}); await messenger.showNotification( channelId: 'test_channel', channelName: 'Test Channel', channelDescription: 'Test Description', icon: 'test_icon', + // For testing purposes, we use a hardcoded color. + // ignore: avoid_hardcoded_color color: const Color(0xFF000000), id: 1, title: 'Test Title', @@ -213,13 +224,15 @@ void main() { payloadJsonMap: {'key': 'value'}, ); - verify(() => notifications.show( - 1, - 'Test Title', - 'Test Body', - any(), - payload: any(named: 'payload'), - )).called(1); + verify( + () => notifications.show( + 1, + 'Test Title', + 'Test Body', + any(), + payload: any(named: 'payload'), + ), + ).called(1); }); }); } diff --git a/packages/altfire_tracker/analysis_options.yaml b/packages/altfire_tracker/analysis_options.yaml index 4446f0e..871c1ec 100644 --- a/packages/altfire_tracker/analysis_options.yaml +++ b/packages/altfire_tracker/analysis_options.yaml @@ -1 +1,4 @@ include: package:altive_lints/altive_lints.yaml +analyzer: + plugins: + - custom_lint \ No newline at end of file diff --git a/packages/altfire_tracker/example/pubspec.yaml b/packages/altfire_tracker/example/pubspec.yaml index 76d80d0..2ff12a7 100644 --- a/packages/altfire_tracker/example/pubspec.yaml +++ b/packages/altfire_tracker/example/pubspec.yaml @@ -15,7 +15,8 @@ dependencies: sdk: flutter dev_dependencies: - altive_lints: ^1.10.0 + altive_lints: ^1.16.0 + custom_lint: ^0.7.0 firebase_core_platform_interface: ^5.1.0 flutter_test: sdk: flutter diff --git a/packages/altfire_tracker/lib/src/tracker.dart b/packages/altfire_tracker/lib/src/tracker.dart index 06d7f37..279a8d7 100644 --- a/packages/altfire_tracker/lib/src/tracker.dart +++ b/packages/altfire_tracker/lib/src/tracker.dart @@ -12,6 +12,7 @@ import 'trackable.dart'; /// /// It exposes methods for sending analytic events and for configuration. class Tracker { + /// Create a Tracker instance. Tracker({ FirebaseCrashlytics? crashlytics, FirebaseAnalytics? analytics, diff --git a/packages/altfire_tracker/pubspec.yaml b/packages/altfire_tracker/pubspec.yaml index e58f7e2..a232b2b 100644 --- a/packages/altfire_tracker/pubspec.yaml +++ b/packages/altfire_tracker/pubspec.yaml @@ -19,7 +19,8 @@ dependencies: sdk: flutter dev_dependencies: - altive_lints: ^1.10.0 + altive_lints: ^1.16.0 + custom_lint: ^0.7.0 flutter_test: sdk: flutter mocktail: ^1.0.4