Skip to content
Open
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
15 changes: 3 additions & 12 deletions _analysis_config/lib/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

include: package:lints/recommended.yaml
include: package:dart_flutter_team_lints/analysis_options.yaml

analyzer:
# language:
# strict-casts: true
language:
strict-casts: true
errors:
dead_code: error
unused_element: error
Expand All @@ -15,27 +15,18 @@ analyzer:

linter:
rules:
- always_declare_return_types
- avoid_classes_with_only_static_members
- avoid_returning_this
- avoid_unused_constructor_parameters
- avoid_void_async
- cancel_subscriptions
- directives_ordering
- join_return_with_assignment
- library_names
- literal_only_boolean_expressions
- omit_local_variable_types
- only_throw_errors
- package_prefixed_library_names
- prefer_final_in_for_each
- prefer_final_locals
- prefer_single_quotes
# - prefer_relative_imports
- prefer_void_to_null
- test_types_in_equals
- throw_in_finally
- unawaited_futures
- unnecessary_lambdas
- unnecessary_parenthesis
- unnecessary_statements
Expand Down
2 changes: 1 addition & 1 deletion _analysis_config/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,4 @@ environment:
sdk: ^3.10.0-0.0.dev

dependencies:
lints: ^5.0.0
dart_flutter_team_lints: ^3.5.2
4 changes: 0 additions & 4 deletions dwds/analysis_options.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,3 @@ analyzer:
- "lib/data/*"
# Ignore debug extension builds
- "debug_extension/compiled/*"

linter:
rules:
- always_use_package_imports
4 changes: 2 additions & 2 deletions dwds/debug_extension/web/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,12 @@ void _registerListeners() {
}

