Unverified Commit fecf99ff authored by Alexandre Ardhuin's avatar Alexandre Ardhuin Committed by GitHub

enable lint avoid_bool_literals_in_conditional_expressions (#35055)

parent 9a3a7490
...@@ -52,7 +52,7 @@ linter: ...@@ -52,7 +52,7 @@ linter:
- annotate_overrides - annotate_overrides
# - avoid_annotating_with_dynamic # conflicts with always_specify_types # - avoid_annotating_with_dynamic # conflicts with always_specify_types
- avoid_as - 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_catches_without_on_clauses # we do this commonly
# - avoid_catching_errors # we do this commonly # - avoid_catching_errors # we do this commonly
- avoid_classes_with_only_static_members - avoid_classes_with_only_static_members
......
...@@ -430,7 +430,7 @@ class SampleChecker { ...@@ -430,7 +430,7 @@ class SampleChecker {
startLine = Line('', filename: relativeFilePath, line: lineNumber + 1, indent: 3); startLine = Line('', filename: relativeFilePath, line: lineNumber + 1, indent: 3);
inPreamble = true; inPreamble = true;
} else if (sampleMatch != null) { } else if (sampleMatch != null) {
inSnippet = sampleMatch != null ? sampleMatch[1] == 'snippet' : false; inSnippet = sampleMatch != null && sampleMatch[1] == 'snippet';
if (inSnippet) { if (inSnippet) {
startLine = Line( startLine = Line(
'', '',
......
...@@ -247,7 +247,7 @@ class _ChipDemoState extends State<ChipDemo> { ...@@ -247,7 +247,7 @@ class _ChipDemoState extends State<ChipDemo> {
return FilterChip( return FilterChip(
key: ValueKey<String>(name), key: ValueKey<String>(name),
label: Text(_capitalize(name)), label: Text(_capitalize(name)),
selected: _tools.contains(name) ? _selectedTools.contains(name) : false, selected: _tools.contains(name) && _selectedTools.contains(name),
onSelected: !_tools.contains(name) onSelected: !_tools.contains(name)
? null ? null
: (bool value) { : (bool value) {
......
...@@ -618,9 +618,9 @@ class _CupertinoBackGestureController<T> { ...@@ -618,9 +618,9 @@ class _CupertinoBackGestureController<T> {
// or after mid screen, we should animate the page out. Otherwise, the page // or after mid screen, we should animate the page out. Otherwise, the page
// should be animated back in. // should be animated back in.
if (velocity.abs() >= _kMinFlingVelocity) if (velocity.abs() >= _kMinFlingVelocity)
animateForward = velocity > 0 ? false : true; animateForward = velocity <= 0;
else else
animateForward = controller.value > 0.5 ? true : false; animateForward = controller.value > 0.5;
if (animateForward) { if (animateForward) {
// The closer the panel is to dismissing, the shorter the animation is. // The closer the panel is to dismissing, the shorter the animation is.
......
...@@ -1469,7 +1469,7 @@ abstract class DiagnosticsNode { ...@@ -1469,7 +1469,7 @@ abstract class DiagnosticsNode {
/// ///
/// If `minLevel` is [DiagnosticLevel.hidden] no diagnostics will be filtered. /// If `minLevel` is [DiagnosticLevel.hidden] no diagnostics will be filtered.
/// If `minLevel` is [DiagnosticLevel.off] all 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 /// Priority level of the diagnostic used to control which diagnostics should
/// be shown and filtered. /// be shown and filtered.
......
...@@ -197,7 +197,7 @@ class BottomNavigationBar extends StatefulWidget { ...@@ -197,7 +197,7 @@ class BottomNavigationBar extends StatefulWidget {
assert(elevation != null && elevation >= 0.0), assert(elevation != null && elevation >= 0.0),
assert(iconSize != null && iconSize >= 0.0), assert(iconSize != null && iconSize >= 0.0),
assert( assert(
selectedItemColor != null ? fixedColor == null : true, selectedItemColor == null || fixedColor == null,
'Either selectedItemColor or fixedColor can be specified, but not both' 'Either selectedItemColor or fixedColor can be specified, but not both'
), ),
assert(selectedFontSize != null && selectedFontSize >= 0.0), assert(selectedFontSize != null && selectedFontSize >= 0.0),
......
...@@ -1410,7 +1410,7 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip ...@@ -1410,7 +1410,7 @@ class _RawChipState extends State<RawChip> with TickerProviderStateMixin<RawChip
} }
bool _isTapping = false; bool _isTapping = false;
bool get isTapping => !canTap ? false : _isTapping; bool get isTapping => canTap && _isTapping;
@override @override
void initState() { void initState() {
......
...@@ -616,7 +616,7 @@ class DataTable extends StatelessWidget { ...@@ -616,7 +616,7 @@ class DataTable extends StatelessWidget {
label: column.label, label: column.label,
tooltip: column.tooltip, tooltip: column.tooltip,
numeric: column.numeric, 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, sorted: dataColumnIndex == sortColumnIndex,
ascending: sortAscending, ascending: sortAscending,
); );
......
...@@ -346,7 +346,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro ...@@ -346,7 +346,7 @@ class DrawerControllerState extends State<DrawerController> with SingleTickerPro
break; break;
} }
final bool opened = _controller.value > 0.5 ? true : false; final bool opened = _controller.value > 0.5;
if (opened != _previouslyOpened && widget.drawerCallback != null) if (opened != _previouslyOpened && widget.drawerCallback != null)
widget.drawerCallback(opened); widget.drawerCallback(opened);
_previouslyOpened = opened; _previouslyOpened = opened;
......
...@@ -2173,7 +2173,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -2173,7 +2173,7 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
); );
// extendBody locked when keyboard is open // 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( return _ScaffoldScope(
hasDrawer: hasDrawer, hasDrawer: hasDrawer,
......
...@@ -150,7 +150,7 @@ class TabController extends ChangeNotifier { ...@@ -150,7 +150,7 @@ class TabController extends ChangeNotifier {
void _changeIndex(int value, { Duration duration, Curve curve }) { void _changeIndex(int value, { Duration duration, Curve curve }) {
assert(value != null); assert(value != null);
assert(value >= 0 && (value < length || length == 0)); assert(value >= 0 && (value < length || length == 0));
assert(duration == null ? curve == null : true); assert(duration != null || curve == null);
assert(_indexIsChangingCount >= 0); assert(_indexIsChangingCount >= 0);
if (value == _index || length < 2) if (value == _index || length < 2)
return; return;
......
...@@ -2969,7 +2969,7 @@ class RenderIgnorePointer extends RenderProxyBox { ...@@ -2969,7 +2969,7 @@ class RenderIgnorePointer extends RenderProxyBox {
@override @override
bool hitTest(BoxHitTestResult result, { Offset position }) { 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 // TODO(ianh): figure out a way to still include labels and flags in
......
...@@ -469,7 +469,7 @@ class RawFloatingCursorPoint { ...@@ -469,7 +469,7 @@ class RawFloatingCursorPoint {
this.offset, this.offset,
@required this.state, @required this.state,
}) : assert(state != null), }) : 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. /// The raw position of the floating cursor as determined by the iOS sdk.
final Offset offset; final Offset offset;
......
...@@ -95,7 +95,7 @@ class Dismissible extends StatefulWidget { ...@@ -95,7 +95,7 @@ class Dismissible extends StatefulWidget {
this.crossAxisEndOffset = 0.0, this.crossAxisEndOffset = 0.0,
this.dragStartBehavior = DragStartBehavior.start, this.dragStartBehavior = DragStartBehavior.start,
}) : assert(key != null), }) : assert(key != null),
assert(secondaryBackground != null ? background != null : true), assert(secondaryBackground == null || background != null),
assert(dragStartBehavior != null), assert(dragStartBehavior != null),
super(key: key); super(key: key);
......
...@@ -75,9 +75,11 @@ class WidgetSpan extends PlaceholderSpan { ...@@ -75,9 +75,11 @@ class WidgetSpan extends PlaceholderSpan {
TextBaseline baseline, TextBaseline baseline,
TextStyle style, TextStyle style,
}) : assert(child != null), }) : assert(child != null),
assert((identical(alignment, ui.PlaceholderAlignment.aboveBaseline) || assert(baseline != null || !(
identical(alignment, ui.PlaceholderAlignment.belowBaseline) || identical(alignment, ui.PlaceholderAlignment.aboveBaseline) ||
identical(alignment, ui.PlaceholderAlignment.baseline)) ? baseline != null : true), identical(alignment, ui.PlaceholderAlignment.belowBaseline) ||
identical(alignment, ui.PlaceholderAlignment.baseline)
)),
super( super(
alignment: alignment, alignment: alignment,
baseline: baseline, baseline: baseline,
......
...@@ -25,7 +25,7 @@ class FakeMissingSizeRenderBox extends RenderBox { ...@@ -25,7 +25,7 @@ class FakeMissingSizeRenderBox extends RenderBox {
} }
@override @override
bool get hasSize => fakeMissingSize ? false : super.hasSize; bool get hasSize => !fakeMissingSize && super.hasSize;
bool fakeMissingSize = false; bool fakeMissingSize = false;
} }
......
...@@ -37,7 +37,7 @@ class FooMaterialLocalizationsDelegate extends LocalizationsDelegate<MaterialLoc ...@@ -37,7 +37,7 @@ class FooMaterialLocalizationsDelegate extends LocalizationsDelegate<MaterialLoc
@override @override
bool isSupported(Locale locale) { bool isSupported(Locale locale) {
return supportedLanguage == 'allLanguages' ? true : locale.languageCode == supportedLanguage; return supportedLanguage == 'allLanguages' || locale.languageCode == supportedLanguage;
} }
@override @override
......
...@@ -175,7 +175,7 @@ class AOTSnapshotter { ...@@ -175,7 +175,7 @@ class AOTSnapshotter {
'entryPoint': mainPath, 'entryPoint': mainPath,
'extraGenSnapshotOptions': extraGenSnapshotOptions.join(' '), 'extraGenSnapshotOptions': extraGenSnapshotOptions.join(' '),
'engineHash': Cache.instance.engineRevision, 'engineHash': Cache.instance.engineRevision,
'buildersUsed': '${flutterProject != null ? flutterProject.hasBuilders : false}', 'buildersUsed': '${flutterProject != null && flutterProject.hasBuilders}',
}, },
depfilePaths: <String>[], depfilePaths: <String>[],
); );
......
...@@ -163,7 +163,7 @@ class Stdio { ...@@ -163,7 +163,7 @@ class Stdio {
bool get hasTerminal => io.stdout.hasTerminal; bool get hasTerminal => io.stdout.hasTerminal;
int get terminalColumns => hasTerminal ? io.stdout.terminalColumns : null; int get terminalColumns => hasTerminal ? io.stdout.terminalColumns : null;
int get terminalLines => hasTerminal ? io.stdout.terminalLines : 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(); Stdio get stdio => context.get<Stdio>() ?? const Stdio();
......
...@@ -148,7 +148,7 @@ Future<int> runCommandAndStreamOutput( ...@@ -148,7 +148,7 @@ Future<int> runCommandAndStreamOutput(
final StreamSubscription<String> stdoutSubscription = process.stdout final StreamSubscription<String> stdoutSubscription = process.stdout
.transform<String>(utf8.decoder) .transform<String>(utf8.decoder)
.transform<String>(const LineSplitter()) .transform<String>(const LineSplitter())
.where((String line) => filter == null ? true : filter.hasMatch(line)) .where((String line) => filter == null || filter.hasMatch(line))
.listen((String line) { .listen((String line) {
if (mapFunction != null) if (mapFunction != null)
line = mapFunction(line); line = mapFunction(line);
...@@ -163,7 +163,7 @@ Future<int> runCommandAndStreamOutput( ...@@ -163,7 +163,7 @@ Future<int> runCommandAndStreamOutput(
final StreamSubscription<String> stderrSubscription = process.stderr final StreamSubscription<String> stderrSubscription = process.stderr
.transform<String>(utf8.decoder) .transform<String>(utf8.decoder)
.transform<String>(const LineSplitter()) .transform<String>(const LineSplitter())
.where((String line) => filter == null ? true : filter.hasMatch(line)) .where((String line) => filter == null || filter.hasMatch(line))
.listen((String line) { .listen((String line) {
if (mapFunction != null) if (mapFunction != null)
line = mapFunction(line); line = mapFunction(line);
......
...@@ -246,7 +246,7 @@ class KernelCompiler { ...@@ -246,7 +246,7 @@ class KernelCompiler {
'trackWidgetCreation': trackWidgetCreation.toString(), 'trackWidgetCreation': trackWidgetCreation.toString(),
'linkPlatformKernelIn': linkPlatformKernelIn.toString(), 'linkPlatformKernelIn': linkPlatformKernelIn.toString(),
'engineHash': Cache.instance.engineRevision, 'engineHash': Cache.instance.engineRevision,
'buildersUsed': '${flutterProject != null ? flutterProject.hasBuilders : false}', 'buildersUsed': '${flutterProject != null && flutterProject.hasBuilders}',
}, },
depfilePaths: <String>[depFilePath], depfilePaths: <String>[depFilePath],
pathFilter: (String path) => !path.startsWith('/b/build/slave/'), pathFilter: (String path) => !path.startsWith('/b/build/slave/'),
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment