Skip to content

Commit c14b6eb

Browse files
FMorschelCommit Queue
authored andcommitted
[DAS] Adds lints for boolean literals to analysis server packages and fixes occurences
Bug: #59789 Change-Id: I3287ab55a1b3048c5cbf7f820563fbbd5a292512 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/445920 Reviewed-by: Samuel Rawlins <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]> Auto-Submit: Felipe Morschel <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]>
1 parent 33e9bb9 commit c14b6eb

File tree

20 files changed

+36
-34
lines changed

20 files changed

+36
-34
lines changed

pkg/analysis_server/analysis_options.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,10 @@ analyzer:
2626

2727
linter:
2828
rules:
29+
- avoid_bool_literals_in_conditional_expressions
2930
- avoid_redundant_argument_values
3031
- flutter_style_todos
32+
- no_literal_bool_comparisons
3133
- prefer_single_quotes
3234
- unawaited_futures
3335
- unnecessary_async

pkg/analysis_server/lib/src/lsp/client_configuration.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -333,7 +333,7 @@ class LspGlobalClientConfiguration extends LspResourceClientConfiguration {
333333

334334
// Whether diagnostics should be generated for all `TODO` comments.
335335
bool get showAllTodos =>
336-
_settings['showTodos'] is bool ? _settings['showTodos'] as bool : false;
336+
_settings['showTodos'] is bool && _settings['showTodos'] as bool;
337337

338338
/// A specific set of `TODO` comments that should generate diagnostics.
339339
///

pkg/analysis_server/lib/src/lsp/completion_utils.dart

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -383,11 +383,8 @@ lsp.CompletionItem? toLspCompletionItem(
383383
}
384384

385385
var isDeprecated =
386-
suggestion is ElementBasedSuggestion
387-
? (suggestion as ElementBasedSuggestion)
388-
.element
389-
.hasOrInheritsDeprecated
390-
: false;
386+
suggestion is ElementBasedSuggestion &&
387+
(suggestion as ElementBasedSuggestion).element.hasOrInheritsDeprecated;
391388

392389
// Because we potentially send thousands of these items, we should minimise
393390
// the generated JSON as much as possible - for example using nulls in place

pkg/analysis_server/lib/src/lsp/handlers/code_actions/code_action_computer.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -487,9 +487,8 @@ class _CodeActionSorter {
487487
// Compare either edits or commands based on which the selected action has.
488488
return firstLiteral.edit != null
489489
? firstLiteral.edit == other.edit
490-
: firstLiteral.command != null
491-
? firstLiteral.command == other.command
492-
: false;
490+
: firstLiteral.command != null &&
491+
firstLiteral.command == other.command;
493492
});
494493

495494
// Build a new CodeAction that merges the diagnostics from each same

pkg/analysis_server/lib/src/lsp/handlers/handler_completion.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -414,9 +414,8 @@ class CompletionHandler
414414
/// invocation that already has an argument list, otherwise we would
415415
/// insert dupes.
416416
var completeFunctionCalls =
417-
_hasExistingArgList(target.entity)
418-
? false
419-
: server.lspClientConfiguration.global.completeFunctionCalls;
417+
!_hasExistingArgList(target.entity) &&
418+
server.lspClientConfiguration.global.completeFunctionCalls;
420419

421420
// Compute defaults that will allow us to reduce payload size.
422421
var defaultReplacementRange = toRange(

pkg/analysis_server/lib/src/lsp/handlers/handler_references.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ class ReferencesHandler
106106
(_) => convert(results, toLocation).nonNulls.toList(),
107107
);
108108

109-
if (params.context.includeDeclaration == true) {
109+
if (params.context.includeDeclaration) {
110110
// Also include the definition for the resolved element.
111111
referenceResults.addAll(
112112
performance.run('_getDeclarations', (_) => _getDeclarations(element)),

pkg/analysis_server/lib/src/services/completion/statement/statement_completion.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1175,7 +1175,7 @@ class StatementCompletionProcessor {
11751175
return diagnostics.firstWhereOrNull(
11761176
(d) =>
11771177
d.diagnosticCode == code &&
1178-
(partialMatch == null ? true : d.message.contains(partialMatch)),
1178+
(partialMatch == null || d.message.contains(partialMatch)),
11791179
);
11801180
}
11811181

pkg/analysis_server/lib/src/services/correction/dart/create_setter.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ class CreateSetter extends ResolvedCorrectionProducer {
7777
}
7878
var targetFragment = targetElement.firstFragment;
7979
var targetSource = targetFragment.libraryFragment.source;
80-
if (targetElement.library.isInSdk == true) {
80+
if (targetElement.library.isInSdk) {
8181
return;
8282
}
8383
// prepare target declaration

pkg/analysis_server/lib/src/services/correction/dart/destructure_local_variable_assignment.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,6 @@ extension on AstNode {
302302
var node = this;
303303
if (node is PrefixedIdentifier) node = node.identifier;
304304
if (node is PropertyAccess) node = node.propertyName;
305-
return (node is SimpleIdentifier) ? node.inSetterContext() : false;
305+
return (node is SimpleIdentifier) && node.inSetterContext();
306306
}
307307
}

pkg/analysis_server/lib/src/services/refactoring/framework/refactoring_producer.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,8 +82,8 @@ abstract class RefactoringProducer {
8282
bool get supportsFileCreation {
8383
var capabilities = refactoringContext.clientCapabilities;
8484
return capabilities != null &&
85-
capabilities.documentChanges == true &&
86-
capabilities.createResourceOperations == true;
85+
capabilities.documentChanges &&
86+
capabilities.createResourceOperations;
8787
}
8888

8989
/// Return the title of this refactoring.

0 commit comments

Comments
 (0)