From 0d3b44e835b04249610b32f2a3f71bf5e819cecd Mon Sep 17 00:00:00 2001 From: Jonah Williams Date: Tue, 3 Aug 2021 13:25:05 -0700 Subject: [PATCH] [flutter] replace 'checked mode' with 'debug mode' (#87408) --- dev/bots/analyze.dart | 26 +++++++++++++++++++ .../lib/src/foundation/assertions.dart | 4 +-- .../flutter/lib/src/foundation/binding.dart | 2 +- packages/flutter/lib/src/material/app.dart | 2 +- .../flutter/lib/src/painting/decoration.dart | 2 +- .../flutter/lib/src/painting/inline_span.dart | 2 +- .../flutter/lib/src/painting/text_span.dart | 2 +- packages/flutter/lib/src/rendering/box.dart | 4 +-- packages/flutter/lib/src/rendering/debug.dart | 4 +-- .../flutter/lib/src/rendering/object.dart | 4 +-- .../flutter/lib/src/rendering/proxy_box.dart | 4 +-- .../flutter/lib/src/rendering/viewport.dart | 2 +- packages/flutter/lib/src/widgets/app.dart | 16 ++++++------ packages/flutter/lib/src/widgets/banner.dart | 4 +-- .../flutter/lib/src/widgets/framework.dart | 2 +- packages/flutter_test/lib/src/binding.dart | 4 +-- .../flutter_test/lib/src/widget_tester.dart | 6 ++--- 17 files changed, 58 insertions(+), 32 deletions(-) diff --git a/dev/bots/analyze.dart b/dev/bots/analyze.dart index 1c45e428c3..28788b3ac8 100644 --- a/dev/bots/analyze.dart +++ b/dev/bots/analyze.dart @@ -48,6 +48,9 @@ Future run(List arguments) async { print('$clock runtimeType in toString...'); await verifyNoRuntimeTypeInToString(flutterRoot); + print('$clock debug mode instead of checked mode...'); + await verifyNoCheckedMode(flutterRoot); + print('$clock Unexpected binaries...'); await verifyNoBinaries(flutterRoot); @@ -471,6 +474,29 @@ Future verifyInternationalizations(String workingDirectory, String dartExe } } + +/// Verifies that all instances of "checked mode" have been migrated to "debug mode". +Future verifyNoCheckedMode(String workingDirectory) async { + final String flutterPackages = path.join(workingDirectory, 'packages'); + final List files = await _allFiles(flutterPackages, 'dart', minimumMatches: 400) + .where((File file) => path.extension(file.path) == '.dart') + .toList(); + final List problems = []; + for (final File file in files) { + int lineCount = 0; + for (final String line in file.readAsLinesSync()) { + if (line.toLowerCase().contains('checked mode')) { + problems.add('${file.path}:$lineCount uses deprecated "checked mode" instead of "debug mode".'); + } + lineCount += 1; + } + } + if (problems.isNotEmpty) { + exitWithError(problems); + } +} + + Future verifyNoRuntimeTypeInToString(String workingDirectory) async { final String flutterLib = path.join(workingDirectory, 'packages', 'flutter', 'lib'); final Set excludedFiles = { diff --git a/packages/flutter/lib/src/foundation/assertions.dart b/packages/flutter/lib/src/foundation/assertions.dart index f4ca3fafb3..4d3faf8a09 100644 --- a/packages/flutter/lib/src/foundation/assertions.dart +++ b/packages/flutter/lib/src/foundation/assertions.dart @@ -533,7 +533,7 @@ class FlutterErrorDetails with Diagnosticable { /// dump this error to the console. /// /// If this is true, then the default error handler would only dump this error - /// to the console in checked mode. In release mode, the error is ignored. + /// to the console in debug mode. In release mode, the error is ignored. /// /// This is used by certain exception handlers that catch errors that could be /// triggered by environmental conditions (as opposed to logic errors). For @@ -950,7 +950,7 @@ class FlutterError extends Error with DiagnosticableTreeMixin implements Asserti assert(details.exception != null); bool isInDebugMode = false; assert(() { - // In checked mode, we ignore the "silent" flag. + // In debug mode, we ignore the "silent" flag. isInDebugMode = true; return true; }()); diff --git a/packages/flutter/lib/src/foundation/binding.dart b/packages/flutter/lib/src/foundation/binding.dart index e89d25056d..34606548b0 100644 --- a/packages/flutter/lib/src/foundation/binding.dart +++ b/packages/flutter/lib/src/foundation/binding.dart @@ -33,7 +33,7 @@ typedef ServiceExtensionCallback = Future> Function(Map objectRuntimeType(this, 'Decoration'); - /// In checked mode, throws an exception if the object is not in a + /// In debug mode, throws an exception if the object is not in a /// valid configuration. Otherwise, returns true. /// /// This is intended to be used as follows: diff --git a/packages/flutter/lib/src/painting/inline_span.dart b/packages/flutter/lib/src/painting/inline_span.dart index f51375acca..b2544bd588 100644 --- a/packages/flutter/lib/src/painting/inline_span.dart +++ b/packages/flutter/lib/src/painting/inline_span.dart @@ -331,7 +331,7 @@ abstract class InlineSpan extends DiagnosticableTree { @protected int? codeUnitAtVisitor(int index, Accumulator offset); - /// In checked mode, throws an exception if the object is not in a + /// In debug mode, throws an exception if the object is not in a /// valid configuration. Otherwise, returns true. /// /// This is intended to be used as follows: diff --git a/packages/flutter/lib/src/painting/text_span.dart b/packages/flutter/lib/src/painting/text_span.dart index 984eb40f50..a80ce78bd2 100644 --- a/packages/flutter/lib/src/painting/text_span.dart +++ b/packages/flutter/lib/src/painting/text_span.dart @@ -432,7 +432,7 @@ class TextSpan extends InlineSpan implements HitTestTarget, MouseTrackerAnnotati offset.increment(text != null ? text!.length : 0); } - /// In checked mode, throws an exception if the object is not in a valid + /// In debug mode, throws an exception if the object is not in a valid /// configuration. Otherwise, returns true. /// /// This is intended to be used as follows: diff --git a/packages/flutter/lib/src/rendering/box.dart b/packages/flutter/lib/src/rendering/box.dart index bcb28aa15a..57a7b9f944 100644 --- a/packages/flutter/lib/src/rendering/box.dart +++ b/packages/flutter/lib/src/rendering/box.dart @@ -497,7 +497,7 @@ class BoxConstraints extends Constraints { /// /// Most of the APIs on BoxConstraints expect the constraints to be /// normalized and have undefined behavior when they are not. In - /// checked mode, many of these APIs will assert if the constraints + /// debug mode, many of these APIs will assert if the constraints /// are not normalized. @override bool get isNormalized { @@ -1951,7 +1951,7 @@ abstract class RenderBox extends RenderObject { return _size!; } Size? _size; - /// Setting the size, in checked mode, triggers some analysis of the render box, + /// Setting the size, in debug mode, triggers some analysis of the render box, /// as implemented by [debugAssertDoesMeetConstraints], including calling the intrinsic /// sizing methods and checking that they meet certain invariants. @protected diff --git a/packages/flutter/lib/src/rendering/debug.dart b/packages/flutter/lib/src/rendering/debug.dart index 8a23f8c7fd..59214ae80f 100644 --- a/packages/flutter/lib/src/rendering/debug.dart +++ b/packages/flutter/lib/src/rendering/debug.dart @@ -36,7 +36,7 @@ bool debugPaintLayerBordersEnabled = false; /// [RenderBox.debugHandleEvent]. bool debugPaintPointersEnabled = false; -/// Overlay a rotating set of colors when repainting layers in checked mode. +/// Overlay a rotating set of colors when repainting layers in debug mode. /// /// See also: /// @@ -44,7 +44,7 @@ bool debugPaintPointersEnabled = false; /// areas are being excessively repainted. bool debugRepaintRainbowEnabled = false; -/// Overlay a rotating set of colors when repainting text in checked mode. +/// Overlay a rotating set of colors when repainting text in debug mode. bool debugRepaintTextRainbowEnabled = false; /// The current color to overlay when repainting a layer. diff --git a/packages/flutter/lib/src/rendering/object.dart b/packages/flutter/lib/src/rendering/object.dart index deb54b9480..52e49e5b53 100644 --- a/packages/flutter/lib/src/rendering/object.dart +++ b/packages/flutter/lib/src/rendering/object.dart @@ -1879,7 +1879,7 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im /// If a subclass has a "size" (the state controlled by `parentUsesSize`, /// whatever it is in the subclass, e.g. the actual `size` property of - /// [RenderBox]), and the subclass verifies that in checked mode this "size" + /// [RenderBox]), and the subclass verifies that in debug mode this "size" /// property isn't used when [debugCanParentUseSize] isn't set, then that /// subclass should override [debugResetSize] to reapply the current values of /// [debugCanParentUseSize] to that state. @@ -2023,7 +2023,7 @@ abstract class RenderObject extends AbstractNode with DiagnosticableTreeMixin im /// See [RepaintBoundary] for more information about how repaint boundaries function. bool get isRepaintBoundary => false; - /// Called, in checked mode, if [isRepaintBoundary] is true, when either the + /// Called, in debug mode, if [isRepaintBoundary] is true, when either the /// this render object or its parent attempt to paint. /// /// This can be used to record metrics about whether the node should actually diff --git a/packages/flutter/lib/src/rendering/proxy_box.dart b/packages/flutter/lib/src/rendering/proxy_box.dart index deb41650d2..e71f10bbbf 100644 --- a/packages/flutter/lib/src/rendering/proxy_box.dart +++ b/packages/flutter/lib/src/rendering/proxy_box.dart @@ -3075,7 +3075,7 @@ class RenderMouseRegion extends RenderProxyBox implements MouseTrackerAnnotation /// application and the rest of the application would not repaint. /// /// To tell if a particular RenderRepaintBoundary is useful, run your -/// application in checked mode, interacting with it in typical ways, and then +/// application in debug mode, interacting with it in typical ways, and then /// call [debugDumpRenderTree]. Each RenderRepaintBoundary will include the /// ratio of cases where the repaint boundary was useful vs the cases where it /// was not. These counts can also be inspected programmatically using @@ -3237,7 +3237,7 @@ class RenderRepaintBoundary extends RenderProxyBox { return true; }()); if (inReleaseMode) - properties.add(DiagnosticsNode.message('(run in checked mode to collect repaint boundary statistics)')); + properties.add(DiagnosticsNode.message('(run in debug mode to collect repaint boundary statistics)')); } } diff --git a/packages/flutter/lib/src/rendering/viewport.dart b/packages/flutter/lib/src/rendering/viewport.dart index b7a8d6c165..da9aeb739f 100644 --- a/packages/flutter/lib/src/rendering/viewport.dart +++ b/packages/flutter/lib/src/rendering/viewport.dart @@ -385,7 +385,7 @@ abstract class RenderViewportBase> Function(String initialRo /// See also: /// /// * [CheckedModeBanner], which displays a [Banner] saying "DEBUG" when -/// running in checked mode. +/// running in debug mode. /// * [DefaultTextStyle], the text style to apply to descendant [Text] widgets /// without an explicit style. /// * [MediaQuery], which establishes a subtree in which media queries resolve @@ -967,9 +967,9 @@ class WidgetsApp extends StatefulWidget { /// Turns on an overlay that enables inspecting the widget tree. /// - /// The inspector is only available in checked mode as it depends on + /// The inspector is only available in debug mode as it depends on /// [RenderObject.debugDescribeChildren] which should not be called outside of - /// checked mode. + /// debug mode. final bool debugShowWidgetInspector; /// Builds the widget the [WidgetInspector] uses to switch between view and @@ -981,18 +981,18 @@ class WidgetsApp extends StatefulWidget { final InspectorSelectButtonBuilder? inspectorSelectButtonBuilder; /// {@template flutter.widgets.widgetsApp.debugShowCheckedModeBanner} - /// Turns on a little "DEBUG" banner in checked mode to indicate - /// that the app is in checked mode. This is on by default (in - /// checked mode), to turn it off, set the constructor argument to + /// Turns on a little "DEBUG" banner in debug mode to indicate + /// that the app is in debug mode. This is on by default (in + /// debug mode), to turn it off, set the constructor argument to /// false. In release mode this has no effect. /// /// To get this banner in your application if you're not using /// WidgetsApp, include a [CheckedModeBanner] widget in your app. /// /// This banner is intended to deter people from complaining that your - /// app is slow when it's in checked mode. In checked mode, Flutter + /// app is slow when it's in debug mode. In debug mode, Flutter /// enables a large number of expensive diagnostics to aid in - /// development, and so performance in checked mode is not + /// development, and so performance in debug mode is not /// representative of what will happen in release mode. /// {@endtemplate} final bool debugShowCheckedModeBanner; diff --git a/packages/flutter/lib/src/widgets/banner.dart b/packages/flutter/lib/src/widgets/banner.dart index 964719a4fc..7e50f73a12 100644 --- a/packages/flutter/lib/src/widgets/banner.dart +++ b/packages/flutter/lib/src/widgets/banner.dart @@ -325,11 +325,11 @@ class Banner extends StatelessWidget { } } -/// Displays a [Banner] saying "DEBUG" when running in checked mode. +/// Displays a [Banner] saying "DEBUG" when running in debug mode. /// [MaterialApp] builds one of these by default. /// Does nothing in release mode. class CheckedModeBanner extends StatelessWidget { - /// Creates a const checked mode banner. + /// Creates a const debug mode banner. const CheckedModeBanner({ Key? key, required this.child, diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index 8d97a2ee52..30fd905ddd 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -2087,7 +2087,7 @@ abstract class BuildContext { /// This getter will only return a valid result if [findRenderObject] actually /// returns a [RenderBox]. If [findRenderObject] returns a render object that /// is not a subtype of [RenderBox] (e.g., [RenderView]), this getter will - /// throw an exception in checked mode and will return null in release mode. + /// throw an exception in debug mode and will return null in release mode. /// /// Calling this getter is theoretically relatively expensive (O(N) in the /// depth of the tree), but in practice is usually cheap because the tree diff --git a/packages/flutter_test/lib/src/binding.dart b/packages/flutter_test/lib/src/binding.dart index 42b37a7409..8fdea90cae 100644 --- a/packages/flutter_test/lib/src/binding.dart +++ b/packages/flutter_test/lib/src/binding.dart @@ -951,8 +951,8 @@ abstract class TestWidgetsFlutterBinding extends BindingBase /// This binding controls time, allowing tests to verify long /// animation sequences without having to execute them in real time. /// -/// This class assumes it is always run in checked mode (since tests are always -/// run in checked mode). +/// This class assumes it is always run in debug mode (since tests are always +/// run in debug mode). class AutomatedTestWidgetsFlutterBinding extends TestWidgetsFlutterBinding { @override void initInstances() { diff --git a/packages/flutter_test/lib/src/widget_tester.dart b/packages/flutter_test/lib/src/widget_tester.dart index 946a7749ed..91a88f2136 100644 --- a/packages/flutter_test/lib/src/widget_tester.dart +++ b/packages/flutter_test/lib/src/widget_tester.dart @@ -393,15 +393,15 @@ const String kDebugWarning = ''' /// passed to the `callback`, and that handle will automatically be disposed /// after the callback is finished. /// -/// Benchmarks must not be run in checked mode, because the performance is not +/// Benchmarks must not be run in debug mode, because the performance is not /// representative. To avoid this, this function will print a big message if it -/// is run in checked mode. Unit tests of this method pass `mayRunWithAsserts`, +/// is run in debug mode. Unit tests of this method pass `mayRunWithAsserts`, /// but it should not be used for actual benchmarking. /// /// Example: /// /// main() async { -/// assert(false); // fail in checked mode +/// assert(false); // fail in debug mode /// await benchmarkWidgets((WidgetTester tester) async { /// await tester.pumpWidget(MyWidget()); /// final Stopwatch timer = Stopwatch()..start();