Skip to content

Commit b0cb6a9

Browse files
authored
Update to Dart/Flutter team lints and fix (#322)
Three bits are a bit too tricky to fix now Removed a lot of dynamic invocations
1 parent d080ebf commit b0cb6a9

25 files changed

+60
-65
lines changed

analysis_options.yaml

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,16 @@
11
# https://dart.dev/guides/language/analysis-options
2-
include: package:lints/recommended.yaml
2+
include: package:dart_flutter_team_lints/analysis_options.yaml
33

44
analyzer:
55
language:
66
strict-casts: true
7+
errors:
8+
avoid_catching_errors: ignore
9+
comment_references: ignore
10+
only_throw_errors: ignore
711

812
linter:
913
rules:
10-
- always_declare_return_types
1114
- avoid_bool_literals_in_conditional_expressions
1215
- avoid_classes_with_only_static_members
1316
- avoid_private_typedef_functions
@@ -16,29 +19,12 @@ linter:
1619
- avoid_unused_constructor_parameters
1720
- avoid_void_async
1821
- cancel_subscriptions
19-
- combinators_ordering
20-
- directives_ordering
21-
- lines_longer_than_80_chars
2222
- literal_only_boolean_expressions
2323
- missing_whitespace_between_adjacent_strings
2424
- no_adjacent_strings_in_list
25-
- omit_local_variable_types
26-
- prefer_asserts_in_initializer_lists
27-
- prefer_const_constructors
2825
- prefer_const_declarations
2926
- prefer_expression_function_bodies
3027
- prefer_final_locals
31-
- prefer_relative_imports
32-
- prefer_single_quotes
33-
- sort_pub_dependencies
34-
- test_types_in_equals
35-
- throw_in_finally
36-
- type_annotate_public_apis
37-
- unawaited_futures
38-
- unnecessary_lambdas
39-
- unnecessary_library_directive
40-
- unnecessary_parenthesis
41-
- unnecessary_statements
4228
- use_if_null_to_convert_nulls_to_bools
4329
- use_raw_strings
4430
- use_string_buffers

lib/src/async/web_driver.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,8 @@ class WebDriver implements SearchContext {
114114
}
115115

116116
/// Search for an element within the entire current page.
117-
/// Throws [NoSuchElementException] if a matching element is not found.
117+
/// Throws [sync_core.NoSuchElementException] if a matching element is not
118+
/// found.
118119
@override
119120
Future<WebElement> findElement(By by) => _client.send(
120121
_handler.elementFinder.buildFindElementRequest(by),

lib/src/common/exception.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ WebDriverException getExceptionFromJsonWireResponse(
189189
{int? httpStatusCode, String? httpReasonPhrase, dynamic jsonResp}) {
190190
if (jsonResp is Map) {
191191
final status = jsonResp['status'] as int?;
192-
final message = jsonResp['value']['message'] as String?;
192+
final message = (jsonResp['value'] as Map)['message'] as String?;
193193

194194
switch (status) {
195195
case 0:
@@ -258,7 +258,7 @@ WebDriverException getExceptionFromW3cResponse({
258258
dynamic jsonResp,
259259
}) {
260260
if (jsonResp is Map && jsonResp.keys.contains('value')) {
261-
final value = jsonResp['value'];
261+
final value = jsonResp['value'] as Map<String, Object?>;
262262

263263
switch (value['error']) {
264264
case 'invalid argument':

lib/src/handler/infer_handler.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,8 @@ class InferSessionHandler extends SessionHandler {
123123
// May be W3C, as it will throw an unknown command exception.
124124
Map<String, dynamic>? body;
125125
try {
126-
body = json.decode(response.body!)['value'] as Map<String, dynamic>?;
126+
body = (json.decode(response.body!) as Map)['value']
127+
as Map<String, dynamic>?;
127128
} catch (e) {
128129
final rawBody =
129130
response.body?.isEmpty ?? true ? '<empty response>' : response.body;

lib/src/handler/json_wire/element_finder.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ class JsonWireElementFinder extends ElementFinder {
1717
@override
1818
List<String> parseFindElementsResponse(WebDriverResponse response) =>
1919
(parseJsonWireResponse(response) as List)
20-
.map((e) => e[jsonWireElementStr])
21-
.toList()
22-
.cast<String>();
20+
.map((e) => (e as Map)[jsonWireElementStr])
21+
.cast<String>()
22+
.toList();
2323

2424
@override
2525
WebDriverRequest buildFindElementRequest(By by, [String? contextId]) {

lib/src/handler/json_wire/mouse.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class JsonWireMouseHandler extends MouseHandler {
5151
0, 'Move to an absolute location is only supported in W3C spec.');
5252
}
5353

54-
final body = {};
54+
final body = <String, Object?>{};
5555
if (elementId != null) {
5656
body['element'] = elementId;
5757
}

lib/src/handler/json_wire/utils.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Object? parseJsonWireResponse(WebDriverResponse response,
2929
statusCode > 299 ||
3030
(responseBody['status'] != null && responseBody['status'] != 0)) {
3131
final status = responseBody['status'] as int?;
32-
final message = responseBody['value']['message'] as String?;
32+
final message = (responseBody['value'] as Map)['message'] as String?;
3333

3434
switch (status) {
3535
case 0:
@@ -108,9 +108,9 @@ Object? deserialize(Object? result, dynamic Function(String) createElement) {
108108
if (result.containsKey(jsonWireElementStr)) {
109109
return createElement(result[jsonWireElementStr] as String);
110110
} else {
111-
final newResult = {};
111+
final newResult = <String, Object?>{};
112112
result.forEach((key, value) {
113-
newResult[key] = deserialize(value, createElement);
113+
newResult[key as String] = deserialize(value, createElement);
114114
});
115115
return newResult;
116116
}

lib/src/handler/json_wire/window.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ class JsonWireWindowHandler extends WindowHandler {
142142
WebDriverRequest.postRequest('execute', {
143143
'script':
144144
'return { width: window.innerWidth, height: window.innerHeight };',
145-
'args': []
145+
'args': <Object>[]
146146
});
147147

148148
@override

lib/src/handler/w3c/element.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class W3cElementHandler extends ElementHandler {
8181
WebDriverRequest.getRequest('${elementPrefix(elementId)}rect');
8282

8383
Rectangle<int> _parseRectResponse(WebDriverResponse response) {
84-
final rect = parseW3cResponse(response);
84+
final rect = parseW3cResponse(response) as Map;
8585
return Rectangle(
8686
(rect['x'] as num).toInt(),
8787
(rect['y'] as num).toInt(),

lib/src/handler/w3c/element_finder.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class W3cElementFinder extends ElementFinder {
4747
@override
4848
List<String> parseFindElementsResponse(WebDriverResponse response) =>
4949
(parseW3cResponse(response) as List)
50-
.map<String>((e) => e[w3cElementStr] as String)
50+
.map<String>((e) => (e as Map)[w3cElementStr] as String)
5151
.toList();
5252

5353
@override
@@ -58,13 +58,13 @@ class W3cElementFinder extends ElementFinder {
5858

5959
@override
6060
String? parseFindActiveElementResponse(WebDriverResponse response) =>
61-
parseW3cResponse(response)[w3cElementStr] as String;
61+
(parseW3cResponse(response) as Map)[w3cElementStr] as String;
6262

6363
@override
6464
WebDriverRequest buildFindActiveElementRequest() =>
6565
WebDriverRequest.getRequest('element/active');
6666

6767
@override
6868
String? parseFindElementResponseCore(WebDriverResponse response) =>
69-
(parseW3cResponse(response) ?? {})[w3cElementStr] as String?;
69+
(parseW3cResponse(response) as Map?)?[w3cElementStr] as String?;
7070
}

lib/src/handler/w3c/session.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class W3cSessionHandler extends SessionHandler {
1616

1717
@override
1818
SessionInfo parseCreateResponse(WebDriverResponse response) {
19-
final session = parseW3cResponse(response);
19+
final session = parseW3cResponse(response) as Map;
2020
return SessionInfo(
2121
session['sessionId'] as String,
2222
WebDriverSpec.W3c,

lib/src/handler/w3c/utils.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,9 @@ Object? deserialize(Object? result, dynamic Function(String) createElement) {
126126
if (result.containsKey(w3cElementStr)) {
127127
return createElement(result[w3cElementStr] as String);
128128
} else {
129-
final newResult = {};
129+
final newResult = <String, Object?>{};
130130
result.forEach((key, value) {
131-
newResult[key] = deserialize(value, createElement);
131+
newResult[key as String] = deserialize(value, createElement);
132132
});
133133
return newResult;
134134
}

lib/src/handler/w3c/window.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ class W3cWindowHandler extends WindowHandler {
6666

6767
@override
6868
Rectangle<int> parseRectResponse(WebDriverResponse response) {
69-
final rect = parseW3cResponse(response);
69+
final rect = parseW3cResponse(response) as Map<String, Object?>;
7070
return Rectangle(
7171
(rect['x'] as num).toInt(),
7272
(rect['y'] as num).toInt(),
@@ -143,12 +143,12 @@ class W3cWindowHandler extends WindowHandler {
143143
WebDriverRequest.postRequest('execute/sync', {
144144
'script':
145145
'return { width: window.innerWidth, height: window.innerHeight };',
146-
'args': []
146+
'args': <Object>[]
147147
});
148148

149149
@override
150150
Rectangle<int> parseInnerSizeResponse(WebDriverResponse response) {
151-
final size = parseW3cResponse(response);
151+
final size = parseW3cResponse(response) as Map<String, Object?>;
152152
return Rectangle(0, 0, size['width'] as int, size['height'] as int);
153153
}
154154
}

lib/src/sync/common.dart

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

1515
import '../../async_core.dart' as async_core;
1616
import '../common/by.dart';
17-
1817
import 'web_driver.dart';
1918
import 'web_element.dart';
2019

@@ -49,6 +48,7 @@ abstract class SearchContext {
4948

5049
/// Searches for an element within the context.
5150
///
52-
/// Throws [NoSuchElementException] if no matching element is found.
51+
/// Throws [async_core.NoSuchElementException] if no matching element is
52+
/// found.
5353
WebElement findElement(By by);
5454
}

lib/src/sync/web_driver.dart

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,9 @@ class WebDriver implements SearchContext {
118118
}
119119

120120
/// Search for an element within the entire current page.
121-
/// Throws [NoSuchElementException] if a matching element is not found.
121+
///
122+
/// Throws [async_core.NoSuchElementException] if a matching element is not
123+
/// found.
122124
@override
123125
WebElement findElement(By by) => WebElement(
124126
this,
@@ -130,7 +132,8 @@ class WebDriver implements SearchContext {
130132
by);
131133

132134
/// Search for an element by xpath within the entire current page.
133-
/// Throws [NoSuchElementException] if a matching element is not found.
135+
/// Throws [async_core.NoSuchElementException] if a matching element is not
136+
/// found.
134137
WebElement findElementByXpath(String by) => findElement(By.xpath(by));
135138

136139
/// An artist's rendition of the current page's source.

lib/src/sync/web_element.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,8 @@ class WebElement extends common.WebElement implements SearchContext {
169169

170170
///Find an element nested within this element.
171171
///
172-
/// Throws [NoSuchElementException] if matching element is not found.
172+
/// Throws [async_core.NoSuchElementException] if matching element is not
173+
/// found.
173174
@override
174175
WebElement findElement(By by) => WebElement(
175176
driver,

lib/support/async.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ class Clock {
7878
}
7979

8080
void _matcherExpect(Object? value, m.Matcher matcher, String? reason) {
81-
final matchState = {};
81+
final matchState = <String, Object?>{};
8282
if (matcher.matches(value, matchState)) {
8383
return;
8484
}

lib/support/firefox_profile.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ class FirefoxProfile {
199199
var canNotParseCaption = true;
200200

201201
for (final line in lines) {
202-
final option = PrefsOption.parse(line);
202+
final option = PrefsOption<Object>.parse(line);
203203
if (option is InvalidOption) {
204204
if (canNotParseCaption) {
205205
print('Can\'t parse lines from file "${file.path}":');

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ dependencies:
1717

1818
dev_dependencies:
1919
archive: ^4.0.2
20-
lints: ^4.0.0
20+
dart_flutter_team_lints: ^3.0.0
2121
test: ^1.24.0

test/async_web_driver_test.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,8 @@ void main() {
137137
const script = '''
138138
arguments[1].textContent = arguments[0];
139139
return arguments[1];''';
140-
final e = await driver.execute(script, ['new text', button]);
140+
final e =
141+
await driver.execute(script, ['new text', button]) as WebElement;
141142
expect(await e.text, 'new text');
142143
});
143144

@@ -146,7 +147,8 @@ void main() {
146147
const script = '''
147148
arguments[1].textContent = arguments[0];
148149
arguments[2](arguments[1]);''';
149-
final e = await driver.executeAsync(script, ['new text', button]);
150+
final e = await driver.executeAsync(script, ['new text', button])
151+
as WebElement;
150152
expect(await e.text, 'new text');
151153
});
152154

test/async_window_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void main() {
3737
const size = Rectangle<int>(0, 0, 600, 400);
3838

3939
// Firefox may take a bit longer to do the resize.
40-
await Future.delayed(const Duration(seconds: 1));
40+
await Future<void>.delayed(const Duration(seconds: 1));
4141
await window.setSize(size);
4242
expect(await window.size, size);
4343
});

test/configs/common_config.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ Map<String, dynamic> getCapabilities(WebDriverSpec spec) {
5454
final capabilities = Capabilities.chrome;
5555
final env = Platform.environment;
5656

57-
final chromeOptions = {};
57+
final chromeOptions = <String, dynamic>{};
5858

5959
if (env['CHROMEDRIVER_BINARY'] != null) {
6060
chromeOptions['binary'] = env['CHROMEDRIVER_BINARY'];

test/support/async_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ void main() {
4242
await lock.acquire();
4343
unawaited(lock.acquire().then((_) => secondLockAcquired = true));
4444
// Make sure that lock is not unacquired just because of timing
45-
await Future.delayed(const Duration(seconds: 1));
45+
await Future<void>.delayed(const Duration(seconds: 1));
4646
expect(secondLockAcquired, isFalse);
4747
lock.release();
4848
// Make sure that enough time has occurred that lock is acquired
49-
await Future.delayed(const Duration(seconds: 1));
49+
await Future<void>.delayed(const Duration(seconds: 1));
5050
expect(secondLockAcquired, isTrue);
5151
});
5252

@@ -149,7 +149,7 @@ void main() {
149149
Object? exception;
150150

151151
try {
152-
await clock.waitFor(() => Future.error('an exception'));
152+
await clock.waitFor(() => Future<void>.error('an exception'));
153153
} catch (e) {
154154
exception = e;
155155
}

0 commit comments

Comments
 (0)