Skip to content

Minor cleanup for new and future lints #321

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 1 commit into from
Feb 24, 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
3 changes: 3 additions & 0 deletions analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion lib/async_html.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
6 changes: 3 additions & 3 deletions lib/async_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
2 changes: 1 addition & 1 deletion lib/core.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions lib/src/async/mouse.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<void> 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<void> doubleClick() => _client.send(
_handler.mouse.buildDoubleClickRequest(),
_handler.mouse.parseDoubleClickResponse);
Expand All @@ -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
Expand Down
5 changes: 2 additions & 3 deletions lib/src/async/stepper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<bool> step(String method, String command, Object? params) =>
Future.value(true);
}
6 changes: 3 additions & 3 deletions lib/src/async/web_driver.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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<int> can be very
/// slow.
/// Don't use this method.
/// Prefer [captureScreenshotAsBase64] or [captureScreenshotAsList].
/// Returning the data as `Stream<int>` can be very slow.
@Deprecated('Use captureScreenshotAsBase64 or captureScreenshotAsList!')
Stream<int> captureScreenshot() async* {
yield* Stream.fromIterable(await captureScreenshotAsList());
Expand Down
9 changes: 7 additions & 2 deletions lib/src/common/exception.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ class WebDriverException implements Exception {
const WebDriverException(this.statusCode, this.message);

@override
String toString() =>
'$runtimeType ($statusCode): ${message?.isEmpty ?? true ? '<no message>' : message!}';
String toString() {
final errorMessage = switch (message) {
final message? when message.isNotEmpty => message,
_ => '<no message>',
};
return '$runtimeType ($statusCode): $errorMessage';
}

@override
bool operator ==(Object other) =>
Expand Down
19 changes: 10 additions & 9 deletions lib/src/handler/json_wire/element.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand All @@ -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);
}
2 changes: 1 addition & 1 deletion lib/src/request/async_io_request_client.dart
Original file line number Diff line number Diff line change
@@ -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';

Expand Down
2 changes: 1 addition & 1 deletion lib/src/sync/alert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions lib/support/stdio_stepper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -75,8 +75,8 @@ class StdioStepper implements Stepper {
}
}

/// Converts a Stream<List<int> | int> to Stream<String> that fires an event
/// for every line of data in the original Stream.
/// Converts a `Stream<List<int> | int>` to `Stream<String>` that
/// fires an event for every line of data in the original [Stream].
class LineReader {
static const cr = 13;
static const lf = 10;
Expand All @@ -98,7 +98,7 @@ class LineReader {
onDone: _controller.close, onError: _controller.addError);
}

void _listen(/* List<int> | int */ data) {
void _listen(Object? /* List<int> | int */ data) {
if (data is List<int>) {
data.forEach(_addByte);
} else {
Expand Down
2 changes: 1 addition & 1 deletion lib/sync_io.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/async_alert_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/async_command_event_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/async_cookies_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/async_keyboard_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

@TestOn('vm')
library webdriver.keyboard_test;
library;

import 'dart:io';

Expand Down
2 changes: 1 addition & 1 deletion test/async_logs_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/async_mouse_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

@TestOn('vm')
library webdriver.mouse_test;
library;

import 'dart:async';

Expand Down
2 changes: 1 addition & 1 deletion test/async_navigation_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/async_target_locator_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/async_timeouts_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/async_web_driver_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

@TestOn('vm')
library webdriver.web_driver_test;
library;

import 'dart:async';

Expand Down
2 changes: 1 addition & 1 deletion test/async_web_element_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
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 @@ -13,7 +13,7 @@
// limitations under the License.

@TestOn('vm')
library webdriver.window_test;
library;

import 'dart:async';
import 'dart:math' show Point, Rectangle;
Expand Down
2 changes: 0 additions & 2 deletions test/support/async_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
4 changes: 2 additions & 2 deletions test/support/firefox_profile_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion test/sync/alert.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 0 additions & 2 deletions test/sync/basic_sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
2 changes: 1 addition & 1 deletion test/sync/command_event.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/sync/cookies.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
2 changes: 1 addition & 1 deletion test/sync/keyboard.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
// limitations under the License.

@TestOn('vm')
library webdriver.keyboard_test;
library;

import 'dart:io';

Expand Down
Loading