Future<void> _handleRuntimeMessages(
dynamic jsRequest,
Object? jsRequest,
MessageSender sender,
Function sendResponse,
) async {
if (jsRequest is! String) return;

if (sendResponse is! void Function(Object?)) return;
interceptMessage<String>(
message: jsRequest,
expectedType: MessageType.isAuthenticated,
Expand Down
19 changes: 11 additions & 8 deletions dwds/debug_extension/web/chrome_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ class Port {
@JS()
@anonymous
class OnPortMessageHandler {
external void addListener(void Function(dynamic, Port) callback);
external void addListener(void Function(Object?, Port) callback);
}

@JS()
Expand All @@ -246,7 +246,7 @@ class ConnectionHandler {
@anonymous
class OnMessageHandler {
external void addListener(
dynamic Function(dynamic, MessageSender, Function) callback,
Object? Function(Object?, MessageSender, Function) callback,
);
}

Expand Down Expand Up @@ -307,16 +307,16 @@ class OnChangedHandler {
@JS()
@anonymous
class Tabs {
external dynamic query(
external Object? query(
QueryInfo queryInfo,
void Function(List<Tab>) callback,
);

external dynamic create(TabInfo tabInfo, void Function(Tab) callback);
external Object? create(TabInfo tabInfo, void Function(Tab) callback);

external dynamic get(int tabId, void Function(Tab?) callback);
external Object? get(int tabId, void Function(Tab?) callback);

external dynamic remove(int tabId, void Function()? callback);
external Object? remove(int tabId, void Function()? callback);

external Object sendMessage(
int tabId,
Expand All @@ -339,7 +339,7 @@ class OnActivatedHandler {
@JS()
@anonymous
class OnRemovedHandler {
external void addListener(void Function(int tabId, dynamic info) callback);
external void addListener(void Function(int tabId, Object? info) callback);
}

@JS()
Expand Down Expand Up @@ -403,7 +403,10 @@ class NavigationInfo {
@JS()
@anonymous
class Windows {
external dynamic create(WindowInfo? createData, Function(WindowObj) callback);
external Object? create(
WindowInfo? createData,
void Function(WindowObj) callback,
);

external OnFocusChangedHandler get onFocusChanged;
}
Expand Down
10 changes: 5 additions & 5 deletions dwds/debug_extension/web/cider_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -96,12 +96,12 @@ void sendErrorMessageToCider({

void _sendMessageToCider(String json) {
final message = {'key': _ciderDartMessageKey, 'json': json};
_ciderPort!.postMessage(jsify(message));
_ciderPort!.postMessage(jsify(message) as Object);
}

Future<void> _handleMessageFromCider(dynamic message, Port _) async {
final key = getProperty(message, 'key');
final json = getProperty(message, 'json');
Future<void> _handleMessageFromCider(Object? message, Port _) async {
final key = getProperty<String>(message!, 'key');
final json = getProperty<Object?>(message, 'json');
if (key != _ciderDartMessageKey || json is! String) {
sendErrorMessageToCider(
errorType: CiderErrorType.invalidRequest,
Expand All @@ -110,7 +110,7 @@ Future<void> _handleMessageFromCider(dynamic message, Port _) async {
return;
}

final decoded = jsonDecode(json) as Map<String, dynamic>;
final decoded = jsonDecode(json) as Map<String, Object?>;
final messageType = decoded['messageType'] as String?;
final messageBody = decoded['messageBody'] as String?;

Expand Down
12 changes: 8 additions & 4 deletions dwds/debug_extension/web/copier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,28 @@ void main() {
}

void _registerListeners() {
chrome.runtime.onMessage.addListener(allowInterop(_handleRuntimeMessages));
chrome.runtime.onMessage.addListener(
allowInterop<void Function(Object?, MessageSender, Function)>(
_handleRuntimeMessages,
),
);
}

void _handleRuntimeMessages(
dynamic jsRequest,
Object? jsRequest,
MessageSender sender,
Function sendResponse,
) {
interceptMessage<String>(
message: jsRequest,
message: jsRequest as String?,
expectedType: MessageType.appId,
expectedSender: Script.background,
expectedRecipient: Script.copier,
sender: sender,
messageHandler: _copyAppId,
);

sendResponse(defaultResponse);
(sendResponse as void Function(Object?))(defaultResponse);
}

void _copyAppId(String appId) {
Expand Down
33 changes: 22 additions & 11 deletions dwds/debug_extension/web/cross_extension_communication.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,16 @@ final _eventsForAngularDartDevTools = {
};

Future<void> handleMessagesFromAngularDartDevTools(
dynamic jsRequest,
Object? jsRequest,
// ignore: avoid-unused-parameters
MessageSender sender,
Function sendResponse,
) async {
if (sendResponse is! void Function(Object)) {
throw StateError(
'Unexpected sendResponse signature: ${sendResponse.runtimeType}',
);
}
if (jsRequest == null) return;
final message = jsRequest as ExternalExtensionMessage;
if (message.name == 'chrome.debugger.sendCommand') {
Expand All @@ -53,7 +58,7 @@ Future<void> handleMessagesFromAngularDartDevTools(

void maybeForwardMessageToAngularDartDevTools({
required String method,
required dynamic params,
required Object? params,
required int tabId,
}) {
if (!_eventsForAngularDartDevTools.contains(method)) return;
Expand All @@ -67,7 +72,7 @@ void maybeForwardMessageToAngularDartDevTools({

void _forwardCommandToChromeDebugger(
ExternalExtensionMessage message,
Function sendResponse,
void Function(Object) sendResponse,
) {
try {
final options = message.options as SendCommandOptions;
Expand All @@ -76,15 +81,18 @@ void _forwardCommandToChromeDebugger(
options.method,
options.commandParams,
allowInterop(
([result]) => _respondWithChromeResult(result, sendResponse),
([Object? result]) => _respondWithChromeResult(result, sendResponse),
),
);
} catch (e) {
sendResponse(ErrorResponse()..error = '$e');
}
}

void _respondWithChromeResult(Object? chromeResult, Function sendResponse) {
void _respondWithChromeResult(
Object? chromeResult,
void Function(Object) sendResponse,
) {
// No result indicates that an error occurred.
if (chromeResult == null) {
sendResponse(
Expand All @@ -96,7 +104,10 @@ void _respondWithChromeResult(Object? chromeResult, Function sendResponse) {
}
}

Future<void> _respondWithEncodedUri(int tabId, Function sendResponse) async {
Future<void> _respondWithEncodedUri(
int tabId,
void Function(Object) sendResponse,
) async {
final encodedUri = await fetchStorageObject<String>(
type: StorageObject.encodedUri,
tabId: tabId,
Expand All @@ -110,7 +121,7 @@ void _forwardMessageToAngularDartDevTools(ExternalExtensionMessage message) {
message,
// options
null,
allowInterop(([result]) => _checkForErrors(result, message.name)),
allowInterop(([Object? result]) => _checkForErrors(result, message.name)),
);
}

Expand All @@ -124,7 +135,7 @@ void _checkForErrors(Object? chromeResult, String messageName) {

ExternalExtensionMessage _debugEventMessage({
required String method,
required dynamic params,
required Object? params,
required int tabId,
}) => ExternalExtensionMessage(
name: 'chrome.debugger.event',
Expand All @@ -134,7 +145,7 @@ ExternalExtensionMessage _debugEventMessage({

ExternalExtensionMessage _dwdsEventMessage({
required String method,
required dynamic params,
required Object? params,
required int tabId,
}) => ExternalExtensionMessage(name: method, tabId: tabId, options: params);

Expand All @@ -145,11 +156,11 @@ ExternalExtensionMessage _dwdsEventMessage({
class ExternalExtensionMessage {
external int get tabId;
external String get name;
external dynamic get options;
external Object? get options;
external factory ExternalExtensionMessage({
required int tabId,
required String name,
required dynamic options,
required Object? options,
});
}

Expand Down
14 changes: 8 additions & 6 deletions dwds/debug_extension/web/debug_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,9 @@ Future<void> _onDebuggerEvent(
}

Future<void> _maybeConnectToDwds(int tabId, Object? params) async {
final context = json.decode(JSON.stringify(params))['context'];
final context =
(json.decode(JSON.stringify(params)) as Map<String, Object?>)['context']!
as Map<String, Object?>;
final contextOrigin = context['origin'] as String?;
if (contextOrigin == null) return;
if (contextOrigin.contains('chrome-extension:')) return;
Expand Down Expand Up @@ -320,7 +322,7 @@ Future<bool> _isDartFrame({required int tabId, required int contextId}) {
returnByValue: true,
contextId: contextId,
),
allowInterop((dynamic response) {
allowInterop((Object? response) {
final evalResponse = response as _EvalResponse;
final value = evalResponse.result.value;
final appId = value?[0];
Expand Down Expand Up @@ -449,7 +451,7 @@ void _forwardDwdsEventToChromeDebugger(
Debuggee(tabId: tabId),
message.command,
js_util.jsify(params),
allowInterop(([e]) {
allowInterop(([Object? e]) {
// No arguments indicate that an error occurred.
if (e == null) {
client.sink.add(
Expand Down Expand Up @@ -491,7 +493,7 @@ void _forwardDwdsEventToChromeDebugger(
void _forwardChromeDebuggerEventToDwds(
Debuggee source,
String method,
dynamic params,
Object? params,
) {
final debugSession = _debugSessions.firstWhereOrNull(
(session) => session.appTabId == source.tabId,
Expand Down Expand Up @@ -736,7 +738,7 @@ DebuggerLocation? _debuggerLocation(int dartAppTabId) {
}

/// Construct an [ExtensionEvent] from [method] and [params].
ExtensionEvent _extensionEventFor(String method, dynamic params) {
ExtensionEvent _extensionEventFor(String method, Object? params) {
return ExtensionEvent(
(b) => b
..params = jsonEncode(json.decode(JSON.stringify(params)))
Expand Down Expand Up @@ -783,7 +785,7 @@ class _DebugSession {
required this.trigger,
required void Function(String data) onIncoming,
required void Function() onDone,
required void Function(dynamic error) onError,
required void Function(Object? error) onError,
required bool cancelOnError,
}) : _socketClient = client {
// Collect extension events and send them periodically to the server.
Expand Down
11 changes: 6 additions & 5 deletions dwds/debug_extension/web/detector.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,11 @@ void _detectMultipleDartApps() {
}

void _detectMultipleDartAppsCallback(
List<dynamic> mutations,
List<Object?> mutations,
MutationObserver observer,
) {
for (final mutation in mutations) {
if (_isMultipleAppsMutation(mutation)) {
if (_isMultipleAppsMutation(mutation!)) {
_sendMessageToBackgroundScript(
type: MessageType.multipleAppsDetected,
body: 'true',
Expand All @@ -96,13 +96,14 @@ void _detectMultipleDartAppsCallback(
}
}

bool _isMultipleAppsMutation(dynamic mutation) {
bool _isMultipleAppsMutation(Object mutation) {
final isAttributeMutation =
hasProperty(mutation, 'type') &&
getProperty(mutation, 'type') == 'attributes';
getProperty<String>(mutation, 'type') == 'attributes';
if (isAttributeMutation) {
return hasProperty(mutation, 'attributeName') &&
getProperty(mutation, 'attributeName') == _multipleAppsAttribute;
getProperty<String>(mutation, 'attributeName') ==
_multipleAppsAttribute;
}
return false;
}
Expand Down
Loading
Loading