Skip to content

Commit 34e079e

Browse files
goderbauerCasey Hillers
authored and
Casey Hillers
committed
enable no_literal_bool_comparisons lint (flutter#126647)
1 parent 84413fd commit 34e079e

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+79
-79
lines changed

analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ linter:
127127
- no_duplicate_case_values
128128
- no_leading_underscores_for_library_prefixes
129129
- no_leading_underscores_for_local_identifiers
130-
# - no_literal_bool_comparisons # needs quick fix, https://github.com/dart-lang/linter/issues/4333
130+
- no_literal_bool_comparisons
131131
- no_logic_in_create_state
132132
# - no_runtimeType_toString # ok in tests; we enable this only in packages/
133133
- non_constant_identifier_names

dev/bots/test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -809,7 +809,7 @@ Future<void> _runFrameworkTests() async {
809809
final List<String> tests = Directory(path.join(flutterRoot, 'packages', 'flutter', 'test'))
810810
.listSync(followLinks: false)
811811
.whereType<Directory>()
812-
.where((Directory dir) => dir.path.endsWith('widgets') == false)
812+
.where((Directory dir) => !dir.path.endsWith('widgets'))
813813
.map<String>((Directory dir) => path.join('test', path.basename(dir.path)) + path.separator)
814814
.toList();
815815
printProgress('${green}Running packages/flutter tests$reset for $cyan${tests.join(", ")}$reset');

dev/conductor/core/lib/src/codesign.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ class CodesignCommand extends Command<void> {
9999
);
100100
}
101101

102-
if (argResults!['verify'] as bool != true) {
102+
if (!(argResults!['verify'] as bool)) {
103103
throw ConductorException(
104104
'Sorry, but codesigning is not implemented yet. Please pass the '
105105
'--$kVerify flag to verify signatures.',

dev/conductor/core/lib/src/next.dart

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ class NextContext extends Context {
128128
stdio.printStatus('These must be applied manually in the directory '
129129
'${state.engine.checkoutPath} before proceeding.\n');
130130
}
131-
if (autoAccept == false) {
131+
if (!autoAccept) {
132132
final bool response = await prompt(
133133
'Are you ready to push your engine branch to the repository '
134134
'${state.engine.mirror.url}?',
@@ -146,7 +146,7 @@ class NextContext extends Context {
146146
'You must validate pre-submit CI for your engine PR, merge it, and codesign',
147147
'binaries before proceeding.\n',
148148
].join('\n'));
149-
if (autoAccept == false) {
149+
if (!autoAccept) {
150150
// TODO(fujino): actually test if binaries have been codesigned on macOS
151151
final bool response = await prompt(
152152
'Has CI passed for the engine PR and binaries been codesigned?',
@@ -236,7 +236,7 @@ class NextContext extends Context {
236236
);
237237
}
238238

239-
if (autoAccept == false) {
239+
if (!autoAccept) {
240240
final bool response = await prompt(
241241
'Are you ready to push your framework branch to the repository '
242242
'${state.framework.mirror.url}?',
@@ -276,7 +276,7 @@ class NextContext extends Context {
276276
previousCheckoutLocation: state.engine.checkoutPath,
277277
);
278278
final String engineHead = await engine.reverseParse('HEAD');
279-
if (autoAccept == false) {
279+
if (!autoAccept) {
280280
final bool response = await prompt(
281281
'Are you ready to tag commit $frameworkHead as ${state.releaseVersion}\n'
282282
'and push to remote ${state.framework.upstream.url}?',
@@ -302,7 +302,7 @@ class NextContext extends Context {
302302
previousCheckoutLocation: state.framework.checkoutPath,
303303
);
304304
final String headRevision = await framework.reverseParse('HEAD');
305-
if (autoAccept == false) {
305+
if (!autoAccept) {
306306
// dryRun: true means print out git command
307307
await framework.pushRef(
308308
fromRef: headRevision,
@@ -332,7 +332,7 @@ class NextContext extends Context {
332332
'The current status of packaging builds can be seen at:\n'
333333
'\t$kLuciPackagingConsoleLink',
334334
);
335-
if (autoAccept == false) {
335+
if (!autoAccept) {
336336
final bool response = await prompt(
337337
'Have all packaging builds finished successfully and post release announcements been completed?');
338338
if (!response) {
@@ -373,7 +373,7 @@ class NextContext extends Context {
373373
force: force,
374374
);
375375
} on GitException catch (exception) {
376-
if (exception.type == GitExceptionType.PushRejected && force == false) {
376+
if (exception.type == GitExceptionType.PushRejected && !force) {
377377
throw ConductorException(
378378
'Push failed because the working branch named '
379379
'${pbRepository.workingBranch} already exists on your mirror. '

dev/devicelab/bin/run.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ Future<void> _runABTest({
176176

177177
abTest.addBResult(localEngineResult);
178178

179-
if (silent != true && i < runsPerTest) {
179+
if (!silent && i < runsPerTest) {
180180
section('A/B results so far');
181181
print(abTest.printSummary());
182182
}
@@ -186,7 +186,7 @@ Future<void> _runABTest({
186186
final File jsonFile = _uniqueFile(resultsFile);
187187
jsonFile.writeAsStringSync(const JsonEncoder.withIndent(' ').convert(abTest.jsonMap));
188188

189-
if (silent != true) {
189+
if (!silent) {
190190
section('Raw results');
191191
print(abTest.rawResults());
192192
}

packages/flutter/lib/src/cupertino/nav_bar.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ class CupertinoSliverNavigationBar extends StatefulWidget {
602602
this.heroTag = _defaultHeroTag,
603603
this.stretch = false,
604604
}) : assert(
605-
automaticallyImplyTitle == true || largeTitle != null,
605+
automaticallyImplyTitle || largeTitle != null,
606606
'No largeTitle has been provided but automaticallyImplyTitle is also '
607607
'false. Either provide a largeTitle or set automaticallyImplyTitle to '
608608
'true.',

packages/flutter/lib/src/foundation/assertions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1009,7 +1009,7 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti
10091009
isInDebugMode = true;
10101010
return true;
10111011
}());
1012-
final bool reportError = isInDebugMode || details.silent != true; // could be null
1012+
final bool reportError = isInDebugMode || !details.silent; // could be null
10131013
if (!reportError && !forceReport) {
10141014
return;
10151015
}

packages/flutter/lib/src/foundation/diagnostics.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1616,7 +1616,7 @@ abstract class DiagnosticsNode {
16161616
'showSeparator': showSeparator,
16171617
if (level != DiagnosticLevel.info)
16181618
'level': level.name,
1619-
if (showName == false)
1619+
if (!showName)
16201620
'showName': showName,
16211621
if (emptyBodyDescription != null)
16221622
'emptyBodyDescription': emptyBodyDescription,

packages/flutter/lib/src/gestures/events.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,9 @@ int smallestButton(int buttons) => buttons & (-buttons);
205205
/// Example:
206206
///
207207
/// ```dart
208-
/// assert(isSingleButton(0x1) == true);
209-
/// assert(isSingleButton(0x11) == false);
210-
/// assert(isSingleButton(0) == false);
208+
/// assert(isSingleButton(0x1));
209+
/// assert(!isSingleButton(0x11));
210+
/// assert(!isSingleButton(0));
211211
/// ```
212212
///
213213
/// See also:

packages/flutter/lib/src/gestures/long_press.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ class LongPressGestureRecognizer extends PrimaryPointerGestureRecognizer {
629629
}
630630

631631
if (event is PointerUpEvent) {
632-
if (_longPressAccepted == true) {
632+
if (_longPressAccepted) {
633633
_checkLongPressEnd(event);
634634
} else {
635635
// Pointer is lifted before timeout.

packages/flutter/lib/src/gestures/multitap.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ class DoubleTapGestureRecognizer extends GestureRecognizer {
208208

209209
// If second tap is not allowed, reset the state.
210210
final bool isPointerAllowed = super.isPointerAllowed(event);
211-
if (isPointerAllowed == false) {
211+
if (!isPointerAllowed) {
212212
_reset();
213213
}
214214
return isPointerAllowed;

packages/flutter/lib/src/material/chip.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -875,7 +875,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
875875
setMaterialState(MaterialState.selected, widget.selected);
876876
selectController = AnimationController(
877877
duration: _kSelectDuration,
878-
value: widget.selected == true ? 1.0 : 0.0,
878+
value: widget.selected ? 1.0 : 0.0,
879879
vsync: this,
880880
);
881881
selectionFade = CurvedAnimation(
@@ -884,7 +884,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
884884
);
885885
avatarDrawerController = AnimationController(
886886
duration: _kDrawerDuration,
887-
value: hasAvatar || widget.selected == true ? 1.0 : 0.0,
887+
value: hasAvatar || widget.selected ? 1.0 : 0.0,
888888
vsync: this,
889889
);
890890
deleteDrawerController = AnimationController(
@@ -1042,7 +1042,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
10421042
}
10431043
if (oldWidget.avatar != widget.avatar || oldWidget.selected != widget.selected) {
10441044
setState(() {
1045-
if (hasAvatar || widget.selected == true) {
1045+
if (hasAvatar || widget.selected) {
10461046
avatarDrawerController.forward();
10471047
} else {
10481048
avatarDrawerController.reverse();
@@ -1052,7 +1052,7 @@ class _RawChipState extends State<RawChip> with MaterialStateMixin, TickerProvid
10521052
if (oldWidget.selected != widget.selected) {
10531053
setState(() {
10541054
setMaterialState(MaterialState.selected, widget.selected);
1055-
if (widget.selected == true) {
1055+
if (widget.selected) {
10561056
selectController.forward();
10571057
} else {
10581058
selectController.reverse();
@@ -1979,7 +1979,7 @@ class _RenderChip extends RenderBox with SlottedContainerRenderObjectMixin<_Chip
19791979
_paintSelectionOverlay(context, offset);
19801980
}
19811981

1982-
if (theme.showAvatar == false && avatarDrawerAnimation.isDismissed) {
1982+
if (!theme.showAvatar && avatarDrawerAnimation.isDismissed) {
19831983
return;
19841984
}
19851985
final Color disabledColor = _disabledColor;

packages/flutter/lib/src/material/selectable_text.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,7 +607,7 @@ class _SelectableTextState extends State<SelectableText> implements TextSelectio
607607
assert(debugCheckHasMediaQuery(context));
608608
assert(debugCheckHasDirectionality(context));
609609
assert(
610-
!(widget.style != null && widget.style!.inherit == false &&
610+
!(widget.style != null && !widget.style!.inherit &&
611611
(widget.style!.fontSize == null || widget.style!.textBaseline == null)),
612612
'inherit false style must supply fontSize and textBaseline',
613613
);

packages/flutter/lib/src/material/slider_theme.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2335,7 +2335,7 @@ class RoundSliderThumbShape extends SliderComponentShape {
23352335

23362336
@override
23372337
Size getPreferredSize(bool isEnabled, bool isDiscrete) {
2338-
return Size.fromRadius(isEnabled == true ? enabledThumbRadius : _disabledThumbRadius);
2338+
return Size.fromRadius(isEnabled ? enabledThumbRadius : _disabledThumbRadius);
23392339
}
23402340

23412341
@override
@@ -2444,7 +2444,7 @@ class RoundRangeSliderThumbShape extends RangeSliderThumbShape {
24442444

24452445
@override
24462446
Size getPreferredSize(bool isEnabled, bool isDiscrete) {
2447-
return Size.fromRadius(isEnabled == true ? enabledThumbRadius : _disabledThumbRadius);
2447+
return Size.fromRadius(isEnabled ? enabledThumbRadius : _disabledThumbRadius);
24482448
}
24492449

24502450
@override

packages/flutter/lib/src/material/text_field.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1234,7 +1234,7 @@ class _TextFieldState extends State<TextField> with RestorationMixin implements
12341234
assert(debugCheckHasMaterialLocalizations(context));
12351235
assert(debugCheckHasDirectionality(context));
12361236
assert(
1237-
!(widget.style != null && widget.style!.inherit == false &&
1237+
!(widget.style != null && !widget.style!.inherit &&
12381238
(widget.style!.fontSize == null || widget.style!.textBaseline == null)),
12391239
'inherit false style must supply fontSize and textBaseline',
12401240
);

packages/flutter/lib/src/painting/debug.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ bool debugAssertAllPaintingVarsUnset(String reason, { bool debugDisableShadowsOv
185185
if (debugDisableShadows != debugDisableShadowsOverride ||
186186
debugNetworkImageHttpClientProvider != null ||
187187
debugOnPaintImage != null ||
188-
debugInvertOversizedImages == true ||
188+
debugInvertOversizedImages ||
189189
debugImageOverheadAllowance != _imageOverheadAllowanceDefault) {
190190
throw FlutterError(reason);
191191
}

packages/flutter/lib/src/painting/inline_span.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ class InlineSpanSemanticsInformation {
6060
this.semanticsLabel,
6161
this.stringAttributes = const <ui.StringAttribute>[],
6262
this.recognizer,
63-
}) : assert(isPlaceholder == false || (text == '\uFFFC' && semanticsLabel == null && recognizer == null)),
63+
}) : assert(!isPlaceholder || (text == '\uFFFC' && semanticsLabel == null && recognizer == null)),
6464
requiresOwnNode = isPlaceholder || recognizer != null;
6565

6666
/// The text info for a [PlaceholderSpan].

packages/flutter/lib/src/rendering/sliver_multi_box_adaptor.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class SliverMultiBoxAdaptorParentData extends SliverLogicalParentData with Conta
151151
bool _keptAlive = false;
152152

153153
@override
154-
String toString() => 'index=$index; ${keepAlive == true ? "keepAlive; " : ""}${super.toString()}';
154+
String toString() => 'index=$index; ${keepAlive ? "keepAlive; " : ""}${super.toString()}';
155155
}
156156

157157
/// A sliver with multiple box children.

packages/flutter/lib/src/services/platform_views.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1158,10 +1158,10 @@ abstract class _AndroidViewControllerInternals {
11581158
'id': viewId,
11591159
'viewType': viewType,
11601160
'direction': AndroidViewController._getAndroidDirection(layoutDirection),
1161-
if (hybrid == true) 'hybrid': hybrid,
1161+
if (hybrid) 'hybrid': hybrid,
11621162
if (size != null) 'width': size.width,
11631163
if (size != null) 'height': size.height,
1164-
if (hybridFallback == true) 'hybridFallback': hybridFallback,
1164+
if (hybridFallback) 'hybridFallback': hybridFallback,
11651165
if (position != null) 'left': position.dx,
11661166
if (position != null) 'top': position.dy,
11671167
};

packages/flutter/lib/src/widgets/actions.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,7 @@ class Actions extends StatefulWidget {
690690
static bool _visitActionsAncestors(BuildContext context, bool Function(InheritedElement element) visitor) {
691691
InheritedElement? actionsElement = context.getElementForInheritedWidgetOfExactType<_ActionsScope>();
692692
while (actionsElement != null) {
693-
if (visitor(actionsElement) == true) {
693+
if (visitor(actionsElement)) {
694694
break;
695695
}
696696
// _getParent is needed here because

packages/flutter/lib/src/widgets/routes.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1499,7 +1499,7 @@ abstract class ModalRoute<T> extends TransitionRoute<T> with LocalHistoryRoute<T
14991499
final _ModalScopeState<T>? scope = _scopeKey.currentState;
15001500
assert(scope != null);
15011501
for (final WillPopCallback callback in List<WillPopCallback>.of(_willPopCallbacks)) {
1502-
if (await callback() != true) {
1502+
if (!await callback()) {
15031503
return RoutePopDisposition.doNotPop;
15041504
}
15051505
}

packages/flutter/lib/src/widgets/visibility.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -64,19 +64,19 @@ class Visibility extends StatelessWidget {
6464
this.maintainSemantics = false,
6565
this.maintainInteractivity = false,
6666
}) : assert(
67-
maintainState == true || maintainAnimation == false,
67+
maintainState || !maintainAnimation,
6868
'Cannot maintain animations if the state is not also maintained.',
6969
),
7070
assert(
71-
maintainAnimation == true || maintainSize == false,
71+
maintainAnimation || !maintainSize,
7272
'Cannot maintain size if animations are not maintained.',
7373
),
7474
assert(
75-
maintainSize == true || maintainSemantics == false,
75+
maintainSize || !maintainSemantics,
7676
'Cannot maintain semantics if size is not maintained.',
7777
),
7878
assert(
79-
maintainSize == true || maintainInteractivity == false,
79+
maintainSize || !maintainInteractivity,
8080
'Cannot maintain interactivity if size is not maintained.',
8181
);
8282

@@ -354,19 +354,19 @@ class SliverVisibility extends StatelessWidget {
354354
this.maintainSemantics = false,
355355
this.maintainInteractivity = false,
356356
}) : assert(
357-
maintainState == true || maintainAnimation == false,
357+
maintainState || !maintainAnimation,
358358
'Cannot maintain animations if the state is not also maintained.',
359359
),
360360
assert(
361-
maintainAnimation == true || maintainSize == false,
361+
maintainAnimation || !maintainSize,
362362
'Cannot maintain size if animations are not maintained.',
363363
),
364364
assert(
365-
maintainSize == true || maintainSemantics == false,
365+
maintainSize || !maintainSemantics,
366366
'Cannot maintain semantics if size is not maintained.',
367367
),
368368
assert(
369-
maintainSize == true || maintainInteractivity == false,
369+
maintainSize || !maintainInteractivity,
370370
'Cannot maintain interactivity if size is not maintained.',
371371
);
372372

packages/flutter/lib/src/widgets/widget_inspector.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3010,7 +3010,7 @@ class _InspectorOverlayLayer extends Layer {
30103010
inDebugMode = true;
30113011
return true;
30123012
}());
3013-
if (inDebugMode == false) {
3013+
if (!inDebugMode) {
30143014
throw FlutterError.fromParts(<DiagnosticsNode>[
30153015
ErrorSummary(
30163016
'The inspector should never be used in production mode due to the '
@@ -3627,7 +3627,7 @@ class InspectorSerializationDelegate implements DiagnosticsSerializationDelegate
36273627
@override
36283628
List<DiagnosticsNode> truncateNodesList(List<DiagnosticsNode> nodes, DiagnosticsNode? owner) {
36293629
if (maxDescendantsTruncatableNode >= 0 &&
3630-
owner!.allowTruncate == true &&
3630+
owner!.allowTruncate &&
36313631
nodes.length > maxDescendantsTruncatableNode) {
36323632
nodes = service._truncateNodes(nodes, maxDescendantsTruncatableNode);
36333633
}

packages/flutter/test/widgets/image_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2182,7 +2182,7 @@ class _FailingImageProvider extends ImageProvider<int> {
21822182
this.failOnLoad = false,
21832183
required this.throws,
21842184
required this.image,
2185-
}) : assert(failOnLoad == true || failOnObtainKey == true);
2185+
}) : assert(failOnLoad || failOnObtainKey);
21862186

21872187
final bool failOnObtainKey;
21882188
final bool failOnLoad;

packages/flutter_test/lib/src/widget_tester.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ void testWidgets(
149149
tester._testDescription = combinedDescription;
150150
SemanticsHandle? semanticsHandle;
151151
tester._recordNumberOfSemanticsHandles();
152-
if (semanticsEnabled == true) {
152+
if (semanticsEnabled) {
153153
semanticsHandle = tester.ensureSemantics();
154154
}
155155
test_package.addTearDown(binding.postTest);
@@ -420,7 +420,7 @@ Future<void> benchmarkWidgets(
420420
assert(binding is! AutomatedTestWidgetsFlutterBinding);
421421
final WidgetTester tester = WidgetTester._(binding);
422422
SemanticsHandle? semanticsHandle;
423-
if (semanticsEnabled == true) {
423+
if (semanticsEnabled) {
424424
semanticsHandle = tester.ensureSemantics();
425425
}
426426
tester._recordNumberOfSemanticsHandles();

0 commit comments

Comments
 (0)