Skip to content

Commit a4b9bfd

Browse files
committed
style(functions): fix issues highlighted by new lint rules
1 parent 773d51f commit a4b9bfd

25 files changed

+144
-135
lines changed

packages/cloud_functions/cloud_functions/example/lib/main.dart

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ Future<void> main() async {
2121

2222
// ignore: public_member_api_docs
2323
class MyApp extends StatefulWidget {
24+
// ignore: public_member_api_docs
25+
MyApp({Key key}) : super(key: key);
2426
@override
2527
_MyAppState createState() => _MyAppState();
2628
}
@@ -45,7 +47,7 @@ class _MyAppState extends State<MyApp> {
4547
itemCount: fruit.length,
4648
itemBuilder: (context, index) {
4749
return ListTile(
48-
title: Text("${fruit[index]}"),
50+
title: Text('${fruit[index]}'),
4951
);
5052
})),
5153
floatingActionButton: Builder(
@@ -55,7 +57,8 @@ class _MyAppState extends State<MyApp> {
5557
// are using for this example
5658
HttpsCallable callable = FirebaseFunctions.instance.httpsCallable(
5759
'listFruit',
58-
options: HttpsCallableOptions(timeout: Duration(seconds: 5)));
60+
options: HttpsCallableOptions(
61+
timeout: const Duration(seconds: 5)));
5962

6063
await callable().then((v) {
6164
setState(() {
@@ -66,12 +69,12 @@ class _MyAppState extends State<MyApp> {
6669
});
6770
}).catchError((e) {
6871
ScaffoldMessenger.of(context).showSnackBar(SnackBar(
69-
content: Text("ERROR: $e"),
72+
content: Text('ERROR: $e'),
7073
));
7174
});
7275
},
73-
label: Text('Call Function'),
74-
icon: Icon(Icons.cloud),
76+
label: const Text('Call Function'),
77+
icon: const Icon(Icons.cloud),
7578
backgroundColor: Colors.deepOrange,
7679
),
7780
),

packages/cloud_functions/cloud_functions/example/test_driver/cloud_functions_e2e.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,13 +140,13 @@ void testsMain() {
140140
setUpAll(() async {
141141
timeoutCallable = FirebaseFunctions.instance.httpsCallable(
142142
kTestFunctionTimeout,
143-
options: HttpsCallableOptions(timeout: Duration(seconds: 3)));
143+
options: HttpsCallableOptions(timeout: const Duration(seconds: 3)));
144144
});
145145

