From e226a73f11f7c0c2887179637e29d4270787409c Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Thu, 11 Nov 2021 09:42:11 -0800 Subject: [PATCH] Enable pkg:lints recommended lints --- analysis_options.yaml | 9 +++++++++ dwds/lib/src/debugging/debugger.dart | 2 +- dwds/lib/src/debugging/inspector.dart | 2 +- dwds/lib/src/handlers/injector.dart | 2 +- dwds/lib/src/services/debug_service.dart | 4 ++-- dwds/lib/src/utilities/conversions.dart | 3 +-- dwds/lib/src/utilities/dart_uri.dart | 3 +-- dwds/test/events_test.dart | 4 ++-- dwds/test/expression_compiler_service_test.dart | 2 +- dwds/test/fixtures/context.dart | 2 +- dwds/test/fixtures/utilities.dart | 7 ++----- dwds/web/run_main.dart | 2 +- webdev/lib/src/daemon_client.dart | 7 ++----- webdev/lib/src/logging.dart | 1 + 14 files changed, 26 insertions(+), 24 deletions(-) diff --git a/analysis_options.yaml b/analysis_options.yaml index 07511dd0f..2faf8a31f 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -40,6 +40,7 @@ linter: - empty_catches - empty_constructor_bodies - empty_statements + - exhaustive_cases - file_names - hash_and_equals - implementation_imports @@ -66,18 +67,23 @@ linter: - prefer_equal_for_default_values - prefer_final_fields - prefer_for_elements_to_map_fromIterable + - prefer_function_declarations_over_variables - prefer_generic_function_type_aliases - prefer_if_null_operators - prefer_initializing_formals + - prefer_inlined_adds - prefer_interpolation_to_compose_strings - prefer_is_empty - prefer_is_not_empty + - prefer_is_not_operator - prefer_iterable_whereType - prefer_null_aware_operators - prefer_relative_imports - prefer_single_quotes - prefer_spread_collections - prefer_typing_uninitialized_variables + - prefer_void_to_null + - provide_deprecation_message - recursive_getters - slash_for_doc_comments - test_types_in_equals @@ -91,8 +97,11 @@ linter: - unnecessary_new - unnecessary_null_aware_assignments - unnecessary_null_in_if_null_operators + - unnecessary_overrides - unnecessary_parenthesis - unnecessary_statements + - unnecessary_string_escapes + - unnecessary_string_interpolations - unnecessary_this - unrelated_type_equality_checks - use_function_type_syntax_for_parameters diff --git a/dwds/lib/src/debugging/debugger.dart b/dwds/lib/src/debugging/debugger.dart index 5b4fef163..ca7a4d26c 100644 --- a/dwds/lib/src/debugging/debugger.dart +++ b/dwds/lib/src/debugging/debugger.dart @@ -181,7 +181,7 @@ class Debugger extends Domain { return debugger; } - Future _initialize() async { + Future _initialize() async { // We must add a listener before enabling the debugger otherwise we will // miss events. // Allow a null debugger/connection for unit tests. diff --git a/dwds/lib/src/debugging/inspector.dart b/dwds/lib/src/debugging/inspector.dart index a3e657ce4..06bd15c8a 100644 --- a/dwds/lib/src/debugging/inspector.dart +++ b/dwds/lib/src/debugging/inspector.dart @@ -140,7 +140,7 @@ class AppInspector extends Domain { isolateFlags: []) ..extensionRPCs = []; AppInspector appInspector; - var provider = () => appInspector; + AppInspector provider() => appInspector; var libraryHelper = LibraryHelper(provider); var classHelper = ClassHelper(provider); var instanceHelper = InstanceHelper(provider); diff --git a/dwds/lib/src/handlers/injector.dart b/dwds/lib/src/handlers/injector.dart index a57ee5cb8..7c8c03941 100644 --- a/dwds/lib/src/handlers/injector.dart +++ b/dwds/lib/src/handlers/injector.dart @@ -82,7 +82,7 @@ class DwdsInjector { var requestedUri = request.requestedUri; var appId = base64 .encode(md5.convert(utf8.encode('$requestedUri')).bytes); - var scheme = '${request.requestedUri.scheme}'; + var scheme = request.requestedUri.scheme; if (!_useSseForInjectedClient) { // Switch http->ws and https->wss. scheme = scheme.replaceFirst('http', 'ws'); diff --git a/dwds/lib/src/services/debug_service.dart b/dwds/lib/src/services/debug_service.dart index 9987c5e51..43a9ce563 100644 --- a/dwds/lib/src/services/debug_service.dart +++ b/dwds/lib/src/services/debug_service.dart @@ -155,7 +155,7 @@ class DebugService { scheme: 'http', host: hostname, port: port, - path: '$authToken', + path: authToken, ), serviceUri: Uri( scheme: 'http', @@ -181,7 +181,7 @@ class DebugService { scheme: 'ws', host: hostname, port: port, - path: '$authToken', + path: authToken, )) .toString(); } diff --git a/dwds/lib/src/utilities/conversions.dart b/dwds/lib/src/utilities/conversions.dart index db4079d16..05465fc0f 100644 --- a/dwds/lib/src/utilities/conversions.dart +++ b/dwds/lib/src/utilities/conversions.dart @@ -5,7 +5,6 @@ // @dart = 2.9 /// Functions for converting between the different object references we use. - import 'package:webkit_inspection_protocol/webkit_inspection_protocol.dart'; /// Convert [argument] to a form usable in WIP evaluation calls. @@ -81,7 +80,7 @@ RemoteObject remoteObjectFor(String dartId) { /// RemoteObjects. String dartIdFor(Object argument) { if (argument == null) { - return '$_nullId'; + return _nullId; } if (argument is double) { return '$_prefixForDoubleIds$argument'; diff --git a/dwds/lib/src/utilities/dart_uri.dart b/dwds/lib/src/utilities/dart_uri.dart index 33ed502f2..b87e8ed86 100644 --- a/dwds/lib/src/utilities/dart_uri.dart +++ b/dwds/lib/src/utilities/dart_uri.dart @@ -78,8 +78,7 @@ class DartUri { // Both currentDirectoryUri and the libraryUri path should have '/' // separators, so we can join them as url paths to get the absolute file // url. - var libraryPath = - p.url.join('$currentDirectoryUri', uri.path.substring(1)); + var libraryPath = p.url.join(currentDirectoryUri, uri.path.substring(1)); _libraryNamesByPath[libraryPath] = libraryUri; } else if (uri.scheme == 'package') { var libraryPath = _packageConfig.resolve(uri); diff --git a/dwds/test/events_test.dart b/dwds/test/events_test.dart index 7ad33ddc9..7f498a58f 100644 --- a/dwds/test/events_test.dart +++ b/dwds/test/events_test.dart @@ -41,10 +41,10 @@ void main() { }); test('emits HTTP_REQUEST_EXCEPTION event', () async { - final throwAsyncException = () async { + Future throwAsyncException() async { await Future.delayed(const Duration(milliseconds: 100)); throw Exception('async error'); - }; + } // The events stream is a broadcast stream so start listening // before the action. diff --git a/dwds/test/expression_compiler_service_test.dart b/dwds/test/expression_compiler_service_test.dart index 6b6dedd4b..3886b1f5e 100644 --- a/dwds/test/expression_compiler_service_test.dart +++ b/dwds/test/expression_compiler_service_test.dart @@ -59,7 +59,7 @@ void main() async { var port = server.port; // start expression compilation service - final assetHandler = (request) => + Response assetHandler(request) => Response(200, body: File.fromUri(kernel).readAsBytesSync()); service = ExpressionCompilerService('localhost', port, assetHandler, false); diff --git a/dwds/test/fixtures/context.dart b/dwds/test/fixtures/context.dart index b3457aa9c..779d8d743 100644 --- a/dwds/test/fixtures/context.dart +++ b/dwds/test/fixtures/context.dart @@ -343,7 +343,7 @@ class TestContext { webkitDebugger = WebkitDebugger(WipDebugger(tabConnection)); } - Future tearDown() async { + Future tearDown() async { await webDriver?.quit(closeSession: true); chromeDriver?.kill(); DartUri.currentDirectory = p.current; diff --git a/dwds/test/fixtures/utilities.dart b/dwds/test/fixtures/utilities.dart index 839ce6509..359dace1d 100644 --- a/dwds/test/fixtures/utilities.dart +++ b/dwds/test/fixtures/utilities.dart @@ -14,11 +14,8 @@ import 'package:path/path.dart' as p; /// Connects to the `build_runner` daemon. Future connectClient(String workingDirectory, List options, Function(ServerLog) logHandler) => - BuildDaemonClient.connect( - workingDirectory, - [dartPath] - ..addAll(['run', 'build_runner', 'daemon']) - ..addAll(options), + BuildDaemonClient.connect(workingDirectory, + [dartPath, 'run', 'build_runner', 'daemon', ...options], logHandler: logHandler); /// The path to the root directory of the SDK. diff --git a/dwds/web/run_main.dart b/dwds/web/run_main.dart index 5010a58db..14d22e3ed 100644 --- a/dwds/web/run_main.dart +++ b/dwds/web/run_main.dart @@ -12,7 +12,7 @@ final ScriptElement Function() _createScript = (() { })(); // According to the CSP3 spec a nonce must be a valid base64 string. -final _noncePattern = RegExp('^[\\w+\/_-]+[=]{0,2}\$'); +final _noncePattern = RegExp('^[\\w+/_-]+[=]{0,2}\$'); /// Returns CSP nonce, if set for any script tag. String _findNonce() { diff --git a/webdev/lib/src/daemon_client.dart b/webdev/lib/src/daemon_client.dart index d8ae674b1..5b3a671e6 100644 --- a/webdev/lib/src/daemon_client.dart +++ b/webdev/lib/src/daemon_client.dart @@ -16,11 +16,8 @@ import 'util.dart'; /// Connects to the `build_runner` daemon. Future connectClient(String workingDirectory, List options, Function(ServerLog) logHandler) => - BuildDaemonClient.connect( - workingDirectory, - [dartPath] - ..addAll(['run', 'build_runner', 'daemon']) - ..addAll(options), + BuildDaemonClient.connect(workingDirectory, + [dartPath, 'run', 'build_runner', 'daemon', ...options], logHandler: logHandler); /// Returns the port of the daemon asset server. diff --git a/webdev/lib/src/logging.dart b/webdev/lib/src/logging.dart index b9eb321b8..95554bf5a 100644 --- a/webdev/lib/src/logging.dart +++ b/webdev/lib/src/logging.dart @@ -28,6 +28,7 @@ void configureLogWriter(bool verbose, {LogWriter customLogWriter}) { }); } +// ignore: prefer_function_declarations_over_variables LogWriter _logWriter = (level, message, {String error, String loggerName, String stackTrace}) { // Erases the previous line