Skip to content

Update to Dart/Flutter team lints and fix #322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Feb 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 5 additions & 19 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
# https://dart.dev/guides/language/analysis-options
include: package:lints/recommended.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
language:
strict-casts: true
errors:
avoid_catching_errors: ignore
comment_references: ignore
only_throw_errors: ignore

linter:
rules:
- always_declare_return_types
- avoid_bool_literals_in_conditional_expressions
- avoid_classes_with_only_static_members
- avoid_private_typedef_functions
Expand All @@ -16,29 +19,12 @@ linter:
- avoid_unused_constructor_parameters
- avoid_void_async
- cancel_subscriptions
- combinators_ordering
- directives_ordering
- lines_longer_than_80_chars
- literal_only_boolean_expressions
- missing_whitespace_between_adjacent_strings
- no_adjacent_strings_in_list
- omit_local_variable_types
- prefer_asserts_in_initializer_lists
- prefer_const_constructors
- prefer_const_declarations
- prefer_expression_function_bodies
- prefer_final_locals
- prefer_relative_imports
- prefer_single_quotes
- sort_pub_dependencies
- test_types_in_equals
- throw_in_finally
- type_annotate_public_apis
- unawaited_futures
- unnecessary_lambdas
- unnecessary_library_directive
- unnecessary_parenthesis
- unnecessary_statements
- use_if_null_to_convert_nulls_to_bools
- use_raw_strings
- use_string_buffers
3 changes: 2 additions & 1 deletion lib/src/async/web_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,8 @@ class WebDriver implements SearchContext {
}

