Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 4 additions & 4 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 Down Expand Up @@ -55,7 +55,7 @@ dart_code_metrics:
- avoid-collection-methods-with-unrelated-types
# - avoid-double-slash-imports
- avoid-duplicate-exports
# - avoid-dynamic
# - avoid-Object?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
# - avoid-Object?
# - avoid-dynamic

# - avoid-global-state # Enable.
# - avoid-ignoring-return-values
# - avoid-late-keyword
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
2 changes: 1 addition & 1 deletion dwds/debug_extension/web/background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void _registerListeners() {
}

Future<void> _handleRuntimeMessages(
dynamic jsRequest,
Object? jsRequest,
MessageSender sender,
Function sendResponse,
) async {
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
10 changes: 5 additions & 5 deletions dwds/debug_extension/web/debug_session.dart
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,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 +449,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 +491,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 +736,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 +783,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
4 changes: 2 additions & 2 deletions dwds/debug_extension/web/messaging.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Message {
});

factory Message.fromJSON(String json) {
final decoded = jsonDecode(json) as Map<String, dynamic>;
final decoded = jsonDecode(json) as Map<String, Object?>;

return Message(
to: Script.fromString(decoded['to'] as String),
Expand Down Expand Up @@ -161,7 +161,7 @@ Future<bool> _sendMessage({
body: body,
).toJSON();
final completer = Completer<bool>();
void responseHandler([dynamic _]) {
void responseHandler([Object? _]) {
final error = chrome.runtime.lastError;
if (error != null) {
debugError(
Expand Down
2 changes: 1 addition & 1 deletion dwds/debug_extension/web/panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ Future<void> _registerListeners() async {
}

void _handleRuntimeMessages(
dynamic jsRequest,
Object? jsRequest,
// ignore: avoid-unused-parameters
MessageSender sender,
// ignore: avoid-unused-parameters
Expand Down
4 changes: 2 additions & 2 deletions dwds/debug_extension/web/storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ Future<bool> setStorageObject<T>({
final completer = Completer<bool>();
final storageArea = _getStorageArea(type.persistence);
storageArea.set(
jsify(storageObj),
jsify(storageObj) as Object,
allowInterop(() {
if (callback != null) {
callback();
Expand Down Expand Up @@ -151,7 +151,7 @@ void interceptStorageChange<T>({
final isExpected = hasProperty(storageObj, expectedStorageKey);
if (!isExpected) return;

final objProp = getProperty(storageObj, expectedStorageKey);
final objProp = getProperty<String>(storageObj, expectedStorageKey);
final json = getProperty(objProp, 'newValue') as String?;
T? decodedObj;
if (json == null || T == String) {
Expand Down
Loading
Loading