diff --git a/analysis_options.yaml b/analysis_options.yaml index c8a416b12b..4a4006398a 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -83,7 +83,7 @@ linter: - avoid_returning_null_for_void # - avoid_returning_this # there are plenty of valid reasons to return this # - avoid_setters_without_getters # not yet tested - # - avoid_shadowing_type_parameters # not yet tested + - avoid_shadowing_type_parameters - avoid_single_cascade_in_expression_statements - avoid_slow_async_io # - avoid_type_to_string # we do this commonly @@ -103,7 +103,7 @@ linter: # - comment_references # blocked on https://github.com/flutter/flutter/issues/20765 # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204 - control_flow_in_finally - # - curly_braces_in_flow_control_structures # not yet tested + # - curly_braces_in_flow_control_structures # not required by flutter style # - diagnostic_describe_all_properties # not yet tested - directives_ordering # - do_not_use_environment # we do this commonly @@ -117,22 +117,22 @@ linter: - implementation_imports # - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811 - iterable_contains_unrelated_type - # - join_return_with_assignment # not yet tested + # - join_return_with_assignment # not required by flutter style - leading_newlines_in_multiline_strings - library_names - library_prefixes - # - lines_longer_than_80_chars # not yet tested + # - lines_longer_than_80_chars # not required by flutter style - list_remove_unrelated_type # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181 # - missing_whitespace_between_adjacent_strings # not yet tested - no_adjacent_strings_in_list # - no_default_cases # too many false positives - no_duplicate_case_values - # - no_logic_in_create_state # not yet tested - # - no_runtimeType_toString # not yet tested + - no_logic_in_create_state + # - no_runtimeType_toString # ok in tests; we enable this only in packages/ - non_constant_identifier_names - null_check_on_nullable_type_parameter - # - null_closures # not yet tested + # - null_closures # not required by flutter style # - omit_local_variable_types # opposite of always_specify_types # - one_member_abstracts # too many false positives # - only_throw_errors # https://github.com/flutter/flutter/issues/5792 @@ -143,14 +143,14 @@ linter: # - parameter_assignments # we do this commonly - prefer_adjacent_string_concatenation - prefer_asserts_in_initializer_lists - # - prefer_asserts_with_message # not yet tested + # - prefer_asserts_with_message # not required by flutter style - prefer_collection_literals - prefer_conditional_assignment - prefer_const_constructors - prefer_const_constructors_in_immutables - prefer_const_declarations - prefer_const_literals_to_create_immutables - # - prefer_constructors_over_static_methods # not yet tested + # - prefer_constructors_over_static_methods # far too many false positives - prefer_contains # - prefer_double_quotes # opposite of prefer_single_quotes - prefer_equal_for_default_values diff --git a/dev/benchmarks/macrobenchmarks/lib/src/filtered_child_animation.dart b/dev/benchmarks/macrobenchmarks/lib/src/filtered_child_animation.dart index cbc378d4d3..0e84906546 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/filtered_child_animation.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/filtered_child_animation.dart @@ -12,34 +12,34 @@ enum FilterType { } class FilteredChildAnimationPage extends StatefulWidget { - const FilteredChildAnimationPage( - this._filterType, - [ - this._complexChild = true, - this._useRepaintBoundary = true, - ]); + const FilteredChildAnimationPage(this.initialFilterType, [ + this.initialComplexChild = true, + this.initialUseRepaintBoundary = true, + ]); - final FilterType _filterType; - final bool _complexChild; - final bool _useRepaintBoundary; + final FilterType initialFilterType; + final bool initialComplexChild; + final bool initialUseRepaintBoundary; @override - _FilteredChildAnimationPageState createState() => _FilteredChildAnimationPageState(_filterType, _complexChild, _useRepaintBoundary); + _FilteredChildAnimationPageState createState() => _FilteredChildAnimationPageState(); } class _FilteredChildAnimationPageState extends State with SingleTickerProviderStateMixin { - _FilteredChildAnimationPageState(this._filterType, this._complexChild, this._useRepaintBoundary); - AnimationController _controller; - bool _useRepaintBoundary; - bool _complexChild; - FilterType _filterType; final GlobalKey _childKey = GlobalKey(debugLabel: 'child to animate'); Offset _childCenter = Offset.zero; + FilterType _filterType; + bool _complexChild; + bool _useRepaintBoundary; + @override void initState() { super.initState(); + _filterType = widget.initialFilterType; + _complexChild = widget.initialComplexChild; + _useRepaintBoundary = widget.initialUseRepaintBoundary; WidgetsBinding.instance.addPostFrameCallback((_) { final RenderBox childBox = _childKey.currentContext.findRenderObject() as RenderBox; _childCenter = childBox.paintBounds.center; diff --git a/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart b/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart index 8ab48f5ddb..1cf38443a5 100644 --- a/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart +++ b/dev/benchmarks/macrobenchmarks/lib/src/web/recorder.dart @@ -528,11 +528,16 @@ class _WidgetBuildRecorderHost extends StatefulWidget { final WidgetBuildRecorder recorder; @override - State createState() => - recorder._hostState = _WidgetBuildRecorderHostState(); + State createState() => _WidgetBuildRecorderHostState(); } class _WidgetBuildRecorderHostState extends State<_WidgetBuildRecorderHost> { + @override + void initState() { + super.initState(); + widget.recorder._hostState = this; + } + // This is just to bypass the @protected on setState. void _setStateTrampoline() { setState(() {}); diff --git a/packages/analysis_options.yaml b/packages/analysis_options.yaml index 001e88fa3a..3f0e82867e 100644 --- a/packages/analysis_options.yaml +++ b/packages/analysis_options.yaml @@ -1,8 +1,9 @@ -# Take our settings from the repo's main analysis_options.yaml file, but include -# an additional rule to validate that public members are documented. +# Take our settings from the repo's main analysis_options.yaml file, and include +# additional rules that are specific to production code. include: ../analysis_options.yaml linter: rules: - - public_member_api_docs + - public_member_api_docs # see https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#documentation-dartdocs-javadocs-etc + - no_runtimeType_toString # use objectRuntimeType from package:foundation diff --git a/packages/flutter/analysis_options.yaml b/packages/flutter/analysis_options.yaml index eb8a8500b7..ad8b22ef40 100644 --- a/packages/flutter/analysis_options.yaml +++ b/packages/flutter/analysis_options.yaml @@ -5,7 +5,4 @@ include: ../analysis_options.yaml analyzer: errors: always_require_non_null_named_parameters: false # not needed with nnbd - type_init_formals: false # https://github.com/dart-lang/linter/issues/2192 - unrelated_type_equality_checks: false # https://github.com/dart-lang/linter/issues/2196 - void_checks: false # https://github.com/dart-lang/linter/issues/2185 unnecessary_null_comparison: false # Turned off until null-safe rollout is complete. diff --git a/packages/flutter/lib/src/cupertino/date_picker.dart b/packages/flutter/lib/src/cupertino/date_picker.dart index bc88a629ef..c89b45d852 100644 --- a/packages/flutter/lib/src/cupertino/date_picker.dart +++ b/packages/flutter/lib/src/cupertino/date_picker.dart @@ -369,7 +369,7 @@ class CupertinoDatePicker extends StatefulWidget { final Color? backgroundColor; @override - State createState() { + State createState() { // ignore: no_logic_in_create_state, https://github.com/flutter/flutter/issues/70499 // The `time` mode and `dateAndTime` mode of the picker share the time // columns, so they are placed together to one state. // The `date` mode has different children and is implemented in a different diff --git a/packages/flutter/lib/src/cupertino/search_field.dart b/packages/flutter/lib/src/cupertino/search_field.dart index 417b50be9c..7f582993a9 100644 --- a/packages/flutter/lib/src/cupertino/search_field.dart +++ b/packages/flutter/lib/src/cupertino/search_field.dart @@ -136,7 +136,7 @@ class CupertinoSearchTextField extends StatefulWidget { this.backgroundColor, this.borderRadius, this.padding = const EdgeInsetsDirectional.fromSTEB(3.8, 8, 5, 8), - Color this.itemColor = CupertinoColors.secondaryLabel, + this.itemColor = CupertinoColors.secondaryLabel, this.itemSize = 20.0, this.prefixInsets = const EdgeInsetsDirectional.fromSTEB(6, 0, 0, 4), this.suffixInsets = const EdgeInsetsDirectional.fromSTEB(0, 0, 5, 2), diff --git a/packages/flutter/lib/src/rendering/mouse_cursor.dart b/packages/flutter/lib/src/rendering/mouse_cursor.dart index 6862e54aa2..2fe9c5ea63 100644 --- a/packages/flutter/lib/src/rendering/mouse_cursor.dart +++ b/packages/flutter/lib/src/rendering/mouse_cursor.dart @@ -375,7 +375,7 @@ class SystemMouseCursor extends MouseCursor { final String kind; @override - String get debugDescription => '$runtimeType($kind)'; + String get debugDescription => '${objectRuntimeType(this, 'SystemMouseCursor')}($kind)'; @override @protected diff --git a/packages/flutter/lib/src/widgets/framework.dart b/packages/flutter/lib/src/widgets/framework.dart index b5588b61b1..2a1a2e30e3 100644 --- a/packages/flutter/lib/src/widgets/framework.dart +++ b/packages/flutter/lib/src/widgets/framework.dart @@ -936,7 +936,7 @@ abstract class StatefulWidget extends Widget { /// [State] objects. @protected @factory - State createState(); + State createState(); // ignore: no_logic_in_create_state, this is the original sin } /// Tracks the lifecycle of [State] objects when asserts are enabled. diff --git a/packages/flutter/lib/src/widgets/implicit_animations.dart b/packages/flutter/lib/src/widgets/implicit_animations.dart index cc1095b3d3..2b68e6ebd5 100644 --- a/packages/flutter/lib/src/widgets/implicit_animations.dart +++ b/packages/flutter/lib/src/widgets/implicit_animations.dart @@ -297,7 +297,7 @@ abstract class ImplicitlyAnimatedWidget extends StatefulWidget { final VoidCallback? onEnd; @override - ImplicitlyAnimatedWidgetState createState(); + ImplicitlyAnimatedWidgetState createState(); // ignore: no_logic_in_create_state, https://github.com/dart-lang/linter/issues/2345 @override void debugFillProperties(DiagnosticPropertiesBuilder properties) { diff --git a/packages/flutter/lib/src/widgets/unique_widget.dart b/packages/flutter/lib/src/widgets/unique_widget.dart index ee90cb50bf..30a5e6403d 100644 --- a/packages/flutter/lib/src/widgets/unique_widget.dart +++ b/packages/flutter/lib/src/widgets/unique_widget.dart @@ -28,7 +28,7 @@ abstract class UniqueWidget> extends StatefulWid super(key: key); @override - T createState(); + T createState(); // ignore: no_logic_in_create_state, https://github.com/dart-lang/linter/issues/2345 /// The state for the unique inflated instance of this widget. /// diff --git a/packages/flutter/test/foundation/synchronous_future_test.dart b/packages/flutter/test/foundation/synchronous_future_test.dart index 40cfe1bf16..d38448d22c 100644 --- a/packages/flutter/test/foundation/synchronous_future_test.dart +++ b/packages/flutter/test/foundation/synchronous_future_test.dart @@ -27,8 +27,9 @@ void main() { expect(await stream.single, equals(42)); bool ranAction = false; - final Future completeResult = future.whenComplete(() { + final Future completeResult = future.whenComplete(() { // ignore: void_checks, https://github.com/dart-lang/linter/issues/1675 ranAction = true; + // verify that whenComplete does NOT propagate its return value: return Future.value(31); }); @@ -39,7 +40,7 @@ void main() { Object? exception; try { - await future.whenComplete(() { + await future.whenComplete(() { // ignore: void_checks, https://github.com/dart-lang/linter/issues/1675 throw ArgumentError(); }); // Unreached. diff --git a/packages/flutter/test/painting/mocks_for_image_cache.dart b/packages/flutter/test/painting/mocks_for_image_cache.dart index f044766b21..a93b9e53e0 100644 --- a/packages/flutter/test/painting/mocks_for_image_cache.dart +++ b/packages/flutter/test/painting/mocks_for_image_cache.dart @@ -24,7 +24,7 @@ class TestImageInfo implements ImageInfo { final int value; @override - String toString() => '$runtimeType($value)'; + String toString() => '${objectRuntimeType(this, 'TestImageInfo')}($value)'; @override TestImageInfo clone() { @@ -81,7 +81,7 @@ class TestImageProvider extends ImageProvider { } @override - String toString() => '$runtimeType($key, $imageValue)'; + String toString() => '${objectRuntimeType(this, 'TestImageProvider')}($key, $imageValue)'; } class FailingTestImageProvider extends TestImageProvider { diff --git a/packages/flutter/test/widgets/implicit_animations_test.dart b/packages/flutter/test/widgets/implicit_animations_test.dart index e416495b15..fc781829e4 100644 --- a/packages/flutter/test/widgets/implicit_animations_test.dart +++ b/packages/flutter/test/widgets/implicit_animations_test.dart @@ -374,7 +374,7 @@ class TestAnimatedWidget extends StatefulWidget { final State state; @override - State createState() => state; + State createState() => state; // ignore: no_logic_in_create_state, this test predates the lint } abstract class _TestAnimatedWidgetState extends State { diff --git a/packages/flutter/test/widgets/scroll_physics_test.dart b/packages/flutter/test/widgets/scroll_physics_test.dart index 45bdbf461e..9bb449d736 100644 --- a/packages/flutter/test/widgets/scroll_physics_test.dart +++ b/packages/flutter/test/widgets/scroll_physics_test.dart @@ -29,8 +29,8 @@ class TestScrollPhysics extends ScrollPhysics { @override String toString() { if (parent == null) - return '$runtimeType($name)'; - return '$runtimeType($name) -> $parent'; + return '${objectRuntimeType(this, 'TestScrollPhysics')}($name)'; + return '${objectRuntimeType(this, 'TestScrollPhysics')}($name) -> $parent'; } } diff --git a/packages/flutter/test/widgets/semantics_tester.dart b/packages/flutter/test/widgets/semantics_tester.dart index 570f4adcbf..69f681bdd3 100644 --- a/packages/flutter/test/widgets/semantics_tester.dart +++ b/packages/flutter/test/widgets/semantics_tester.dart @@ -349,7 +349,7 @@ class TestSemantics { String toString([ int indentAmount = 0 ]) { final String indent = ' ' * indentAmount; final StringBuffer buf = StringBuffer(); - buf.writeln('$indent$runtimeType('); + buf.writeln('$indent${objectRuntimeType(this, 'TestSemantics')}('); if (id != null) buf.writeln('$indent id: $id,'); if (flags is int && flags != 0 || flags is List && (flags as List).isNotEmpty) diff --git a/packages/flutter/test/widgets/widget_inspector_test.dart b/packages/flutter/test/widgets/widget_inspector_test.dart index ed6e28298f..15762982b5 100644 --- a/packages/flutter/test/widgets/widget_inspector_test.dart +++ b/packages/flutter/test/widgets/widget_inspector_test.dart @@ -114,7 +114,7 @@ class CyclicDiagnostic extends DiagnosticableTree { final String name; @override - String toStringShort() => '$runtimeType-$name'; + String toStringShort() => '${objectRuntimeType(this, 'CyclicDiagnistic')}-$name'; // We have to override toString to avoid the toString call itself triggering a // stack overflow. diff --git a/packages/flutter_driver/lib/src/driver/driver.dart b/packages/flutter_driver/lib/src/driver/driver.dart index ab5ecb6033..02c59776ab 100644 --- a/packages/flutter_driver/lib/src/driver/driver.dart +++ b/packages/flutter_driver/lib/src/driver/driver.dart @@ -777,7 +777,7 @@ class DriverOffset { final double dy; @override - String toString() => '$runtimeType($dx, $dy)'; + String toString() => '$runtimeType($dx, $dy)'; // ignore: no_runtimetype_tostring, can't access package:flutter here to use objectRuntimeType @override bool operator ==(Object other) { diff --git a/packages/flutter_localizations/test/widgets_test.dart b/packages/flutter_localizations/test/widgets_test.dart index c4ec2d1d9b..c9dc350ec3 100644 --- a/packages/flutter_localizations/test/widgets_test.dart +++ b/packages/flutter_localizations/test/widgets_test.dart @@ -52,7 +52,7 @@ class SyncTestLocalizationsDelegate extends LocalizationsDelegate '$runtimeType($prefix)'; + String toString() => '${objectRuntimeType(this, 'SyncTestLocalizationsDelegate')}($prefix)'; } class AsyncTestLocalizationsDelegate extends LocalizationsDelegate { @@ -74,7 +74,7 @@ class AsyncTestLocalizationsDelegate extends LocalizationsDelegate '$runtimeType($prefix)'; + String toString() => '${objectRuntimeType(this, 'AsyncTestLocalizationsDelegate')}($prefix)'; } class MoreLocalizations {