Skip to content

Commit 0afc9eb

Browse files
authored
Add Dart Code Metrics (#2055)
1 parent 5fcbb80 commit 0afc9eb

24 files changed

+112
-69
lines changed

dwds/analysis_options.yaml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,45 @@ linter:
2222
- require_trailing_commas
2323
- unawaited_futures
2424
- unnecessary_lambdas
25+
26+
# TODO(https://github.com/dart-lang/webdev/issues/2053): Enable commented-out rules with fixes.
27+
dart_code_metrics:
28+
metrics:
29+
# cyclomatic-complexity: 20
30+
# number-of-parameters: 5
31+
# maximum-nesting-level: 5
32+
metrics-exclude:
33+
- test/**
34+
rules:
35+
- avoid-cascade-after-if-null
36+
- avoid-collection-methods-with-unrelated-types
37+
- avoid-duplicate-exports
38+
# - avoid-global-state
39+
- avoid-missing-enum-constant-in-map
40+
- avoid-nested-conditional-expressions
41+
- avoid-non-ascii-symbols
42+
# - avoid-non-null-assertion
43+
# - avoid-passing-async-when-sync-expected
44+
- avoid-redundant-async
45+
# - avoid-throw-in-catch-block
46+
- avoid-unnecessary-type-assertions
47+
- avoid-unnecessary-type-casts
48+
- avoid-unrelated-type-assertions
49+
- avoid-unused-parameters
50+
- binary-expression-operand-order
51+
- double-literal-format
52+
# - format-comment
53+
# - member-ordering
54+
- no-boolean-literal-compare
55+
# - no-empty-block
56+
- no-equal-then-else
57+
# - prefer-async-await
58+
# - prefer-commenting-analyzer-ignores
59+
# - prefer-correct-test-file-name
60+
- prefer-correct-type-name
61+
- prefer-enums-by-name
62+
# - prefer-immediate-return
63+
- prefer-iterable-of
64+
- prefer-last
65+
# - prefer-moving-to-variable:
66+
# allow-duplicated-chains: 2

dwds/debug_extension_mv3/tool/build_extension.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ Future<int> run({required bool isProd, required bool isMV3}) async {
7474
return updateExitCode;
7575
}
7676

77-
Future<int> _handleProcess(Process process) async {
77+
Future<int> _handleProcess(Process process) {
7878
_handleOutput(process.stdout, isStdout: true);
7979
_handleOutput(process.stderr, isStdout: false);
8080
return process.exitCode;

dwds/debug_extension_mv3/web/background.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ void _registerListeners() {
6262
Future<void> _handleRuntimeMessages(
6363
dynamic jsRequest,
6464
MessageSender sender,
65-
Function sendResponse,
65+
Function _,
6666
) async {
6767
if (jsRequest is! String) return;
6868

dwds/debug_extension_mv3/web/cross_extension_communication.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ final _eventsForAngularDartDevTools = {
2929

3030
Future<void> handleMessagesFromAngularDartDevTools(
3131
dynamic jsRequest,
32-
MessageSender sender,
32+
MessageSender _,
3333
Function sendResponse,
3434
) async {
3535
if (jsRequest == null) return;
@@ -107,7 +107,8 @@ void _forwardMessageToAngularDartDevTools(ExternalExtensionMessage message) {
107107
chrome.runtime.sendMessage(
108108
_angularDartDevToolsId,
109109
message,
110-
/* options */ null,
110+
/* options */
111+
null,
111112
allowInterop(([result]) => _checkForErrors(result, message.name)),
112113
);
113114
}