146146
test('times out when the provided timeout is exceeded', () async {
147147
try {
148148
await timeoutCallable({
149-
'testTimeout': Duration(seconds: 6).inMilliseconds.toString(),
149+
'testTimeout': const Duration(seconds: 6).inMilliseconds.toString(),
150150
});
151151
fail('Should have thrown');
152152
} on FirebaseFunctionsException catch (e) {

packages/cloud_functions/cloud_functions/lib/src/firebase_functions.dart

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,23 @@ part of cloud_functions;
1010
///
1111
/// You can get an instance by calling [FirebaseFunctions.instance].
1212
class FirebaseFunctions extends FirebasePluginPlatform {
13+
FirebaseFunctions._({this.app, String region})
14+
: _region = region ??= 'us-central1',
15+
super(app.name, 'plugins.flutter.io/firebase_functions');
16+
1317
// Cached and lazily loaded instance of [FirebaseFunctionsPlatform] to avoid
1418
// creating a [MethodChannelFirebaseFunctions] when not needed or creating an
1519
// instance with the default app before a user specifies an app.
1620
FirebaseFunctionsPlatform _delegatePackingProperty;
1721

1822
FirebaseFunctionsPlatform get _delegate {
19-
if (_delegatePackingProperty == null) {
20-
_delegatePackingProperty =
21-
FirebaseFunctionsPlatform.instanceFor(app: app, region: _region);
22-
}
23-
return _delegatePackingProperty;
23+
return _delegatePackingProperty ??=
24+
FirebaseFunctionsPlatform.instanceFor(app: app, region: _region);
2425
}
2526

2627
/// The [FirebaseApp] for this current [FirebaseFunctions] instance.
2728
final FirebaseApp app;
2829

29-
FirebaseFunctions._({this.app, String region})
30-
: _region = region ??= 'us-central1',
31-
super(app.name, 'plugins.flutter.io/firebase_functions');
32-
3330
static final Map<String, FirebaseFunctions> _cachedInstances = {};
3431

3532
/// Returns an instance using the default [FirebaseApp] and region.
@@ -79,9 +76,12 @@ class FirebaseFunctions extends FirebasePluginPlatform {
7976
// Android considers localhost as 10.0.2.2 - automatically handle this for users.
8077
if (defaultTargetPlatform == TargetPlatform.android) {
8178
if (origin.startsWith('http://localhost')) {
82-
origin = origin.replaceFirst('http://localhost', 'http://10.0.2.2');
83-
} else if (origin.startsWith('http://127.0.0.1')) {
84-
origin = origin.replaceFirst('http://127.0.0.1', 'http://10.0.2.2');
79+
_origin = origin.replaceFirst('http://localhost', 'http://10.0.2.2');
80+
return;
81+
}
82+
if (origin.startsWith('http://127.0.0.1')) {
83+
_origin = origin.replaceFirst('http://127.0.0.1', 'http://10.0.2.2');
84+
return;
8585
}
8686
}
8787
}

packages/cloud_functions/cloud_functions/lib/src/https_callable.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ class HttpsCallable {
3838
/// Asserts whether a given call parameter is a valid type.
3939
void _assertValidParameterType(dynamic parameter, [bool isRoot = true]) {
4040
if (parameter is List) {
41-
return parameter
42-
.forEach((element) => _assertValidParameterType(element, false));
41+
for (final element in parameter) {
42+
_assertValidParameterType(element, false);
43+
}
4344
}
4445

4546
if (parameter is Map) {

packages/cloud_functions/cloud_functions/test/firebase_functions_test.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,10 @@ import 'package:firebase_core/firebase_core.dart';
88
import 'package:cloud_functions/cloud_functions.dart';
99
import 'package:cloud_functions_platform_interface/cloud_functions_platform_interface.dart';
1010
import 'package:flutter_test/flutter_test.dart';
11+
import 'package:mockito/mockito.dart';
1112

1213
import 'mock.dart';
1314

14-
import 'package:mockito/mockito.dart';
15-
1615
void main() {
1716
setupFirebaseFunctionsMocks();
1817
FirebaseFunctions functions;
@@ -29,7 +28,7 @@ void main() {
2928

3029
secondaryApp = await Firebase.initializeApp(
3130
name: 'foo',
32-
options: FirebaseOptions(
31+
options: const FirebaseOptions(
3332
apiKey: '123',
3433
appId: '123',
3534
messagingSenderId: '123',

packages/cloud_functions/cloud_functions/test/https_callable_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import 'package:cloud_functions_platform_interface/cloud_functions_platform_inte
88
import 'package:firebase_core/firebase_core.dart';
99
import 'package:cloud_functions/cloud_functions.dart';
1010
import 'package:flutter_test/flutter_test.dart';
11+
import 'package:mockito/mockito.dart';
1112

1213
import 'mock.dart';
1314

14-
import 'package:mockito/mockito.dart';
1515
import 'sample.dart' as data;
1616

1717
void main() {
@@ -43,8 +43,8 @@ void main() {
4343
return Future.value(kMockHttpsCallablePlatform);
4444
});
4545

46-
kHttpsCallable = functions.httpsCallable('test_name',
47-
options: HttpsCallableOptions(timeout: Duration(minutes: 1)));
46+
kHttpsCallable =
47+
functions.httpsCallable('test_name', options: HttpsCallableOptions());
4848
});
4949

5050
group('constructor', () {
@@ -61,7 +61,7 @@ void main() {
6161

6262
test('accepts null', () async {
6363
expect(await kHttpsCallable(null), isA<HttpsCallableResult>());
64-
verify(kMockHttpsCallablePlatform.call(null));
64+
verify(kMockHttpsCallablePlatform.call());
6565
});
6666

6767
test('accepts String', () async {

packages/cloud_functions/cloud_functions/test/mock.dart

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,16 +12,16 @@ import 'package:flutter_test/flutter_test.dart';
1212
import 'package:mockito/mockito.dart';
1313
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
1414

15-
typedef Callback(MethodCall call);
15+
typedef Callback = Function(MethodCall call);
1616

17-
final String kTestString = 'Hello World';
18-
final String kBucket = 'gs://fake-storage-bucket-url.com';
19-
final String kSecondaryBucket = 'gs://fake-storage-bucket-url-2.com';
17+
const String kTestString = 'Hello World';
18+
const String kBucket = 'gs://fake-storage-bucket-url.com';
19+
const String kSecondaryBucket = 'gs://fake-storage-bucket-url-2.com';
2020
MockFirebaseFunctionsPlatform kMockFirebaseFunctionsPlatform;
2121
final MockHttpsCallablePlatform kMockHttpsCallablePlatform =
2222
MockHttpsCallablePlatform();
2323

24-
setupFirebaseFunctionsMocks() {
24+
void setupFirebaseFunctionsMocks() {
2525
TestWidgetsFlutterBinding.ensureInitialized();
2626

2727
MethodChannelFirebase.channel.setMockMethodCallHandler((call) async {
@@ -57,24 +57,31 @@ setupFirebaseFunctionsMocks() {
5757

5858
// FirebaseFunctionsPlatform Mock
5959
class MockFirebaseFunctionsPlatform extends Mock
60-
with MockPlatformInterfaceMixin
61-
implements TestFirebaseFunctionsPlatform {
60+
with
61+
// ignore: prefer_mixin, plugin_platform_interface needs to migrate to use `mixin`
62+
MockPlatformInterfaceMixin
63+
implements
64+
TestFirebaseFunctionsPlatform {
6265
MockFirebaseFunctionsPlatform(FirebaseApp app, String region) {
6366
TestFirebaseFunctionsPlatform(app, region);
6467
}
6568
}
6669

6770
// HttpsCallablePlatform Mock
6871
class MockHttpsCallablePlatform extends Mock
69-
with MockPlatformInterfaceMixin
70-
implements HttpsCallablePlatform {}
72+
with
73+
// ignore: prefer_mixin, plugin_platform_interface needs to migrate to use `mixin`
74+
MockPlatformInterfaceMixin
75+
implements
76+
HttpsCallablePlatform {}
7177

7278
class TestFirebaseFunctionsPlatform extends FirebaseFunctionsPlatform {
7379
TestFirebaseFunctionsPlatform(FirebaseApp app, String region)
7480
: super(app, region);
7581

76-
instanceFor({FirebaseApp app, Map<dynamic, dynamic> pluginConstants}) {}
82+
void instanceFor({FirebaseApp app, Map<dynamic, dynamic> pluginConstants}) {}
7783

84+
@override
7885
FirebaseFunctionsPlatform delegateFor({FirebaseApp app, String region}) {
7986
return this;
8087
}

packages/cloud_functions/cloud_functions_platform_interface/lib/cloud_functions_platform_interface.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
library cloud_functions_platform_interface;
88

9+
export 'src/firebase_functions_exception.dart';
10+
export 'src/https_callable_options.dart';
911
export 'src/platform_interface/platform_interface_firebase_functions.dart';
1012
export 'src/platform_interface/platform_interface_https_callable.dart';
11-
export 'src/https_callable_options.dart';
12-
export 'src/firebase_functions_exception.dart';

packages/cloud_functions/cloud_functions_platform_interface/lib/src/firebase_functions_exception.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ class FirebaseFunctionsException extends FirebaseException
1818
String code,
1919
StackTrace stackTrace,
2020
this.details,
21-
}) : super(plugin: 'firebase_functions', message: message, code: code);
21+
}) : super(
22+
plugin: 'firebase_functions',
23+
message: message,
24+
code: code,
25+
stackTrace: stackTrace);
2226

2327
/// Additional data provided with the exception.
2428
final dynamic details;

packages/cloud_functions/cloud_functions_platform_interface/lib/src/method_channel/method_channel_firebase_functions.dart

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,25 @@
44

55
// @dart=2.9
66

7-
import 'package:cloud_functions_platform_interface/cloud_functions_platform_interface.dart';
87
import 'package:firebase_core/firebase_core.dart';
98
import 'package:flutter/services.dart';
109

10+
import '../../cloud_functions_platform_interface.dart';
1111
import 'method_channel_https_callable.dart';
1212

1313
/// Method Channel delegate for [FirebaseFunctionsPlatform].
1414
class MethodChannelFirebaseFunctions extends FirebaseFunctionsPlatform {
15+
/// Creates a new [MethodChannelFirebaseFunctions] instance with an [app] and/or
16+
/// [region].
17+
MethodChannelFirebaseFunctions({FirebaseApp app, String region})
18+
: super(app, region);
19+
20+
/// Internal stub class initializer.
21+
///
22+
/// When the user code calls a functions method, the real instance is
23+
/// then initialized via the [delegateFor] method.
24+
MethodChannelFirebaseFunctions._() : super(null, null);
25+
1526
/// Returns a stub instance to allow the platform interface to access
1627
/// the class instance statically.
1728
static MethodChannelFirebaseFunctions get instance {
@@ -23,23 +34,14 @@ class MethodChannelFirebaseFunctions extends FirebaseFunctionsPlatform {
2334
'plugins.flutter.io/firebase_functions',
2435
);
2536

26-
/// Internal stub class initializer.
27-
///
28-
/// When the user code calls a functions method, the real instance is
29-
/// then initialized via the [delegateFor] method.
30-
MethodChannelFirebaseFunctions._() : super(null, null);
31-
32-
/// Creates a new [MethodChannelFirebaseFunctions] instance with an [app] and/or
33-
/// [region].
34-
MethodChannelFirebaseFunctions({FirebaseApp app, String region})
35-
: super(app, region);
36-
37+
@override
3738
FirebaseFunctionsPlatform delegateFor({FirebaseApp app, String region}) {
3839
return MethodChannelFirebaseFunctions(app: app, region: region);
3940
}
4041

4142
@override
42-
httpsCallable(String origin, String name, HttpsCallableOptions options) {
43+
HttpsCallablePlatform httpsCallable(
44+
String origin, String name, HttpsCallableOptions options) {
4345
return MethodChannelHttpsCallable(this, origin, name, options);
4446
}
4547
}

0 commit comments

Comments
 (0)