Skip to content

Commit 377230d

Browse files
Merge pull request #321 from KhaleelSH/add-linting-rules
2 parents a266d55 + 2f0c55b commit 377230d

13 files changed

+49
-20
lines changed

src/SDK/Language/Dart.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ public function getKeywords()
101101
"set",
102102
"yield",
103103
"required",
104-
"default"
104+
"extension",
105+
"late"
105106
];
106107
}
107108

templates/flutter/lib/services/service.dart.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class {{ service.name | caseUcfirst }} extends Service {
5252
});
5353

5454
Uri endpoint = Uri.parse(client.endPoint);
55-
Uri url = new Uri(scheme: endpoint.scheme,
55+
Uri url = Uri(scheme: endpoint.scheme,
5656
host: endpoint.host,
5757
port: endpoint.port,
5858
path: endpoint.path + path,

templates/flutter/lib/src/client_base.dart.twig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,23 @@ abstract class ClientBase implements Client {
77
{% if header.description %}
88
/// {{header.description}}
99
{% endif %}
10+
@override
1011
ClientBase set{{header.key | caseUcfirst}}(value);
1112
{% endfor %}
1213

14+
@override
1315
ClientBase setSelfSigned({bool status = true});
1416

17+
@override
1518
ClientBase setEndpoint(String endPoint);
1619

20+
@override
1721
Client setEndPointRealtime(String endPoint);
1822

23+
@override
1924
ClientBase addHeader(String key, String value);
2025

26+
@override
2127
Future<Response> call(
2228
HttpMethod method, {
2329
String path = '',

templates/flutter/lib/src/client_browser.dart.twig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@ ClientBase createClient({
1717
class ClientBrowser extends ClientBase with ClientMixin {
1818
String _endPoint;
1919
Map<String, String>? _headers;
20+
@override
2021
late Map<String, String> config;
2122
late BrowserClient _httpClient;
2223
String? _endPointRealtime;
2324

25+
@override
2426
String? get endPointRealtime => _endPointRealtime;
2527

2628
ClientBrowser({
@@ -46,23 +48,27 @@ class ClientBrowser extends ClientBase with ClientMixin {
4648
init();
4749
}
4850

51+
@override
4952
String get endPoint => _endPoint;
5053

5154
{% for header in spec.global.headers %}
5255
{% if header.description %}
5356
/// {{header.description}}
5457
{% endif %}
58+
@override
5559
ClientBrowser set{{header.key | caseUcfirst}}(value) {
5660
config['{{ header.key | caseCamel }}'] = value;
5761
addHeader('{{header.name}}', value);
5862
return this;
5963
}
6064
{% endfor %}
6165

66+
@override
6267
ClientBrowser setSelfSigned({bool status = true}) {
6368
return this;
6469
}
6570

71+
@override
6672
ClientBrowser setEndpoint(String endPoint) {
6773
this._endPoint = endPoint;
6874
_endPointRealtime = endPoint
@@ -71,17 +77,20 @@ class ClientBrowser extends ClientBase with ClientMixin {
7177
return this;
7278
}
7379

80+
@override
7481
ClientBrowser setEndPointRealtime(String endPoint) {
7582
_endPointRealtime = endPoint;
7683
return this;
7784
}
7885

86+
@override
7987
ClientBrowser addHeader(String key, String value) {
8088
_headers![key] = value;
8189

8290
return this;
8391
}
8492

93+
@override
8594
Future init() async {
8695
if (html.window.localStorage.keys.contains('cookieFallback')) {
8796
addHeader('x-fallback-cookies',

templates/flutter/lib/src/client_io.dart.twig

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,29 @@ ClientBase createClient({
2727
class ClientIO extends ClientBase with ClientMixin {
2828
String _endPoint;
2929
Map<String, String>? _headers;
30+
@override
3031
late Map<String, String> config;
3132
bool selfSigned;
3233
bool _initialized = false;
3334
String? _endPointRealtime;
3435
late http.Client _httpClient;
3536
late HttpClient _nativeClient;
3637
late CookieJar _cookieJar;
37-
List<Interceptor> _interceptors = [];
38+
final List<Interceptor> _interceptors = [];
3839

3940
bool get initialized => _initialized;
4041
CookieJar get cookieJar => _cookieJar;
42+
@override
4143
String? get endPointRealtime => _endPointRealtime;
4244

4345
ClientIO({
4446
String endPoint = 'https://appwrite.io/v1',
4547
this.selfSigned = false,
4648
}) : _endPoint = endPoint {
47-
_nativeClient = new HttpClient()
49+
_nativeClient = HttpClient()
4850
..badCertificateCallback =
4951
((X509Certificate cert, String host, int port) => selfSigned);
50-
_httpClient = new IOClient(_nativeClient);
52+
_httpClient = IOClient(_nativeClient);
5153
_endPointRealtime = endPoint
5254
.replaceFirst('https://', 'wss://')
5355
.replaceFirst('http://', 'ws://');
@@ -66,12 +68,13 @@ class ClientIO extends ClientBase with ClientMixin {
6668
init();
6769
}
6870

71+
@override
6972
String get endPoint => _endPoint;
7073

7174
Future<Directory> _getCookiePath() async {
7275
final directory = await getApplicationDocumentsDirectory();
7376
final path = directory.path;
74-
final Directory dir = new Directory('$path/cookies');
77+
final Directory dir = Directory('$path/cookies');
7578
await dir.create();
7679
return dir;
7780
}
@@ -80,20 +83,23 @@ class ClientIO extends ClientBase with ClientMixin {
8083
{% if header.description %}
8184
/// {{header.description}}
8285
{% endif %}
86+
@override
8387
ClientIO set{{header.key | caseUcfirst}}(value) {
8488
config['{{ header.key | caseCamel }}'] = value;
8589
addHeader('{{header.name}}', value);
8690
return this;
8791
}
8892
{% endfor %}
8993

94+
@override
9095
ClientIO setSelfSigned({bool status = true}) {
9196
this.selfSigned = status;
9297
_nativeClient.badCertificateCallback =
9398
((X509Certificate cert, String host, int port) => status);
9499
return this;
95100
}
96101

102+
@override
97103
ClientIO setEndpoint(String endPoint) {
98104
this._endPoint = endPoint;
99105
_endPointRealtime = endPoint
@@ -102,11 +108,13 @@ class ClientIO extends ClientBase with ClientMixin {
102108
return this;
103109
}
104110

111+
@override
105112
ClientIO setEndPointRealtime(String endPoint) {
106113
_endPointRealtime = endPoint;
107114
return this;
108115
}
109116

117+
@override
110118
ClientIO addHeader(String key, String value) {
111119
_headers![key] = value;
112120

@@ -116,7 +124,7 @@ class ClientIO extends ClientBase with ClientMixin {
116124
Future init() async {
117125
// if web skip cookie implementation and origin header as those are automatically handled by browsers
118126
final Directory cookieDir = await _getCookiePath();
119-
_cookieJar = new PersistCookieJar(storage: FileStorage(cookieDir.path));
127+
_cookieJar = PersistCookieJar(storage: FileStorage(cookieDir.path));
120128
this._interceptors.add(CookieManager(_cookieJar));
121129
PackageInfo packageInfo = await PackageInfo.fromPlatform();
122130
addHeader('Origin',
@@ -191,6 +199,7 @@ class ClientIO extends ClientBase with ClientMixin {
191199
return response;
192200
}
193201

202+
@override
194203
Future webAuth(Uri url) {
195204
return FlutterWebAuth.authenticate(
196205
url: url.toString(),
@@ -203,7 +212,7 @@ class ClientIO extends ClientBase with ClientMixin {
203212
throw {{spec.title | caseUcfirst}}Exception(
204213
"Invalid OAuth2 Response. Key and Secret not available.", 500);
205214
}
206-
Cookie cookie = new Cookie(key, secret);
215+
Cookie cookie = Cookie(key, secret);
207216
cookie.domain = Uri.parse(_endPoint).host;
208217
cookie.httpOnly = true;
209218
cookie.path = '/';
@@ -213,6 +222,7 @@ class ClientIO extends ClientBase with ClientMixin {
213222
});
214223
}
215224

225+
@override
216226
Future<Response> call(
217227
HttpMethod method, {
218228
String path = '',

templates/flutter/lib/src/client_mixin.dart.twig

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ class ClientMixin {
6767
}
6868

6969
Response prepareResponse(http.Response res, {ResponseType? responseType}) {
70-
if (responseType == null) {
71-
responseType = ResponseType.json;
72-
}
70+
responseType ??= ResponseType.json;
7371
if (res.statusCode >= 400) {
7472
if ((res.headers['content-type'] ?? '').contains('application/json')) {
7573
final response = json.decode(res.body);
@@ -82,7 +80,7 @@ class ClientMixin {
8280
throw {{spec.title | caseUcfirst}}Exception(res.body);
8381
}
8482
}
85-
var data;
83+
dynamic data;
8684
if ((res.headers['content-type'] ?? '').contains('application/json')) {
8785
if (responseType == ResponseType.json) {
8886
data = json.decode(res.body);
@@ -103,7 +101,7 @@ class ClientMixin {
103101

104102
Future<http.Response> toResponse(http.StreamedResponse streamedResponse) async {
105103
if(streamedResponse.statusCode == 204) {
106-
return new http.Response('',
104+
return http.Response('',
107105
streamedResponse.statusCode,
108106
headers: streamedResponse.headers.map((k,v) => k.toLowerCase()=='content-type' ? MapEntry(k, 'text/plain') : MapEntry(k,v)),
109107
request: streamedResponse.request,

templates/flutter/lib/src/cookie_manager.dart.twig

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class CookieManager extends Interceptor {
1919
.then((cookies) {
2020
var cookie = getCookies(cookies);
2121
if (cookie.isNotEmpty) {
22-
request..headers.addAll({HttpHeaders.cookieHeader: cookie});
22+
request.headers.addAll({HttpHeaders.cookieHeader: cookie});
2323
}
2424
return request;
2525
}).catchError((e, stackTrace) {

templates/flutter/lib/src/exception.dart.twig

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ class {{spec.title | caseUcfirst}}Exception implements Exception {
44
final dynamic response;
55

66
{{spec.title | caseUcfirst}}Exception([this.message = "", this.code, this.response]);
7-
7+
8+
@override
89
String toString() {
910
if (message == null) return "{{spec.title | caseUcfirst}}Exception";
1011
return "{{spec.title | caseUcfirst}}Exception: $message (${code ?? 0})";

templates/flutter/lib/src/realtime_base.dart.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ import 'realtime_subscription.dart';
22
import 'realtime.dart';
33

44
abstract class RealtimeBase implements Realtime {
5+
@override
56
RealtimeSubscription subscribe(List<String> channels);
67
}

templates/flutter/lib/src/realtime_browser.dart.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class RealtimeBrowser extends RealtimeBase with RealtimeMixin {
3434
return null;
3535
}
3636

37+
@override
3738
RealtimeSubscription subscribe(List<String> channels) {
3839
return subscribeTo(channels);
3940
}

0 commit comments

Comments
 (0)