Skip to content

Commit 515a482

Browse files
scheglovCommit Queue
authored andcommitted
Enable no_literal_bool_comparisons in the analyzer.
Change-Id: Ib6d534331ab91fe03f9d8292c2aa946d5599387a Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/440202 Reviewed-by: Paul Berry <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
1 parent 32124f2 commit 515a482

File tree

8 files changed

+9
-11
lines changed

8 files changed

+9
-11
lines changed

pkg/analyzer/analysis_options.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ linter:
5555
- avoid_unused_constructor_parameters
5656
- discarded_futures
5757
- flutter_style_todos
58+
- no_literal_bool_comparisons
5859
- unawaited_futures
5960
- unnecessary_breaks
6061
- unnecessary_final

pkg/analyzer/lib/src/dart/analysis/search.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1752,7 +1752,7 @@ class _LocalReferencesVisitor extends RecursiveAstVisitor<void> {
17521752
}
17531753

17541754
void _addResult(SyntacticEntity entity, SearchResultKind kind) {
1755-
bool isQualified = entity is AstNode ? entity.parent is Label : false;
1755+
bool isQualified = entity is AstNode && entity.parent is Label;
17561756
var enclosingFragment = _getEnclosingFragment(
17571757
enclosingLibraryFragment,
17581758
entity.offset,

pkg/analyzer/lib/src/dart/ast/constant_evaluator.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class ConstantEvaluator extends GeneralizingAstVisitor<Object> {
244244
}
245245

246246
@override
247-
Object? visitBooleanLiteral(BooleanLiteral node) => node.value ? true : false;
247+
Object? visitBooleanLiteral(BooleanLiteral node) => node.value;
248248

249249
@override
250250
Object? visitDoubleLiteral(DoubleLiteral node) => node.value;

pkg/analyzer/lib/src/dart/constant/evaluation.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ class ConstantVisitor extends UnifyingAstVisitor<Constant> {
695695
}
696696
return _dartObjectComputer.lazyOr(node, leftResult, computeRightOperand);
697697
} else if (operatorType == TokenType.QUESTION_QUESTION) {
698-
if (leftResult.isNull != true) {
698+
if (!leftResult.isNull) {
699699
var error = _reportNotPotentialConstants(node.rightOperand);
700700
if (error is InvalidConstant) {
701701
return error;

pkg/analyzer/lib/src/dart/element/type_algebra.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ abstract class _TypeSubstitutor
369369
int useCounter = 0;
370370

371371
_TypeSubstitutor(this.outer) {
372-
covariantContext = outer == null ? true : outer!.covariantContext;
372+
covariantContext = outer == null || outer!.covariantContext;
373373
}
374374

375375
void bumpCountersUntil(_TypeSubstitutor target) {

pkg/analyzer/lib/src/error/null_safe_api_verifier.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class NullSafeApiVerifier {
5050

5151
var targetClass = targetType.element;
5252

53-
if (targetClass.library.isDartAsync == true &&
53+
if (targetClass.library.isDartAsync &&
5454
targetClass.name == 'Completer' &&
5555
node.methodName.name == 'complete') {
5656
_checkTypes(

pkg/analyzer/lib/src/fasta/doc_comment_builder.dart

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -929,9 +929,7 @@ final class _BlockDocDirectiveBuilder {
929929
/// Whether this doc directive's opening tag is the opposing tag for [tag].
930930
bool matches(DocDirectiveTag tag) {
931931
var openingTag = this.openingTag;
932-
return openingTag == null
933-
? false
934-
: openingTag.type.opposingName == tag.type.name;
932+
return openingTag != null && openingTag.type.opposingName == tag.type.name;
935933
}
936934

937935
void push(DocDirective docDirective) => innerDocDirectives.add(docDirective);

pkg/analyzer/lib/src/generated/ffi_verifier.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1376,9 +1376,8 @@ class FfiVerifier extends RecursiveAstVisitor<void> {
13761376
} else if (nativeReturnType == _PrimitiveDartType.bool) {
13771377
return dartType.isDartCoreBool;
13781378
} else if (nativeReturnType == _PrimitiveDartType.void_) {
1379-
return direction == _FfiTypeCheckDirection.dartToNative
1380-
? true
1381-
: dartType is VoidType;
1379+
return direction == _FfiTypeCheckDirection.dartToNative ||
1380+
dartType is VoidType;
13821381
} else if (dartType is VoidType) {
13831382
// Don't allow other native subtypes if the Dart return type is void.
13841383
return nativeReturnType == _PrimitiveDartType.void_;

0 commit comments

Comments
 (0)