[go: nahoru, domu]

Skip to content

Commit

Permalink
Taboo the word "simply" from our API documentation. (#116061)
Browse files Browse the repository at this point in the history
  • Loading branch information
Hixie committed Dec 11, 2022
1 parent 1fc166a commit 9fdb64b
Show file tree
Hide file tree
Showing 51 changed files with 180 additions and 133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,18 @@ import 'dart:ui' as ui;

import 'recorder.dart';

/// Measures the performance of image decoding.
///
/// The benchmark measures the decoding latency and not impact on jank. It
/// cannot distinguish between blocking and non-blocking decoding. It simply
/// measures the total time it takes to decode image frames. For example, the
/// WASM codecs execute on the main thread and block the UI, leading to jank,
/// but the browser's WebCodecs API is asynchronous running on a separate thread
/// and does not jank. However, the benchmark result may be the same.
///
/// This benchmark does not support the HTML renderer because the HTML renderer
/// cannot decode image frames (it always returns 1 dummy frame, even for
/// animated images).
// Measures the performance of image decoding.
//
// The benchmark measures the decoding latency and not impact on jank. It
// cannot distinguish between blocking and non-blocking decoding. It naively
// measures the total time it takes to decode image frames. For example, the
// WASM codecs execute on the main thread and block the UI, leading to jank,
// but the browser's WebCodecs API is asynchronous running on a separate thread
// and does not jank. However, the benchmark result may be the same.
//
// This benchmark does not support the HTML renderer because the HTML renderer
// cannot decode image frames (it always returns 1 dummy frame, even for
// animated images).
class BenchImageDecoding extends RawRecorder {
BenchImageDecoding() : super(
name: benchmarkName,
Expand Down
35 changes: 30 additions & 5 deletions dev/bots/analyze.dart
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,9 @@ Future<void> run(List<String> arguments) async {
printProgress('null initialized debug fields...');
await verifyNullInitializedDebugExpensiveFields(flutterRoot);

printProgress('Taboo words...');
await verifyTabooDocumentation(flutterRoot);

// Ensure that all package dependencies are in sync.
printProgress('Package dependencies...');
await runCommand(flutter, <String>['update-packages', '--verify-only'],
Expand Down Expand Up @@ -1815,18 +1818,17 @@ Future<void> verifyNullInitializedDebugExpensiveFields(String workingDirectory,
final List<String> errors = <String>[];
for (final File file in files) {
final List<String> lines = file.readAsLinesSync();
for (int i = 0; i < lines.length; i += 1) {
final String line = lines[i];
for (int index = 0; index < lines.length; index += 1) {
final String line = lines[index];
if (!line.contains(_kDebugOnlyAnnotation)) {
continue;
}
final String nextLine = lines[i + 1];
final String nextLine = lines[index + 1];
if (_nullInitializedField.firstMatch(nextLine) == null) {
errors.add('${file.path} L$i');
errors.add('${file.path}:$index');
}
}
}

if (errors.isNotEmpty) {
foundError(<String>[
'${bold}ERROR: ${red}fields annotated with @_debugOnly must null initialize.$reset',
Expand All @@ -1839,6 +1841,29 @@ Future<void> verifyNullInitializedDebugExpensiveFields(String workingDirectory,
}
}

final RegExp tabooPattern = RegExp(r'^ *///.*\b(simply)\b', caseSensitive: false);

Future<void> verifyTabooDocumentation(String workingDirectory, { int minimumMatches = 100 }) async {
final List<String> errors = <String>[];
await for (final File file in _allFiles(workingDirectory, 'dart', minimumMatches: minimumMatches)) {
final List<String> lines = file.readAsLinesSync();
for (int index = 0; index < lines.length; index += 1) {
final String line = lines[index];
final Match? match = tabooPattern.firstMatch(line);
if (match != null) {
errors.add('${file.path}:${index + 1}: Found use of the taboo word "${match.group(1)}" in documentation string.');
}
}
}
if (errors.isNotEmpty) {
foundError(<String>[
'${bold}Avoid the word "simply" in documentation. See https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-the-passive-voice-recommend-do-not-require-never-say-things-are-simple for details.$reset',
'${bold}In many cases the word can be omitted without loss of generality; in other cases it may require a bit of rewording to avoid implying that the task is simple.$reset',
...errors,
]);
}
}

Future<CommandResult> _runFlutterAnalyze(String workingDirectory, {
List<String> options = const <String>[],
}) async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,6 @@ class Foo {
@_debugOnly
final Map<String, String>? bar = kDebugMode ? null : <String, String>{};
}

/// Simply avoid this
/// and simply do that.
15 changes: 13 additions & 2 deletions dev/bots/test/analyze_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,18 @@ void main() {
minimumMatches: 1,
), shouldHaveErrors: true);

expect(result, contains('L15'));
expect(result, isNot(contains('L12')));
expect(result, contains(':15'));
expect(result, isNot(contains(':12')));
});

test('analyze.dart - verifyTabooDocumentation', () async {
final String result = await capture(() => verifyTabooDocumentation(
testRootPath,
minimumMatches: 1,
), shouldHaveErrors: true);

expect(result, isNot(contains(':19')));
expect(result, contains(':20'));
expect(result, contains(':21'));
});
}
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/animation/animations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -255,8 +255,8 @@ class ProxyAnimation extends Animation<double>
/// If the parent animation is running forward from 0.0 to 1.0, this animation
/// is running in reverse from 1.0 to 0.0.
///
/// Using a [ReverseAnimation] is different from simply using a [Tween] with a
/// begin of 1.0 and an end of 0.0 because the tween does not change the status
/// Using a [ReverseAnimation] is different from using a [Tween] with a
/// `begin` of 1.0 and an `end` of 0.0 because the tween does not change the status
/// or direction of the animation.
///
/// See also:
Expand Down
17 changes: 8 additions & 9 deletions packages/flutter/lib/src/cupertino/context_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,10 +99,10 @@ enum _ContextMenuLocation {
/// [Expanded] widget so that it will grow to fill the Overlay if its size is
/// unconstrained.
///
/// When closed, the CupertinoContextMenu simply displays the child as if the
/// CupertinoContextMenu were not there. Sizing and positioning is unaffected.
/// When closed, the [CupertinoContextMenu] displays the child as if the
/// [CupertinoContextMenu] were not there. Sizing and positioning is unaffected.
/// The menu can be closed like other [PopupRoute]s, such as by tapping the
/// background or by calling `Navigator.pop(context)`. Unlike PopupRoute, it can
/// background or by calling `Navigator.pop(context)`. Unlike [PopupRoute], it can
/// also be closed by swiping downwards.
///
/// The [previewBuilder] parameter is most commonly used to display a slight
Expand All @@ -111,8 +111,8 @@ enum _ContextMenuLocation {
/// Photos app on iOS.
///
/// {@tool dartpad}
/// This sample shows a very simple CupertinoContextMenu for the Flutter logo.
/// Simply long press on it to open.
/// This sample shows a very simple [CupertinoContextMenu] for the Flutter logo.
/// Long press on it to open.
///
/// ** See code in examples/api/lib/cupertino/context_menu/cupertino_context_menu.0.dart **
/// {@end-tool}
Expand Down Expand Up @@ -256,10 +256,9 @@ class CupertinoContextMenu extends StatefulWidget {
/// and when it is fully open. This will overwrite the default animation that
/// matches the behavior of an iOS 16.0 context menu.
///
/// This builder can be used instead of the child when either the intended
/// child has a property that would conflict with the default animation, like
/// a border radius or a shadow, or if simply a more custom animation is
/// needed.
/// This builder can be used instead of the child when the intended child has
/// a property that would conflict with the default animation, such as a
/// border radius or a shadow, or if a more custom animation is needed.
///
/// In addition to the current [BuildContext], the function is also called
/// with an [Animation]. The complete animation goes from 0 to 1 when
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/cupertino/scrollbar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ const double _kScrollbarCrossAxisMargin = 3.0;

/// An iOS style scrollbar.
///
/// To add a scrollbar to a [ScrollView], simply wrap the scroll view widget in
/// To add a scrollbar to a [ScrollView], wrap the scroll view widget in
/// a [CupertinoScrollbar] widget.
///
/// {@youtube 560 315 https://www.youtube.com/watch?v=DbkIQSvwnZc}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import 'text_field.dart';
/// Creates a [CupertinoFormRow] containing a [FormField] that wraps
/// a [CupertinoTextField].
///
/// A [Form] ancestor is not required. The [Form] simply makes it easier to
/// A [Form] ancestor is not required. The [Form] allows one to
/// save, reset, or validate multiple fields at once. To use without a [Form],
/// pass a [GlobalKey] to the constructor and use [GlobalKey.currentState] to
/// save or reset the form field.
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/foundation/assertions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ class RepetitiveStackFrameFilter extends StackFilter {
/// The string to replace the frames with.
///
/// If the same replacement string is used multiple times in a row, the
/// [FlutterError.defaultStackFilter] will simply update a counter after this
/// [FlutterError.defaultStackFilter] will insert a repeat count after this
/// line rather than repeating it.
final String replacement;

Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/gestures/tap.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ abstract class BaseTapGestureRecognizer extends PrimaryPointerGestureRecognizer
if (_down != null) {
// This happens when this tap gesture has been rejected while the pointer
// is down (i.e. due to movement), when another allowed pointer is added,
// in which case all pointers are simply ignored. The `_down` being null
// in which case all pointers are ignored. The `_down` being null
// means that _reset() has been called, since it is always set at the
// first allowed down event and will not be cleared except for reset(),
super.addAllowedPointer(event);
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/button_theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ class ButtonThemeData with Diagnosticable {
/// Defaults to [ButtonBarLayoutBehavior.padded].
final ButtonBarLayoutBehavior layoutBehavior;

/// Simply a convenience that returns [minWidth] and [height] as a
/// Convenience that returns [minWidth] and [height] as a
/// [BoxConstraints] object.
BoxConstraints get constraints {
return BoxConstraints(
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/dropdown.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1530,7 +1530,7 @@ class _DropdownButtonState<T> extends State<DropdownButton<T>> with WidgetsBindi
/// This is a convenience widget that wraps a [DropdownButton] widget in a
/// [FormField].
///
/// A [Form] ancestor is not required. The [Form] simply makes it easier to
/// A [Form] ancestor is not required. The [Form] allows one to
/// save, reset, or validate multiple fields at once. To use without a [Form],
/// pass a [GlobalKey] to the constructor and use [GlobalKey.currentState] to
/// save or reset the form field.
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/lib/src/material/expansion_panel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,14 @@ class ExpansionPanelList extends StatefulWidget {
/// is pressed. The arguments passed to the callback are the index of the
/// pressed panel and whether the panel is currently expanded or not.
///
/// If ExpansionPanelList.radio is used, the callback may be called a
/// If [ExpansionPanelList.radio] is used, the callback may be called a
/// second time if a different panel was previously open. The arguments
/// passed to the second callback are the index of the panel that will close
/// and false, marking that it will be closed.
///
/// For ExpansionPanelList, the callback needs to setState when it's notified
/// For [ExpansionPanelList], the callback needs to setState when it's notified
/// about the closing/opening panel. On the other hand, the callback for
/// ExpansionPanelList.radio is simply meant to inform the parent widget of
/// [ExpansionPanelList.radio] is intended to inform the parent widget of
/// changes, as the radio panels' open/close states are managed internally.
///
/// This callback is useful in order to keep track of the expanded/collapsed
Expand Down
12 changes: 6 additions & 6 deletions packages/flutter/lib/src/material/menu_anchor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -700,10 +700,10 @@ class MenuController {
/// platform instead of by Flutter (on macOS, for example).
/// * [ShortcutRegistry], a registry of shortcuts that apply for the entire
/// application.
/// * [VoidCallbackIntent] to define intents that will call a [VoidCallback] and
/// * [VoidCallbackIntent], to define intents that will call a [VoidCallback] and
/// work with the [Actions] and [Shortcuts] system.
/// * [CallbackShortcuts] to define shortcuts that simply call a callback and
/// don't involve using [Actions].
/// * [CallbackShortcuts], to define shortcuts that call a callback without
/// involving [Actions].
class MenuBar extends StatelessWidget {
/// Creates a const [MenuBar].
///
Expand Down Expand Up @@ -789,10 +789,10 @@ class MenuBar extends StatelessWidget {
/// platform instead of by Flutter (on macOS, for example).
/// * [ShortcutRegistry], a registry of shortcuts that apply for the entire
/// application.
/// * [VoidCallbackIntent] to define intents that will call a [VoidCallback] and
/// * [VoidCallbackIntent], to define intents that will call a [VoidCallback] and
/// work with the [Actions] and [Shortcuts] system.
/// * [CallbackShortcuts] to define shortcuts that simply call a callback and
/// don't involve using [Actions].
/// * [CallbackShortcuts] to define shortcuts that call a callback without
/// involving [Actions].
class MenuItemButton extends StatefulWidget {
/// Creates a const [MenuItemButton].
///
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/material/snack_bar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ enum SnackBarClosedReason {

/// A button for a [SnackBar], known as an "action".
///
/// Snack bar actions are always enabled. If you want to disable a snack bar
/// action, simply don't include it in the snack bar.
/// Snack bar actions are always enabled. Instead of disabling a snack bar
/// action, avoid including it in the snack bar in the first place.
///
/// Snack bar actions can only be pressed once. Subsequent presses are ignored.
///
Expand Down
2 changes: 1 addition & 1 deletion packages/flutter/lib/src/material/text_form_field.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export 'package:flutter/services.dart' show SmartDashesType, SmartQuotesType;
/// This is a convenience widget that wraps a [TextField] widget in a
/// [FormField].
///
/// A [Form] ancestor is not required. The [Form] simply makes it easier to
/// A [Form] ancestor is not required. The [Form] allows one to
/// save, reset, or validate multiple fields at once. To use without a [Form],
/// pass a `GlobalKey<FormFieldState>` (see [GlobalKey]) to the constructor and use
/// [GlobalKey.currentState] to save or reset the form field.
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/lib/src/painting/matrix_utils.dart
Original file line number Diff line number Diff line change
Expand Up @@ -455,8 +455,8 @@ class MatrixUtils {
///
/// The `radius` simulates the radius of the cylinder the plane is being
/// wrapped onto. If the transformation is applied to a 0-dimensional dot
/// instead of a plane, the dot would simply translate by +/- `radius` pixels
/// along the `orientation` [Axis] when rotating from 0 to +/- 90 degrees.
/// instead of a plane, the dot would translate by ± `radius` pixels
/// along the `orientation` [Axis] when rotating from 0 to ±90 degrees.
///
/// A positive radius means the object is closest at 0 `angle` and a negative
/// radius means the object is closest at π `angle` or 180 degrees.
Expand All @@ -478,7 +478,7 @@ class MatrixUtils {
/// The `orientation` is the direction of the rotation axis.
///
/// Because the viewing position is a point, it's never possible to see the
/// outer side of the cylinder at or past +/- π / 2 or 90 degrees and it's
/// outer side of the cylinder at or past ±π/2 or 90 degrees and it's
/// almost always possible to end up seeing the inner side of the cylinder
/// or the back side of the transformed plane before π / 2 when perspective > 0.
static Matrix4 createCylindricalProjectionTransform({
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/rendering/box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -1936,7 +1936,7 @@ abstract class RenderBox extends RenderObject {
/// may depend on the baseline of a child (which is not available without
/// doing a full layout), it may be computed by a callback about which the
/// render object cannot reason, or the layout is so complex that it
/// is simply impractical to calculate the size in an efficient way.
/// is impractical to calculate the size in an efficient way.
///
/// In such cases, it may be impossible (or at least impractical) to actually
/// return a valid answer. In such cases, the function should call
Expand Down Expand Up @@ -1964,7 +1964,7 @@ abstract class RenderBox extends RenderObject {
/// When asserts are enabled and [debugCheckingIntrinsics] is not true, this
/// method will either throw the provided [FlutterError] or it will create and
/// throw a [FlutterError] with the provided `reason`. Otherwise, it will
/// simply return true.
/// return true.
///
/// One of the arguments has to be provided.
///
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/rendering/flow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,8 @@ class FlowParentData extends ContainerBoxParentData<RenderBox> {
///
/// Rather than positioning the children during layout, the children are
/// positioned using transformation matrices during the paint phase using the
/// matrices from the [FlowDelegate.paintChildren] function. The children can be
/// repositioned efficiently by simply repainting the flow.
/// matrices from the [FlowDelegate.paintChildren] function. The children are thus
/// repositioned efficiently by repainting the flow, skipping layout.
///
/// The most efficient way to trigger a repaint of the flow is to supply a
/// repaint argument to the constructor of the [FlowDelegate]. The flow will
Expand Down
6 changes: 3 additions & 3 deletions packages/flutter/lib/src/rendering/layer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ abstract class Layer extends AbstractNode with DiagnosticableTreeMixin {
/// should search for annotations, or if the layer has its own annotations to
/// add.
///
/// The default implementation simply returns `false`, which means neither
/// The default implementation always returns `false`, which means neither
/// the layer nor its children has annotations, and the annotation search
/// is not absorbed either (see below for explanation).
///
Expand Down Expand Up @@ -602,7 +602,7 @@ abstract class Layer extends AbstractNode with DiagnosticableTreeMixin {
///
/// Returns null if no matching annotations are found.
///
/// By default this method simply calls [findAnnotations] with `onlyFirst:
/// By default this method calls [findAnnotations] with `onlyFirst:
/// true` and returns the annotation of the first result. Prefer overriding
/// [findAnnotations] instead of this method, because during an annotation
/// search, only [findAnnotations] is recursively called, while custom
Expand All @@ -628,7 +628,7 @@ abstract class Layer extends AbstractNode with DiagnosticableTreeMixin {
///
/// Returns a result with empty entries if no matching annotations are found.
///
/// By default this method simply calls [findAnnotations] with `onlyFirst:
/// By default this method calls [findAnnotations] with `onlyFirst:
/// false` and returns the annotations of its result. Prefer overriding
/// [findAnnotations] instead of this method, because during an annotation
/// search, only [findAnnotations] is recursively called, while custom
Expand Down
4 changes: 2 additions & 2 deletions packages/flutter/lib/src/rendering/mouse_tracker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,8 +302,8 @@ class MouseTracker extends ChangeNotifier {
/// [MouseTracker] filter which to react to.
///
/// The `getResult` is a function to return the hit test result at the
/// position of the event. It should not simply return cached hit test
/// result, because the cache does not change throughout a tap sequence.
/// position of the event. It should not return a cached hit test
/// result, because the cache would not change during a tap sequence.
void updateWithEvent(PointerEvent event, ValueGetter<HitTestResult> getResult) {
if (event.kind != PointerDeviceKind.mouse) {
return;
Expand Down
Loading

0 comments on commit 9fdb64b

Please sign in to comment.