/// Search for an element within the entire current page.
/// Throws [NoSuchElementException] if a matching element is not found.
/// Throws [sync_core.NoSuchElementException] if a matching element is not
/// found.
@override
Future<WebElement> findElement(By by) => _client.send(
_handler.elementFinder.buildFindElementRequest(by),
Expand Down
4 changes: 2 additions & 2 deletions lib/src/common/exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ WebDriverException getExceptionFromJsonWireResponse(
{int? httpStatusCode, String? httpReasonPhrase, dynamic jsonResp}) {
if (jsonResp is Map) {
final status = jsonResp['status'] as int?;
final message = jsonResp['value']['message'] as String?;
final message = (jsonResp['value'] as Map)['message'] as String?;

switch (status) {
case 0:
Expand Down Expand Up @@ -258,7 +258,7 @@ WebDriverException getExceptionFromW3cResponse({
dynamic jsonResp,
}) {
if (jsonResp is Map && jsonResp.keys.contains('value')) {
final value = jsonResp['value'];
final value = jsonResp['value'] as Map<String, Object?>;

switch (value['error']) {
case 'invalid argument':
Expand Down
3 changes: 2 additions & 1 deletion lib/src/handler/infer_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ class InferSessionHandler extends SessionHandler {
// May be W3C, as it will throw an unknown command exception.
Map<String, dynamic>? body;
try {
body = json.decode(response.body!)['value'] as Map<String, dynamic>?;
body = (json.decode(response.body!) as Map)['value']
as Map<String, dynamic>?;
} catch (e) {
final rawBody =
response.body?.isEmpty ?? true ? '<empty response>' : response.body;
Expand Down
6 changes: 3 additions & 3 deletions lib/src/handler/json_wire/element_finder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ class JsonWireElementFinder extends ElementFinder {
@override
List<String> parseFindElementsResponse(WebDriverResponse response) =>
(parseJsonWireResponse(response) as List)
.map((e) => e[jsonWireElementStr])
.toList()
.cast<String>();
.map((e) => (e as Map)[jsonWireElementStr])
.cast<String>()
.toList();

@override
WebDriverRequest buildFindElementRequest(By by, [String? contextId]) {
Expand Down
2 changes: 1 addition & 1 deletion lib/src/handler/json_wire/mouse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class JsonWireMouseHandler extends MouseHandler {
0, 'Move to an absolute location is only supported in W3C spec.');
}

final body = {};
final body = <String, Object?>{};
if (elementId != null) {
body['element'] = elementId;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/handler/json_wire/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Object? parseJsonWireResponse(WebDriverResponse response,
statusCode > 299 ||
(responseBody['status'] != null && responseBody['status'] != 0)) {
final status = responseBody['status'] as int?;
final message = responseBody['value']['message'] as String?;
final message = (responseBody['value'] as Map)['message'] as String?;

switch (status) {
case 0:
Expand Down Expand Up @@ -108,9 +108,9 @@ Object? deserialize(Object? result, dynamic Function(String) createElement) {
if (result.containsKey(jsonWireElementStr)) {
return createElement(result[jsonWireElementStr] as String);
} else {
final newResult = {};
final newResult = <String, Object?>{};
result.forEach((key, value) {
newResult[key] = deserialize(value, createElement);
newResult[key as String] = deserialize(value, createElement);
});
return newResult;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/handler/json_wire/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ class JsonWireWindowHandler extends WindowHandler {
WebDriverRequest.postRequest('execute', {
'script':
'return { width: window.innerWidth, height: window.innerHeight };',
'args': []
'args': <Object>[]
});

@override
Expand Down
2 changes: 1 addition & 1 deletion lib/src/handler/w3c/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ class W3cElementHandler extends ElementHandler {
WebDriverRequest.getRequest('${elementPrefix(elementId)}rect');

Rectangle<int> _parseRectResponse(WebDriverResponse response) {
final rect = parseW3cResponse(response);
final rect = parseW3cResponse(response) as Map;
return Rectangle(
(rect['x'] as num).toInt(),
(rect['y'] as num).toInt(),
Expand Down
6 changes: 3 additions & 3 deletions lib/src/handler/w3c/element_finder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class W3cElementFinder extends ElementFinder {
@override
List<String> parseFindElementsResponse(WebDriverResponse response) =>
(parseW3cResponse(response) as List)
.map<String>((e) => e[w3cElementStr] as String)
.map<String>((e) => (e as Map)[w3cElementStr] as String)
.toList();

@override
Expand All @@ -58,13 +58,13 @@ class W3cElementFinder extends ElementFinder {

@override
String? parseFindActiveElementResponse(WebDriverResponse response) =>
parseW3cResponse(response)[w3cElementStr] as String;
(parseW3cResponse(response) as Map)[w3cElementStr] as String;

@override
WebDriverRequest buildFindActiveElementRequest() =>
WebDriverRequest.getRequest('element/active');

@override
String? parseFindElementResponseCore(WebDriverResponse response) =>
(parseW3cResponse(response) ?? {})[w3cElementStr] as String?;
(parseW3cResponse(response) as Map?)?[w3cElementStr] as String?;
}
2 changes: 1 addition & 1 deletion lib/src/handler/w3c/session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class W3cSessionHandler extends SessionHandler {

@override
SessionInfo parseCreateResponse(WebDriverResponse response) {
final session = parseW3cResponse(response);
final session = parseW3cResponse(response) as Map;
return SessionInfo(
session['sessionId'] as String,
WebDriverSpec.W3c,
Expand Down
4 changes: 2 additions & 2 deletions lib/src/handler/w3c/utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,9 @@ Object? deserialize(Object? result, dynamic Function(String) createElement) {
if (result.containsKey(w3cElementStr)) {
return createElement(result[w3cElementStr] as String);
} else {
final newResult = {};
final newResult = <String, Object?>{};
result.forEach((key, value) {
newResult[key] = deserialize(value, createElement);
newResult[key as String] = deserialize(value, createElement);
});
return newResult;
}
Expand Down
6 changes: 3 additions & 3 deletions lib/src/handler/w3c/window.dart
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class W3cWindowHandler extends WindowHandler {

@override
Rectangle<int> parseRectResponse(WebDriverResponse response) {
final rect = parseW3cResponse(response);
final rect = parseW3cResponse(response) as Map<String, Object?>;
return Rectangle(
(rect['x'] as num).toInt(),
(rect['y'] as num).toInt(),
Expand Down Expand Up @@ -143,12 +143,12 @@ class W3cWindowHandler extends WindowHandler {
WebDriverRequest.postRequest('execute/sync', {
'script':
'return { width: window.innerWidth, height: window.innerHeight };',
'args': []
'args': <Object>[]
});

@override
Rectangle<int> parseInnerSizeResponse(WebDriverResponse response) {
final size = parseW3cResponse(response);
final size = parseW3cResponse(response) as Map<String, Object?>;
return Rectangle(0, 0, size['width'] as int, size['height'] as int);
}
}
4 changes: 2 additions & 2 deletions lib/src/sync/common.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

import '../../async_core.dart' as async_core;
import '../common/by.dart';

import 'web_driver.dart';
import 'web_element.dart';

Expand Down Expand Up @@ -49,6 +48,7 @@ abstract class SearchContext {

/// Searches for an element within the context.
///
/// Throws [NoSuchElementException] if no matching element is found.
/// Throws [async_core.NoSuchElementException] if no matching element is
/// found.
WebElement findElement(By by);
}
7 changes: 5 additions & 2 deletions lib/src/sync/web_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,9 @@ class WebDriver implements SearchContext {
}

/// Search for an element within the entire current page.
/// Throws [NoSuchElementException] if a matching element is not found.
///
/// Throws [async_core.NoSuchElementException] if a matching element is not
/// found.
@override
WebElement findElement(By by) => WebElement(
this,
Expand All @@ -129,7 +131,8 @@ class WebDriver implements SearchContext {
by);

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

/// An artist's rendition of the current page's source.
Expand Down
3 changes: 2 additions & 1 deletion lib/src/sync/web_element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,8 @@ class WebElement extends common.WebElement implements SearchContext {

///Find an element nested within this element.
///
/// Throws [NoSuchElementException] if matching element is not found.
/// Throws [async_core.NoSuchElementException] if matching element is not
/// found.
@override
WebElement findElement(By by) => WebElement(
driver,
Expand Down
2 changes: 1 addition & 1 deletion lib/support/async.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ class Clock {
}

void _matcherExpect(Object? value, m.Matcher matcher, String? reason) {
final matchState = {};
final matchState = <String, Object?>{};
if (matcher.matches(value, matchState)) {
return;
}
Expand Down
2 changes: 1 addition & 1 deletion lib/support/firefox_profile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class FirefoxProfile {
var canNotParseCaption = true;

for (final line in lines) {
final option = PrefsOption.parse(line);
final option = PrefsOption<Object>.parse(line);
if (option is InvalidOption) {
if (canNotParseCaption) {
print('Can\'t parse lines from file "${file.path}":');
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ dependencies:

dev_dependencies:
archive: ^4.0.2
lints: ^4.0.0
dart_flutter_team_lints: ^3.0.0
test: ^1.24.0
6 changes: 4 additions & 2 deletions test/async_web_driver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,8 @@ void main() {
const script = '''
arguments[1].textContent = arguments[0];
return arguments[1];''';
final e = await driver.execute(script, ['new text', button]);
final e =
await driver.execute(script, ['new text', button]) as WebElement;
expect(await e.text, 'new text');
});

Expand All @@ -146,7 +147,8 @@ void main() {
const script = '''
arguments[1].textContent = arguments[0];
arguments[2](arguments[1]);''';
final e = await driver.executeAsync(script, ['new text', button]);
final e = await driver.executeAsync(script, ['new text', button])
as WebElement;
expect(await e.text, 'new text');
});

Expand Down
2 changes: 1 addition & 1 deletion test/async_window_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void main() {
const size = Rectangle<int>(0, 0, 600, 400);

// Firefox may take a bit longer to do the resize.
await Future.delayed(const Duration(seconds: 1));
await Future<void>.delayed(const Duration(seconds: 1));
await window.setSize(size);
expect(await window.size, size);
});
Expand Down
2 changes: 1 addition & 1 deletion test/configs/common_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Map<String, dynamic> getCapabilities(WebDriverSpec spec) {
final capabilities = Capabilities.chrome;
final env = Platform.environment;

final chromeOptions = {};
final chromeOptions = <String, dynamic>{};

if (env['CHROMEDRIVER_BINARY'] != null) {
chromeOptions['binary'] = env['CHROMEDRIVER_BINARY'];
Expand Down
6 changes: 3 additions & 3 deletions test/support/async_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ void main() {
await lock.acquire();
unawaited(lock.acquire().then((_) => secondLockAcquired = true));
// Make sure that lock is not unacquired just because of timing
await Future.delayed(const Duration(seconds: 1));
await Future<void>.delayed(const Duration(seconds: 1));
expect(secondLockAcquired, isFalse);
lock.release();
// Make sure that enough time has occurred that lock is acquired
await Future.delayed(const Duration(seconds: 1));
await Future<void>.delayed(const Duration(seconds: 1));
expect(secondLockAcquired, isTrue);
});

Expand Down Expand Up @@ -149,7 +149,7 @@ void main() {
Object? exception;

try {
await clock.waitFor(() => Future.error('an exception'));
await clock.waitFor(() => Future<void>.error('an exception'));
} catch (e) {
exception = e;
}
Expand Down
Loading