enable lint avoid_bool_literals_in_conditional_expressions (#35055)
diff --git a/analysis_options.yaml b/analysis_options.yaml index 53084f2..d252227 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml
@@ -52,7 +52,7 @@ - annotate_overrides # - avoid_annotating_with_dynamic # conflicts with always_specify_types - avoid_as - # - avoid_bool_literals_in_conditional_expressions # not yet tested + - avoid_bool_literals_in_conditional_expressions # - avoid_catches_without_on_clauses # we do this commonly # - avoid_catching_errors # we do this commonly - avoid_classes_with_only_static_members
diff --git a/dev/bots/analyze-sample-code.dart b/dev/bots/analyze-sample-code.dart index 6304d49..f26fc54 100644 --- a/dev/bots/analyze-sample-code.dart +++ b/dev/bots/analyze-sample-code.dart
@@ -430,7 +430,7 @@ startLine = Line('', filename: relativeFilePath, line: lineNumber + 1, indent: 3); inPreamble = true; } else if (sampleMatch != null) { - inSnippet = sampleMatch != null ? sampleMatch[1] == 'snippet' : false; + inSnippet = sampleMatch != null && sampleMatch[1] == 'snippet'; if (inSnippet) { startLine = Line( '',
diff --git a/examples/flutter_gallery/lib/demo/material/chip_demo.dart b/examples/flutter_gallery/lib/demo/material/chip_demo.dart index 38f5fb1..6c464db 100644 --- a/examples/flutter_gallery/lib/demo/material/chip_demo.dart +++ b/examples/flutter_gallery/lib/demo/material/chip_demo.dart
@@ -247,7 +247,7 @@ return FilterChip( key: ValueKey<String>(name), label: Text(_capitalize(name)), - selected: _tools.contains(name) ? _selectedTools.contains(name) : false, + selected: _tools.contains(name) && _selectedTools.contains(name), onSelected: !_tools.contains(name) ? null : (bool value) {
diff --git a/packages/flutter/lib/src/cupertino/route.dart b/packages/flutter/lib/src/cupertino/route.dart index 42bbc4d..0ae5b46 100644 --- a/packages/flutter/lib/src/cupertino/route.dart +++ b/packages/flutter/lib/src/cupertino/route.dart
@@ -618,9 +618,9 @@ // or after mid screen, we should animate the page out. Otherwise, the page // should be animated back in. if (velocity.abs() >= _kMinFlingVelocity) - animateForward = velocity > 0 ? false : true; + animateForward = velocity <= 0; else - animateForward = controller.value > 0.5 ? true : false; + animateForward = controller.value > 0.5; if (animateForward) { // The closer the panel is to dismissing, the shorter the animation is.
diff --git a/packages/flutter/lib/src/foundation/diagnostics.dart b/packages/flutter/lib/src/foundation/diagnostics.dart index 72278b3..40cb508 100644 --- a/packages/flutter/lib/src/foundation/diagnostics.dart +++ b/packages/flutter/lib/src/foundation/diagnostics.dart
@@ -1469,7 +1469,7 @@ /// /// If `minLevel` is [DiagnosticLevel.hidden] no diagnostics will be filtered. /// If `minLevel` is [DiagnosticLevel.off] all diagnostics will be filtered. - bool isFiltered(DiagnosticLevel minLevel) => kReleaseMode ? true : level.index < minLevel.index; + bool isFiltered(DiagnosticLevel minLevel) => kReleaseMode || level.index < minLevel.index; /// Priority level of the diagnostic used to control which diagnostics should /// be shown and filtered.
diff --git a/packages/flutter/lib/src/material/bottom_navigation_bar.dart b/packages/flutter/lib/src/material/bottom_navigation_bar.dart index 7ab9acd..1d6ec1a 100644 --- a/packages/flutter/lib/src/material/bottom_navigation_bar.dart +++ b/packages/flutter/lib/src/material/bottom_navigation_bar.dart
@@ -197,7 +197,7 @@ assert(elevation != null && elevation >= 0.0), assert(iconSize != null && iconSize >= 0.0), assert( - selectedItemColor != null ? fixedColor == null : true, + selectedItemColor == null || fixedColor == null, 'Either selectedItemColor or fixedColor can be specified, but not both' ), assert(selectedFontSize != null && selectedFontSize >= 0.0),
diff --git a/packages/flutter/lib/src/material/chip.dart b/packages/flutter/lib/src/material/chip.dart index ebdeed2..b093f60 100644 --- a/packages/flutter/lib/src/material/chip.dart +++ b/packages/flutter/lib/src/material/chip.dart
@@ -1410,7 +1410,7 @@ } bool _isTapping = false; - bool get isTapping => !canTap ? false : _isTapping; + bool get isTapping => canTap && _isTapping; @override void initState() {
diff --git a/packages/flutter/lib/src/material/data_table.dart b/packages/flutter/lib/src/material/data_table.dart index c16ebe5..47ad31f 100644 --- a/packages/flutter/lib/src/material/data_table.dart +++ b/packages/flutter/lib/src/material/data_table.dart
@@ -616,7 +616,7 @@ label: column.label, tooltip: column.tooltip, numeric: column.numeric, - onSort: () => column.onSort != null ? column.onSort(dataColumnIndex, sortColumnIndex == dataColumnIndex ? !sortAscending : true) : null, + onSort: () => column.onSort != null ? column.onSort(dataColumnIndex, sortColumnIndex != dataColumnIndex || !sortAscending) : null, sorted: dataColumnIndex == sortColumnIndex, ascending: sortAscending, );
diff --git a/packages/flutter/lib/src/material/drawer.dart b/packages/flutter/lib/src/material/drawer.dart index ab052c7..3e52124 100644 --- a/packages/flutter/lib/src/material/drawer.dart +++ b/packages/flutter/lib/src/material/drawer.dart
@@ -346,7 +346,7 @@ break; } - final bool opened = _controller.value > 0.5 ? true : false; + final bool opened = _controller.value > 0.5; if (opened != _previouslyOpened && widget.drawerCallback != null) widget.drawerCallback(opened); _previouslyOpened = opened;
diff --git a/packages/flutter/lib/src/material/scaffold.dart b/packages/flutter/lib/src/material/scaffold.dart index 8170c32..f74e35b 100644 --- a/packages/flutter/lib/src/material/scaffold.dart +++ b/packages/flutter/lib/src/material/scaffold.dart
@@ -2173,7 +2173,7 @@ ); // extendBody locked when keyboard is open - final bool _extendBody = minInsets.bottom > 0 ? false : widget.extendBody; + final bool _extendBody = minInsets.bottom <= 0 && widget.extendBody; return _ScaffoldScope( hasDrawer: hasDrawer,
diff --git a/packages/flutter/lib/src/material/tab_controller.dart b/packages/flutter/lib/src/material/tab_controller.dart index 6390bbd..c7da646 100644 --- a/packages/flutter/lib/src/material/tab_controller.dart +++ b/packages/flutter/lib/src/material/tab_controller.dart
@@ -150,7 +150,7 @@ void _changeIndex(int value, { Duration duration, Curve curve }) { assert(value != null); assert(value >= 0 && (value < length || length == 0)); - assert(duration == null ? curve == null : true); + assert(duration != null || curve == null); assert(_indexIsChangingCount >= 0); if (value == _index || length < 2) return;
diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index cef3bfb..6471cae 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart
@@ -2969,7 +2969,7 @@ @override bool hitTest(BoxHitTestResult result, { Offset position }) { - return ignoring ? false : super.hitTest(result, position: position); + return !ignoring && super.hitTest(result, position: position); } // TODO(ianh): figure out a way to still include labels and flags in
diff --git a/packages/flutter/lib/src/services/text_input.dart b/packages/flutter/lib/src/services/text_input.dart index 9e760a4..6c67b93 100644 --- a/packages/flutter/lib/src/services/text_input.dart +++ b/packages/flutter/lib/src/services/text_input.dart
@@ -469,7 +469,7 @@ this.offset, @required this.state, }) : assert(state != null), - assert(state == FloatingCursorDragState.Update ? offset != null : true); + assert(state != FloatingCursorDragState.Update || offset != null); /// The raw position of the floating cursor as determined by the iOS sdk. final Offset offset;
diff --git a/packages/flutter/lib/src/widgets/dismissible.dart b/packages/flutter/lib/src/widgets/dismissible.dart index a95475a..84c21e3 100644 --- a/packages/flutter/lib/src/widgets/dismissible.dart +++ b/packages/flutter/lib/src/widgets/dismissible.dart
@@ -95,7 +95,7 @@ this.crossAxisEndOffset = 0.0, this.dragStartBehavior = DragStartBehavior.start, }) : assert(key != null), - assert(secondaryBackground != null ? background != null : true), + assert(secondaryBackground == null || background != null), assert(dragStartBehavior != null), super(key: key);
diff --git a/packages/flutter/lib/src/widgets/widget_span.dart b/packages/flutter/lib/src/widgets/widget_span.dart index a24c04a..3cac58e 100644 --- a/packages/flutter/lib/src/widgets/widget_span.dart +++ b/packages/flutter/lib/src/widgets/widget_span.dart
@@ -75,9 +75,11 @@ TextBaseline baseline, TextStyle style, }) : assert(child != null), - assert((identical(alignment, ui.PlaceholderAlignment.aboveBaseline) || - identical(alignment, ui.PlaceholderAlignment.belowBaseline) || - identical(alignment, ui.PlaceholderAlignment.baseline)) ? baseline != null : true), + assert(baseline != null || !( + identical(alignment, ui.PlaceholderAlignment.aboveBaseline) || + identical(alignment, ui.PlaceholderAlignment.belowBaseline) || + identical(alignment, ui.PlaceholderAlignment.baseline) + )), super( alignment: alignment, baseline: baseline,
diff --git a/packages/flutter/test/rendering/box_test.dart b/packages/flutter/test/rendering/box_test.dart index 0c22e4f..9fe5e15 100644 --- a/packages/flutter/test/rendering/box_test.dart +++ b/packages/flutter/test/rendering/box_test.dart
@@ -25,7 +25,7 @@ } @override - bool get hasSize => fakeMissingSize ? false : super.hasSize; + bool get hasSize => !fakeMissingSize && super.hasSize; bool fakeMissingSize = false; }
diff --git a/packages/flutter_localizations/test/override_test.dart b/packages/flutter_localizations/test/override_test.dart index a36f402..e650753 100644 --- a/packages/flutter_localizations/test/override_test.dart +++ b/packages/flutter_localizations/test/override_test.dart
@@ -37,7 +37,7 @@ @override bool isSupported(Locale locale) { - return supportedLanguage == 'allLanguages' ? true : locale.languageCode == supportedLanguage; + return supportedLanguage == 'allLanguages' || locale.languageCode == supportedLanguage; } @override
diff --git a/packages/flutter_tools/lib/src/base/build.dart b/packages/flutter_tools/lib/src/base/build.dart index 5f6cb9d..fb85ba3 100644 --- a/packages/flutter_tools/lib/src/base/build.dart +++ b/packages/flutter_tools/lib/src/base/build.dart
@@ -175,7 +175,7 @@ 'entryPoint': mainPath, 'extraGenSnapshotOptions': extraGenSnapshotOptions.join(' '), 'engineHash': Cache.instance.engineRevision, - 'buildersUsed': '${flutterProject != null ? flutterProject.hasBuilders : false}', + 'buildersUsed': '${flutterProject != null && flutterProject.hasBuilders}', }, depfilePaths: <String>[], );
diff --git a/packages/flutter_tools/lib/src/base/io.dart b/packages/flutter_tools/lib/src/base/io.dart index 0250dbd..6e5468e 100644 --- a/packages/flutter_tools/lib/src/base/io.dart +++ b/packages/flutter_tools/lib/src/base/io.dart
@@ -163,7 +163,7 @@ bool get hasTerminal => io.stdout.hasTerminal; int get terminalColumns => hasTerminal ? io.stdout.terminalColumns : null; int get terminalLines => hasTerminal ? io.stdout.terminalLines : null; - bool get supportsAnsiEscapes => hasTerminal ? io.stdout.supportsAnsiEscapes : false; + bool get supportsAnsiEscapes => hasTerminal && io.stdout.supportsAnsiEscapes; } Stdio get stdio => context.get<Stdio>() ?? const Stdio();
diff --git a/packages/flutter_tools/lib/src/base/process.dart b/packages/flutter_tools/lib/src/base/process.dart index 0dab7e9..47b2949 100644 --- a/packages/flutter_tools/lib/src/base/process.dart +++ b/packages/flutter_tools/lib/src/base/process.dart
@@ -148,7 +148,7 @@ final StreamSubscription<String> stdoutSubscription = process.stdout .transform<String>(utf8.decoder) .transform<String>(const LineSplitter()) - .where((String line) => filter == null ? true : filter.hasMatch(line)) + .where((String line) => filter == null || filter.hasMatch(line)) .listen((String line) { if (mapFunction != null) line = mapFunction(line); @@ -163,7 +163,7 @@ final StreamSubscription<String> stderrSubscription = process.stderr .transform<String>(utf8.decoder) .transform<String>(const LineSplitter()) - .where((String line) => filter == null ? true : filter.hasMatch(line)) + .where((String line) => filter == null || filter.hasMatch(line)) .listen((String line) { if (mapFunction != null) line = mapFunction(line);
diff --git a/packages/flutter_tools/lib/src/compile.dart b/packages/flutter_tools/lib/src/compile.dart index 89a03af..0a577a1 100644 --- a/packages/flutter_tools/lib/src/compile.dart +++ b/packages/flutter_tools/lib/src/compile.dart
@@ -246,7 +246,7 @@ 'trackWidgetCreation': trackWidgetCreation.toString(), 'linkPlatformKernelIn': linkPlatformKernelIn.toString(), 'engineHash': Cache.instance.engineRevision, - 'buildersUsed': '${flutterProject != null ? flutterProject.hasBuilders : false}', + 'buildersUsed': '${flutterProject != null && flutterProject.hasBuilders}', }, depfilePaths: <String>[depFilePath], pathFilter: (String path) => !path.startsWith('/b/build/slave/'),