From 21edf22394fe8dd75c815e2946d717e276a550a1 Mon Sep 17 00:00:00 2001 From: Parker Lougheed Date: Sat, 22 Feb 2025 15:32:51 -0600 Subject: [PATCH] Minor cleanup for new and future lints --- analysis_options.yaml | 3 +++ lib/async_html.dart | 2 +- lib/async_io.dart | 6 +++--- lib/core.dart | 2 +- lib/io.dart | 2 +- lib/src/async/mouse.dart | 8 ++++---- lib/src/async/stepper.dart | 5 ++--- lib/src/async/web_driver.dart | 6 +++--- lib/src/common/exception.dart | 9 +++++++-- lib/src/handler/json_wire/element.dart | 19 ++++++++++--------- lib/src/request/async_io_request_client.dart | 2 +- lib/src/sync/alert.dart | 2 +- lib/support/stdio_stepper.dart | 8 ++++---- lib/sync_io.dart | 2 +- test/async_alert_test.dart | 2 +- test/async_command_event_test.dart | 2 +- test/async_cookies_test.dart | 2 +- test/async_keyboard_test.dart | 2 +- test/async_logs_test.dart | 2 +- test/async_mouse_test.dart | 2 +- test/async_navigation_test.dart | 2 +- test/async_target_locator_test.dart | 2 +- test/async_timeouts_test.dart | 2 +- test/async_web_driver_test.dart | 2 +- test/async_web_element_test.dart | 2 +- test/async_window_test.dart | 2 +- test/support/async_test.dart | 2 -- test/support/firefox_profile_test.dart | 4 ++-- test/sync/alert.dart | 2 +- test/sync/basic_sync.dart | 2 -- test/sync/command_event.dart | 2 +- test/sync/cookies.dart | 2 +- test/sync/keyboard.dart | 2 +- test/sync/logs.dart | 2 +- test/sync/mouse.dart | 2 +- test/sync/navigation.dart | 2 +- test/sync/spec_inference_test.dart | 2 +- test/sync/sync_async_interop.dart | 2 -- test/sync/target_locator.dart | 2 +- test/sync/timeouts.dart | 2 +- test/sync/web_driver.dart | 2 +- test/sync/web_element.dart | 2 +- test/sync/window.dart | 2 +- 43 files changed, 69 insertions(+), 67 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index ca4c645..f5964c4 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -16,7 +16,9 @@ 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 @@ -34,6 +36,7 @@ linter: - type_annotate_public_apis - unawaited_futures - unnecessary_lambdas + - unnecessary_library_directive - unnecessary_parenthesis - unnecessary_statements - use_if_null_to_convert_nulls_to_bools diff --git a/lib/async_html.dart b/lib/async_html.dart index e774b10..3ef50ee 100644 --- a/lib/async_html.dart +++ b/lib/async_html.dart @@ -15,7 +15,7 @@ import 'dart:async' show Future; import 'async_core.dart' as core - show createDriver, fromExistingSession, fromExistingSessionSync, WebDriver; + show WebDriver, createDriver, fromExistingSession, fromExistingSessionSync; import 'src/common/spec.dart'; import 'src/request/async_xhr_request_client.dart'; diff --git a/lib/async_io.dart b/lib/async_io.dart index f3b0993..a7c1141 100644 --- a/lib/async_io.dart +++ b/lib/async_io.dart @@ -16,11 +16,11 @@ import 'dart:async' show Future; import 'async_core.dart' as core show + WebDriver, + WebDriverSpec, createDriver, fromExistingSession, - fromExistingSessionSync, - WebDriver, - WebDriverSpec; + fromExistingSessionSync; import 'src/request/async_io_request_client.dart'; export 'package:webdriver/async_core.dart' diff --git a/lib/core.dart b/lib/core.dart index 4c7ce75..3e17f06 100644 --- a/lib/core.dart +++ b/lib/core.dart @@ -13,7 +13,7 @@ // limitations under the License. @Deprecated("Use 'package:webdriver/async_core.dart' instead.") -library core; +library; /// Consider this file as deprecated. This exists as an alias to async_core.dart /// for backward compatibility. diff --git a/lib/io.dart b/lib/io.dart index 79805d7..ff68583 100644 --- a/lib/io.dart +++ b/lib/io.dart @@ -13,7 +13,7 @@ // limitations under the License. @Deprecated("Use 'package:webdriver/async_io.dart' instead.") -library io; +library; /// Consider this file as deprecated. This exists as an alias to async_io.dart /// for backward compatibility. diff --git a/lib/src/async/mouse.dart b/lib/src/async/mouse.dart index 52f7b21..63d3302 100644 --- a/lib/src/async/mouse.dart +++ b/lib/src/async/mouse.dart @@ -38,11 +38,11 @@ class Mouse { _handler.mouse.buildDownRequest(button), _handler.mouse.parseDownResponse); - /// Releases the mouse button previously held (where the mouse is currently at). + /// Releases the mouse button previously held (where the mouse is currently). Future up([MouseButton button = MouseButton.primary]) => _client.send( _handler.mouse.buildUpRequest(button), _handler.mouse.parseUpResponse); - /// Double-clicks at the current mouse coordinates (set by moveTo). + /// Double-clicks at the current mouse coordinates (set by [moveTo]). Future doubleClick() => _client.send( _handler.mouse.buildDoubleClickRequest(), _handler.mouse.parseDoubleClickResponse); @@ -52,8 +52,8 @@ class Mouse { /// If [element] is specified and [xOffset] and [yOffset] are not, will move /// the mouse to the center of the [element]. /// - /// If [xOffset] and [yOffset] are specified, will move the mouse that distance - /// from its current location. + /// If [xOffset] and [yOffset] are specified, will move the mouse + /// that distance from its current location. /// /// If all three are specified, the behavior will be different /// for W3C and JsonWire. For W3C, it will use [element] center as the diff --git a/lib/src/async/stepper.dart b/lib/src/async/stepper.dart index 0db19ab..a52fca4 100644 --- a/lib/src/async/stepper.dart +++ b/lib/src/async/stepper.dart @@ -12,14 +12,13 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.stepper; - import 'dart:async'; class Stepper { const Stepper(); - /// returns true if command should be executed, false if should not be executed. + /// Returns `true` if [command] should be executed, + /// `false` if it should not be executed. Future step(String method, String command, Object? params) => Future.value(true); } diff --git a/lib/src/async/web_driver.dart b/lib/src/async/web_driver.dart index 21480d0..d71cfb6 100644 --- a/lib/src/async/web_driver.dart +++ b/lib/src/async/web_driver.dart @@ -216,9 +216,9 @@ class WebDriver implements SearchContext { /// Take a screenshot of the current page as PNG as stream of uint8. /// - /// Don't use this method. Prefer [captureScreenshotAsBase64] or - /// [captureScreenshotAsList]. Returning the data as Stream can be very - /// slow. + /// Don't use this method. + /// Prefer [captureScreenshotAsBase64] or [captureScreenshotAsList]. + /// Returning the data as `Stream` can be very slow. @Deprecated('Use captureScreenshotAsBase64 or captureScreenshotAsList!') Stream captureScreenshot() async* { yield* Stream.fromIterable(await captureScreenshotAsList()); diff --git a/lib/src/common/exception.dart b/lib/src/common/exception.dart index 83063f3..fa5ec94 100644 --- a/lib/src/common/exception.dart +++ b/lib/src/common/exception.dart @@ -10,8 +10,13 @@ class WebDriverException implements Exception { const WebDriverException(this.statusCode, this.message); @override - String toString() => - '$runtimeType ($statusCode): ${message?.isEmpty ?? true ? '' : message!}'; + String toString() { + final errorMessage = switch (message) { + final message? when message.isNotEmpty => message, + _ => '', + }; + return '$runtimeType ($statusCode): $errorMessage'; + } @override bool operator ==(Object other) => diff --git a/lib/src/handler/json_wire/element.dart b/lib/src/handler/json_wire/element.dart index b8defa5..79f39e3 100644 --- a/lib/src/handler/json_wire/element.dart +++ b/lib/src/handler/json_wire/element.dart @@ -131,14 +131,15 @@ class JsonWireElementHandler extends ElementHandler { parseJsonWireResponse(response)?.toString(); @override - WebDriverRequest buildCssPropertyRequest(String elementId, String name) => - WebDriverRequest.postRequest('execute', { - 'script': - 'return window.getComputedStyle(arguments[0]).${_cssPropName(name)};', - 'args': [ - {jsonWireElementStr: elementId} - ] - }); + WebDriverRequest buildCssPropertyRequest(String elementId, String name) { + final cssProperty = _cssPropName(name); + return WebDriverRequest.postRequest('execute', { + 'script': 'return window.getComputedStyle(arguments[0]).$cssProperty;', + 'args': [ + {jsonWireElementStr: elementId} + ] + }); + } @override String? parseCssPropertyResponse(WebDriverResponse response) => @@ -158,6 +159,6 @@ class JsonWireElementHandler extends ElementHandler { parseJsonWireResponse(response)?.toString(); /// Convert hyphenated-properties to camelCase. - String _cssPropName(String name) => name.splitMapJoin(RegExp(r'-(\w)'), + static String _cssPropName(String name) => name.splitMapJoin(RegExp(r'-(\w)'), onMatch: (m) => m.group(1)!.toUpperCase(), onNonMatch: (m) => m); } diff --git a/lib/src/request/async_io_request_client.dart b/lib/src/request/async_io_request_client.dart index 18888c0..ae5971e 100644 --- a/lib/src/request/async_io_request_client.dart +++ b/lib/src/request/async_io_request_client.dart @@ -1,6 +1,6 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:io' show ContentType, HttpClient, HttpHeaders, HttpClientRequest; +import 'dart:io' show ContentType, HttpClient, HttpClientRequest, HttpHeaders; import '../../support/async.dart'; diff --git a/lib/src/sync/alert.dart b/lib/src/sync/alert.dart index 7650848..1c90da3 100644 --- a/lib/src/sync/alert.dart +++ b/lib/src/sync/alert.dart @@ -38,7 +38,7 @@ class Alert { /// Dismisses the currently displayed alert (may not be the alert for which /// this object was created). /// - /// Throws [NoSuchAlertException] if there isn't currently an alert. + /// Throws [NoSuchAlertException] if there isn't currently an alert. void dismiss() { _client.send(_handler.alert.buildDismissRequest(), _handler.alert.parseDismissResponse); diff --git a/lib/support/stdio_stepper.dart b/lib/support/stdio_stepper.dart index 3758fe2..fef29f3 100644 --- a/lib/support/stdio_stepper.dart +++ b/lib/support/stdio_stepper.dart @@ -14,7 +14,7 @@ import 'dart:async' show StreamController; import 'dart:convert' show Encoding, json; -import 'dart:io' show exit, Stdin, stdin, systemEncoding; +import 'dart:io' show Stdin, exit, stdin, systemEncoding; import '../src/async/stepper.dart'; @@ -75,8 +75,8 @@ class StdioStepper implements Stepper { } } -/// Converts a Stream | int> to Stream that fires an event -/// for every line of data in the original Stream. +/// Converts a `Stream | int>` to `Stream` that +/// fires an event for every line of data in the original [Stream]. class LineReader { static const cr = 13; static const lf = 10; @@ -98,7 +98,7 @@ class LineReader { onDone: _controller.close, onError: _controller.addError); } - void _listen(/* List | int */ data) { + void _listen(Object? /* List | int */ data) { if (data is List) { data.forEach(_addByte); } else { diff --git a/lib/sync_io.dart b/lib/sync_io.dart index 797dc2a..eab6973 100644 --- a/lib/sync_io.dart +++ b/lib/sync_io.dart @@ -14,7 +14,7 @@ import 'src/request/sync_http_request_client.dart'; import 'sync_core.dart' as core - show createDriver, fromExistingSession, WebDriver, WebDriverSpec; + show WebDriver, WebDriverSpec, createDriver, fromExistingSession; export 'package:webdriver/sync_core.dart' hide createDriver, fromExistingSession; diff --git a/test/async_alert_test.dart b/test/async_alert_test.dart index cd26540..e3de091 100644 --- a/test/async_alert_test.dart +++ b/test/async_alert_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.alert_test; +library; import 'package:test/test.dart'; import 'package:webdriver/async_core.dart'; diff --git a/test/async_command_event_test.dart b/test/async_command_event_test.dart index f518ca6..3afa437 100644 --- a/test/async_command_event_test.dart +++ b/test/async_command_event_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.command_event_test; +library; import 'package:stack_trace/stack_trace.dart'; import 'package:test/test.dart'; diff --git a/test/async_cookies_test.dart b/test/async_cookies_test.dart index 02fe5cf..00df068 100644 --- a/test/async_cookies_test.dart +++ b/test/async_cookies_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.options_test; +library; import 'package:test/test.dart'; import 'package:webdriver/async_core.dart'; diff --git a/test/async_keyboard_test.dart b/test/async_keyboard_test.dart index 130ff74..b8c15fc 100644 --- a/test/async_keyboard_test.dart +++ b/test/async_keyboard_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.keyboard_test; +library; import 'dart:io'; diff --git a/test/async_logs_test.dart b/test/async_logs_test.dart index 3cce53d..758d3a1 100644 --- a/test/async_logs_test.dart +++ b/test/async_logs_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.logs_test; +library; import 'package:test/test.dart'; import 'package:webdriver/async_core.dart'; diff --git a/test/async_mouse_test.dart b/test/async_mouse_test.dart index 05f006d..f2e2d7b 100644 --- a/test/async_mouse_test.dart +++ b/test/async_mouse_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.mouse_test; +library; import 'dart:async'; diff --git a/test/async_navigation_test.dart b/test/async_navigation_test.dart index 31e8a38..ab210a1 100644 --- a/test/async_navigation_test.dart +++ b/test/async_navigation_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.navigation_test; +library; import 'package:test/test.dart'; import 'package:webdriver/async_core.dart'; diff --git a/test/async_target_locator_test.dart b/test/async_target_locator_test.dart index 92ee3e9..3d5e0bc 100644 --- a/test/async_target_locator_test.dart +++ b/test/async_target_locator_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.target_locator_test; +library; import 'package:test/test.dart'; import 'package:webdriver/async_core.dart'; diff --git a/test/async_timeouts_test.dart b/test/async_timeouts_test.dart index 0e67873..2e5db60 100644 --- a/test/async_timeouts_test.dart +++ b/test/async_timeouts_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.options_test; +library; import 'package:test/test.dart'; import 'package:webdriver/async_core.dart'; diff --git a/test/async_web_driver_test.dart b/test/async_web_driver_test.dart index 59dfb99..f5cfed2 100644 --- a/test/async_web_driver_test.dart +++ b/test/async_web_driver_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.web_driver_test; +library; import 'dart:async'; diff --git a/test/async_web_element_test.dart b/test/async_web_element_test.dart index c0a2b39..d7c3cec 100644 --- a/test/async_web_element_test.dart +++ b/test/async_web_element_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.web_element_test; +library; import 'package:test/test.dart'; import 'package:webdriver/async_core.dart'; diff --git a/test/async_window_test.dart b/test/async_window_test.dart index 6ea476e..44a963b 100644 --- a/test/async_window_test.dart +++ b/test/async_window_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.window_test; +library; import 'dart:async'; import 'dart:math' show Point, Rectangle; diff --git a/test/support/async_test.dart b/test/support/async_test.dart index f065de1..b9ae529 100644 --- a/test/support/async_test.dart +++ b/test/support/async_test.dart @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.support.async_test; - import 'dart:async' show Future, unawaited; import 'package:test/test.dart'; diff --git a/test/support/firefox_profile_test.dart b/test/support/firefox_profile_test.dart index 9af3922..113ef1c 100644 --- a/test/support/firefox_profile_test.dart +++ b/test/support/firefox_profile_test.dart @@ -14,9 +14,9 @@ @Tags(['ff']) @TestOn('vm') -library webdriver.support.firefox_profile_test; +library; -import 'dart:convert' show base64, Encoding, utf8; +import 'dart:convert' show Encoding, base64, utf8; import 'dart:io' as io; import 'package:archive/archive_io.dart' as archive; diff --git a/test/sync/alert.dart b/test/sync/alert.dart index ce584f6..75af5f6 100644 --- a/test/sync/alert.dart +++ b/test/sync/alert.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.alert_test; +library; import 'package:test/test.dart'; import 'package:webdriver/sync_core.dart'; diff --git a/test/sync/basic_sync.dart b/test/sync/basic_sync.dart index 394377a..1a9c288 100644 --- a/test/sync/basic_sync.dart +++ b/test/sync/basic_sync.dart @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.support.async_test; - import 'package:test/test.dart'; import 'package:webdriver/sync_io.dart'; diff --git a/test/sync/command_event.dart b/test/sync/command_event.dart index 1f7b25a..741f163 100644 --- a/test/sync/command_event.dart +++ b/test/sync/command_event.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.command_event_test; +library; import 'package:stack_trace/stack_trace.dart'; import 'package:test/test.dart'; diff --git a/test/sync/cookies.dart b/test/sync/cookies.dart index fda6d8e..36c4991 100644 --- a/test/sync/cookies.dart +++ b/test/sync/cookies.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.options_test; +library; import 'package:test/test.dart'; import 'package:webdriver/sync_core.dart'; diff --git a/test/sync/keyboard.dart b/test/sync/keyboard.dart index 0a4b299..b23ae76 100644 --- a/test/sync/keyboard.dart +++ b/test/sync/keyboard.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.keyboard_test; +library; import 'dart:io'; diff --git a/test/sync/logs.dart b/test/sync/logs.dart index 339f405..c4d5690 100644 --- a/test/sync/logs.dart +++ b/test/sync/logs.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.logs_test; +library; import 'package:test/test.dart'; import 'package:webdriver/sync_core.dart'; diff --git a/test/sync/mouse.dart b/test/sync/mouse.dart index ada7453..795276f 100644 --- a/test/sync/mouse.dart +++ b/test/sync/mouse.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.mouse_test; +library; import 'package:test/test.dart'; import 'package:webdriver/sync_core.dart'; diff --git a/test/sync/navigation.dart b/test/sync/navigation.dart index a2794f4..771226d 100644 --- a/test/sync/navigation.dart +++ b/test/sync/navigation.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.navigation_test; +library; import 'package:test/test.dart'; import 'package:webdriver/sync_core.dart'; diff --git a/test/sync/spec_inference_test.dart b/test/sync/spec_inference_test.dart index 0a841d4..8fe8bc7 100644 --- a/test/sync/spec_inference_test.dart +++ b/test/sync/spec_inference_test.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.spec_inference_test; +library; import 'package:test/test.dart'; import 'package:webdriver/sync_core.dart'; diff --git a/test/sync/sync_async_interop.dart b/test/sync/sync_async_interop.dart index d611785..6cdbfc4 100644 --- a/test/sync/sync_async_interop.dart +++ b/test/sync/sync_async_interop.dart @@ -12,8 +12,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -library webdriver.support.async_test; - import 'package:test/test.dart'; import 'package:webdriver/async_core.dart' as async_core; import 'package:webdriver/sync_io.dart'; diff --git a/test/sync/target_locator.dart b/test/sync/target_locator.dart index b28299b..00b39ad 100644 --- a/test/sync/target_locator.dart +++ b/test/sync/target_locator.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.target_locator_test; +library; import 'package:test/test.dart'; import 'package:webdriver/sync_core.dart'; diff --git a/test/sync/timeouts.dart b/test/sync/timeouts.dart index 4ae1306..5e1af45 100644 --- a/test/sync/timeouts.dart +++ b/test/sync/timeouts.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.options_test; +library; import 'package:test/test.dart'; import 'package:webdriver/sync_core.dart'; diff --git a/test/sync/web_driver.dart b/test/sync/web_driver.dart index a3ef74b..77d04d0 100644 --- a/test/sync/web_driver.dart +++ b/test/sync/web_driver.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.web_driver_test; +library; import 'dart:io'; diff --git a/test/sync/web_element.dart b/test/sync/web_element.dart index d1ff061..0243840 100644 --- a/test/sync/web_element.dart +++ b/test/sync/web_element.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.web_element_test; +library; import 'package:test/test.dart'; import 'package:webdriver/sync_core.dart'; diff --git a/test/sync/window.dart b/test/sync/window.dart index 830613e..fc329f1 100644 --- a/test/sync/window.dart +++ b/test/sync/window.dart @@ -13,7 +13,7 @@ // limitations under the License. @TestOn('vm') -library webdriver.window_test; +library; import 'dart:io'; import 'dart:math' show Rectangle;