dwds/debug_extension_mv3/web/debug_session.dart

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -234,9 +234,11 @@ _enableExecutionContextReporting(int tabId) {
234234
if (chromeError != null) {
235235
final errorMessage = _translateChromeError(chromeError.message);
236236
chrome.notifications.create(
237-
/*notificationId*/ null,
237+
/*notificationId*/
238+
null,
238239
NotificationOptions(message: errorMessage),
239-
/*callback*/ null,
240+
/*callback*/
241+
null,
240242
);
241243
return;
242244
}
@@ -682,7 +684,8 @@ Future<bool> _sendAuthRequest(String authUrl) async {
682684
Future<bool> _showWarningNotification(String message) {
683685
final completer = Completer<bool>();
684686
chrome.notifications.create(
685-
/*notificationId*/ null,
687+
/*notificationId*/
688+
null,
686689
NotificationOptions(
687690
title: '[Error] Dart Debug Extension',
688691
message: message,

dwds/debug_extension_mv3/web/lifeline_connection.dart

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'chrome_api.dart';
66
import 'logger.dart';
77

8-
void main() async {
8+
void main() {
99
_connectToLifelinePort();
1010
}
1111

@@ -15,7 +15,8 @@ void _connectToLifelinePort() {
1515
prefix: 'Dart Debug Extension',
1616
);
1717
chrome.runtime.connect(
18-
/*extensionId=*/ null,
18+
/*extensionId=*/
19+
null,
1920
ConnectInfo(name: 'keepAlive'),
2021
);
2122
}

dwds/debug_extension_mv3/web/messaging.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,11 @@ Future<bool> sendRuntimeMessage({
118118
);
119119
final completer = Completer<bool>();
120120
chrome.runtime.sendMessage(
121-
/*id*/ null,
121+
/*id*/
122+
null,
122123
message.toJSON(),
123-
/*options*/ null,
124+
/*options*/
125+
null,
124126
allowInterop(() {
125127
final error = chrome.runtime.lastError;
126128
if (error != null) {

dwds/debug_extension_mv3/web/panel.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,8 @@ Future<void> _registerListeners() async {
7777

7878
void _handleRuntimeMessages(
7979
dynamic jsRequest,
80-
MessageSender sender,
81-
Function sendResponse,
80+
MessageSender _,
81+
Function __,
8282
) {
8383
if (jsRequest is! String) return;
8484

@@ -120,7 +120,7 @@ void _handleRuntimeMessages(
120120
);
121121
}
122122

123-
void _handleStorageChanges(Object storageObj, String storageArea) {
123+
void _handleStorageChanges(Object storageObj, String _) {
124124
interceptStorageChange<DebugInfo>(
125125
storageObj: storageObj,
126126
expectedType: StorageObject.debugInfo,
@@ -252,7 +252,7 @@ bool _warningBannerIsVisible({String? message}) {
252252
final warningBanner = document.getElementById(_warningBannerId);
253253
final isVisible =
254254
warningBanner != null && warningBanner.classes.contains(_showClass);
255-
if (message == null || isVisible == false) return isVisible;
255+
if (message == null || !isVisible) return isVisible;
256256
final warningMsg = document.getElementById(_warningMsgId);
257257
return warningMsg?.innerHtml == message;
258258
}
@@ -293,7 +293,7 @@ Future<void> _launchDebugConnection(Event _) async {
293293
Future<void> _maybeHandleConnectionTimeout() async {
294294
_connecting = true;
295295
await Future.delayed(Duration(seconds: 10));
296-
if (_connecting == true) {
296+
if (_connecting) {
297297
_handleConnectFailure(ConnectFailureReason.timeout);
298298
}
299299
}

dwds/debug_extension_mv3/web/utils.dart

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Future<Tab?> getTab(int tabId) {
4242
return completer.future;
4343
}
4444

45-
Future<Tab?> get activeTab async {
45+
Future<Tab?> get activeTab {
4646
final completer = Completer<Tab?>();
4747
final query = QueryInfo(active: true, currentWindow: true);
4848
chrome.tabs.query(
@@ -96,9 +96,17 @@ void onExtensionIconClicked(void Function(Tab) callback) {
9696

9797
void setExtensionIcon(IconInfo info) {
9898
if (isMV3) {
99-
_setExtensionIconMV3(info, /*callback*/ null);
99+
_setExtensionIconMV3(
100+
info,
101+
/*callback*/
102+
null,
103+
);
100104
} else {
101-
_setExtensionIconMV2(info, /*callback*/ null);
105+
_setExtensionIconMV2(
106+
info,
107+
/*callback*/
108+
null,
109+
);
102110
}
103111
}
104112

dwds/lib/dart_web_debug_service.dart

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@ class Dwds {
141141
buildResults,
142142
devTools,
143143
assetReader,
144-
loadStrategy,
145144
hostname,
146145
extensionBackend,
147146
urlEncoder,

0 commit comments

Comments
 (0)