From c8d6f85d0f70fb870e7396fbc224817973766552 Mon Sep 17 00:00:00 2001 From: Konstantin Shcheglov Date: Sat, 6 Mar 2021 05:20:16 +0000 Subject: [PATCH] Enforce lint unnecessary_parenthesis in analysis_server. Change-Id: Ib68c124988743b45807015e7274f429fff67fe44 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/189384 Reviewed-by: Brian Wilkerson Commit-Queue: Konstantin Shcheglov --- pkg/analysis_server/analysis_options.yaml | 1 + .../lib/lsp_protocol/protocol_custom_generated.dart | 1 + .../lib/lsp_protocol/protocol_generated.dart | 1 + pkg/analysis_server/lib/src/lsp/mapping.dart | 2 +- pkg/analysis_server/lib/src/plugin/result_merger.dart | 8 ++++---- pkg/analysis_server/lib/src/server/sdk_configuration.dart | 2 +- .../lib/src/services/completion/dart/uri_contributor.dart | 2 +- .../completion/statement/statement_completion.dart | 6 +++--- .../src/services/correction/dart/convert_to_contains.dart | 2 +- .../correction/fix/data_driven/code_fragment_parser.dart | 2 +- pkg/analysis_server/lib/src/status/diagnostics.dart | 4 ++-- .../test/channel/byte_stream_channel_test.dart | 4 ++-- .../test/integration/support/integration_tests.dart | 2 +- pkg/analysis_server/test/stress/utilities/server.dart | 2 +- pkg/analysis_server/test/timing/timing_framework.dart | 2 +- .../tool/code_completion/completion_metrics.dart | 4 ++-- pkg/analysis_server/tool/lsp_spec/generate_all.dart | 1 + 17 files changed, 25 insertions(+), 21 deletions(-) diff --git a/pkg/analysis_server/analysis_options.yaml b/pkg/analysis_server/analysis_options.yaml index 254951f8243..06e8506ee1b 100644 --- a/pkg/analysis_server/analysis_options.yaml +++ b/pkg/analysis_server/analysis_options.yaml @@ -24,4 +24,5 @@ linter: - prefer_typing_uninitialized_variables - unnecessary_brace_in_string_interps - unnecessary_overrides + - unnecessary_parenthesis - void_checks diff --git a/pkg/analysis_server/lib/lsp_protocol/protocol_custom_generated.dart b/pkg/analysis_server/lib/lsp_protocol/protocol_custom_generated.dart index e4b17e6e4c8..c67d3f769c7 100644 --- a/pkg/analysis_server/lib/lsp_protocol/protocol_custom_generated.dart +++ b/pkg/analysis_server/lib/lsp_protocol/protocol_custom_generated.dart @@ -10,6 +10,7 @@ // ignore_for_file: deprecated_member_use // ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: unnecessary_brace_in_string_interps +// ignore_for_file: unnecessary_parenthesis // ignore_for_file: unused_import // ignore_for_file: unused_shown_name diff --git a/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart b/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart index 4af958b56b3..215bf08db5e 100644 --- a/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart +++ b/pkg/analysis_server/lib/lsp_protocol/protocol_generated.dart @@ -10,6 +10,7 @@ // ignore_for_file: deprecated_member_use // ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: unnecessary_brace_in_string_interps +// ignore_for_file: unnecessary_parenthesis // ignore_for_file: unused_import // ignore_for_file: unused_shown_name diff --git a/pkg/analysis_server/lib/src/lsp/mapping.dart b/pkg/analysis_server/lib/src/lsp/mapping.dart index 298e9978398..9e59ec6407b 100644 --- a/pkg/analysis_server/lib/src/lsp/mapping.dart +++ b/pkg/analysis_server/lib/src/lsp/mapping.dart @@ -643,7 +643,7 @@ ErrorOr pathOfUri(Uri uri) { message: 'Document URI was not supplied', )); } - final isValidFileUri = (uri?.isScheme('file') ?? false); + final isValidFileUri = uri?.isScheme('file') ?? false; if (!isValidFileUri) { return ErrorOr.error(ResponseError( code: lsp.ServerErrorCodes.InvalidFilePath, diff --git a/pkg/analysis_server/lib/src/plugin/result_merger.dart b/pkg/analysis_server/lib/src/plugin/result_merger.dart index 91a5a65b929..0336650b293 100644 --- a/pkg/analysis_server/lib/src/plugin/result_merger.dart +++ b/pkg/analysis_server/lib/src/plugin/result_merger.dart @@ -575,12 +575,12 @@ class ResultMerger { lengths.addAll(feedback.lengths); } return ExtractLocalVariableFeedback(names.toList(), offsets, lengths, - coveringExpressionOffsets: (coveringExpressionOffsets.isEmpty + coveringExpressionOffsets: coveringExpressionOffsets.isEmpty ? null - : coveringExpressionOffsets), - coveringExpressionLengths: (coveringExpressionLengths.isEmpty + : coveringExpressionOffsets, + coveringExpressionLengths: coveringExpressionLengths.isEmpty ? null - : coveringExpressionLengths)); + : coveringExpressionLengths); } else if (first is ExtractMethodFeedback) { var offset = first.offset; var length = first.length; diff --git a/pkg/analysis_server/lib/src/server/sdk_configuration.dart b/pkg/analysis_server/lib/src/server/sdk_configuration.dart index 08105f8dd0d..c296772a2f1 100644 --- a/pkg/analysis_server/lib/src/server/sdk_configuration.dart +++ b/pkg/analysis_server/lib/src/server/sdk_configuration.dart @@ -55,7 +55,7 @@ class SdkConfiguration { /// Return a string describing the contents of this SDK configuration. String get displayString { - return _values.keys.map((key) => '$key: ${_values[key]}').join(('\n')); + return _values.keys.map((key) => '$key: ${_values[key]}').join('\n'); } /// Returns whether this SDK configuration has any configured values. diff --git a/pkg/analysis_server/lib/src/services/completion/dart/uri_contributor.dart b/pkg/analysis_server/lib/src/services/completion/dart/uri_contributor.dart index 6e53137324c..fed0ed7fa70 100644 --- a/pkg/analysis_server/lib/src/services/completion/dart/uri_contributor.dart +++ b/pkg/analysis_server/lib/src/services/completion/dart/uri_contributor.dart @@ -115,7 +115,7 @@ class _UriSuggestionBuilder extends SimpleAstVisitor { var source = request.source; String parentUri; - if ((partialUri.endsWith('/'))) { + if (partialUri.endsWith('/')) { parentUri = partialUri; } else { parentUri = posix.dirname(partialUri); diff --git a/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart b/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart index 2ff7dae7df2..a8634cacc24 100644 --- a/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart +++ b/pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart @@ -1231,10 +1231,10 @@ class StatementCompletionProcessor { } if (body is Block) { var block = body; - return (!(block.leftBracket.isSynthetic)); + return !block.leftBracket.isSynthetic; } - return (lineInfo.getLocation(keyword.offset) == - lineInfo.getLocation(body.offset)); + return lineInfo.getLocation(keyword.offset) == + lineInfo.getLocation(body.offset); } } diff --git a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_contains.dart b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_contains.dart index 1da824e75b5..d1a5302e8ea 100644 --- a/pkg/analysis_server/lib/src/services/correction/dart/convert_to_contains.dart +++ b/pkg/analysis_server/lib/src/services/correction/dart/convert_to_contains.dart @@ -76,7 +76,7 @@ class ConvertToContains extends CorrectionProducer { expression.operator.type == TokenType.MINUS) { var operand = expression.operand; if (operand is IntegerLiteral) { - return -(operand.value); + return -operand.value; } } throw StateError('invalid integer value'); diff --git a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/code_fragment_parser.dart b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/code_fragment_parser.dart index 0050c6d81b5..27dd4cb7f77 100644 --- a/pkg/analysis_server/lib/src/services/correction/fix/data_driven/code_fragment_parser.dart +++ b/pkg/analysis_server/lib/src/services/correction/fix/data_driven/code_fragment_parser.dart @@ -429,7 +429,7 @@ class _CodeFragmentScanner { } /// Return `true` if the [char] is a digit. - bool _isDigit(int char) => (char >= $0 && char <= $9); + bool _isDigit(int char) => char >= $0 && char <= $9; /// Return `true` if the [char] is a letter. bool _isLetter(int char) => diff --git a/pkg/analysis_server/lib/src/status/diagnostics.dart b/pkg/analysis_server/lib/src/status/diagnostics.dart index 368b129f41f..7818392ed79 100644 --- a/pkg/analysis_server/lib/src/status/diagnostics.dart +++ b/pkg/analysis_server/lib/src/status/diagnostics.dart @@ -777,8 +777,8 @@ class DiagnosticsSite extends Site implements AbstractGetHandler { pages.add(MemoryAndCpuPage(this, profiler)); } - pages.sort(((Page a, Page b) => - a.title.toLowerCase().compareTo(b.title.toLowerCase()))); + pages.sort((Page a, Page b) => + a.title.toLowerCase().compareTo(b.title.toLowerCase())); // Add the status page at the beginning. pages.insert(0, StatusPage(this)); diff --git a/pkg/analysis_server/test/channel/byte_stream_channel_test.dart b/pkg/analysis_server/test/channel/byte_stream_channel_test.dart index 8f3b0551c18..717b50b3575 100644 --- a/pkg/analysis_server/test/channel/byte_stream_channel_test.dart +++ b/pkg/analysis_server/test/channel/byte_stream_channel_test.dart @@ -38,7 +38,7 @@ class ByteStreamClientChannelTest { inputSink = IOSink(inputStream); var outputStream = StreamController>(); outputLineStream = outputStream.stream - .transform((Utf8Codec()).decoder) + .transform(Utf8Codec().decoder) .transform(LineSplitter()); outputSink = IOSink(outputStream); channel = ByteStreamClientChannel(inputStream.stream, outputSink); @@ -124,7 +124,7 @@ class ByteStreamServerChannelTest { inputSink = IOSink(inputStream); var outputStream = StreamController>(); outputLineStream = outputStream.stream - .transform((Utf8Codec()).decoder) + .transform(Utf8Codec().decoder) .transform(LineSplitter()); var outputSink = IOSink(outputStream); channel = ByteStreamServerChannel( diff --git a/pkg/analysis_server/test/integration/support/integration_tests.dart b/pkg/analysis_server/test/integration/support/integration_tests.dart index 8f34d328ed5..69a48044812 100644 --- a/pkg/analysis_server/test/integration/support/integration_tests.dart +++ b/pkg/analysis_server/test/integration/support/integration_tests.dart @@ -518,7 +518,7 @@ class Server { } }); _process.stderr - .transform((Utf8Codec()).decoder) + .transform(Utf8Codec().decoder) .transform(LineSplitter()) .listen((String line) { var trimmedLine = line.trim(); diff --git a/pkg/analysis_server/test/stress/utilities/server.dart b/pkg/analysis_server/test/stress/utilities/server.dart index 9bbafb3bd4f..5e652d25744 100644 --- a/pkg/analysis_server/test/stress/utilities/server.dart +++ b/pkg/analysis_server/test/stress/utilities/server.dart @@ -786,7 +786,7 @@ class Server { void installHandler( Stream> stream, void Function(String) handler) { stream - .transform((Utf8Codec()).decoder) + .transform(Utf8Codec().decoder) .transform(LineSplitter()) .listen(handler); } diff --git a/pkg/analysis_server/test/timing/timing_framework.dart b/pkg/analysis_server/test/timing/timing_framework.dart index 8dae417e4d7..f7d6da1084d 100644 --- a/pkg/analysis_server/test/timing/timing_framework.dart +++ b/pkg/analysis_server/test/timing/timing_framework.dart @@ -79,7 +79,7 @@ class TimingResult { var diff = values[i] - average; sumOfDiffSquared += diff * diff; } - return sqrt((sumOfDiffSquared / (count - 1))); + return sqrt(sumOfDiffSquared / (count - 1)); } /// Convert the given [times], expressed in nanoseconds, to times expressed in diff --git a/pkg/analysis_server/tool/code_completion/completion_metrics.dart b/pkg/analysis_server/tool/code_completion/completion_metrics.dart index 744cd505da0..a271a8751a3 100644 --- a/pkg/analysis_server/tool/code_completion/completion_metrics.dart +++ b/pkg/analysis_server/tool/code_completion/completion_metrics.dart @@ -830,8 +830,8 @@ class CompletionMetricsComputer { var lines = []; for (var entry in metrics.locationMrrComputers.entries) { var count = entry.value.count; - var mrr = (1 / entry.value.mrr); - var mrr_5 = (1 / entry.value.mrr_5); + var mrr = 1 / entry.value.mrr; + var mrr_5 = 1 / entry.value.mrr_5; var product = count * mrr; lines.add(LocationTableLine( label: entry.key, diff --git a/pkg/analysis_server/tool/lsp_spec/generate_all.dart b/pkg/analysis_server/tool/lsp_spec/generate_all.dart index ecc30791bec..782aa26620a 100644 --- a/pkg/analysis_server/tool/lsp_spec/generate_all.dart +++ b/pkg/analysis_server/tool/lsp_spec/generate_all.dart @@ -163,6 +163,7 @@ String generatedFileHeader(int year, {bool importCustom = false}) => ''' // ignore_for_file: deprecated_member_use // ignore_for_file: deprecated_member_use_from_same_package // ignore_for_file: unnecessary_brace_in_string_interps +// ignore_for_file: unnecessary_parenthesis // ignore_for_file: unused_import // ignore_for_file: unused_shown_name