Skip to content

Commit cc3dca6

Browse files
[all] Omit obvious local types (flutter#10511)
Makes the analysis options changes described in flutter/flutter#178827: - Adding [omit_obvious_local_variable_types](https://dart.dev/tools/linter-rules/omit_obvious_local_variable_types) - Adding [specify_nonobvious_local_variable_types](https://dart.dev/tools/linter-rules/specify_nonobvious_local_variable_types) - Adding [specify_nonobvious_property_types](https://dart.dev/tools/linter-rules/specify_nonobvious_property_types) - Adding [type_annotate_public_apis](https://dart.dev/tools/linter-rules/type_annotate_public_apis) - Removing [always_specify_types](https://dart.dev/tools/linter-rules/always_specify_types) After those changes, makes the following repo-wide changes: - `dart fix --apply` in all packages and in script/tool/ - `dart format` in all packages and in script/tool/ - `update-excerpts` repo tooling command to update excerpts based on the changes to their sources Also updates the min Flutter/Dart SDK version to 3.35/3.9 for the following packages, to avoid `analyze` failures in the `N-2` legacy analysis run due to what appears to be a 3.9 change in what the Dart analyzer continues to be an obvious local type in loop iterations: - go_router - google_fonts - google_identity_services_web - google_maps_flutter_web - local_auth_platform_interface - metrics_center - multicast_dns - pigeon - rfw - shared_preferences - two_dimensional_scrollables - vector_graphics_compiler - mustache_template - path_parsing Because this is causing a significant amount of format churn already, I took this opportunity to update the repository tooling to a min Dart SDK of 3.8 (the N-2 stable version, so the earliest version we need the tooling to support) to pick up the new format style, so the amount of automated formatter change is higher in script/tool/ than in the packages. This does contain two manual changes (other than the repo tooling min version): - flutter@d700b45 changes `dynamic` to `Object?` in a few places where `dynamic` caused analyzer warnings under the new rule set. - Updates the repo tooling to ignore `.dart_tool/` when looking for unexpected local `analysis_options.yaml` files, to fix issues running the repo tool's `analyze` command locally based on recent changes in `dart` behavior. This does not include any CHANGELOG or version updates; even though we normally version any changes to production code, mass automated changes like this aren't worth the churn of releasing. This includes changes to lib/example/main.dart and to README.md excerpts; while the style changes will be user-visible on pub.dev, it's fine for those changes to wait for the next release of each package. Part of flutter/flutter#178827
1 parent e019cf9 commit cc3dca6

File tree

1,010 files changed

+38564
-36641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,010 files changed

+38564
-36641
lines changed

analysis_options.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ linter:
2929
- always_declare_return_types
3030
- always_put_control_body_on_new_line
3131
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
32-
- always_specify_types
32+
# - always_specify_types # conflicts with omit_obvious_local_variable_types
3333
# - always_use_package_imports # we do this commonly
3434
- annotate_overrides
3535
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
@@ -128,7 +128,8 @@ linter:
128128
- noop_primitive_operations
129129
- null_check_on_nullable_type_parameter
130130
- null_closures
131-
# - omit_local_variable_types # opposite of always_specify_types
131+
# - omit_local_variable_types # conflicts with specify_nonobvious_local_variable_types
132+
- omit_obvious_local_variable_types
132133
# - one_member_abstracts # too many false positives
133134
- only_throw_errors # this does get disabled in a few places where we have legacy code that uses strings et al
134135
- overridden_fields
@@ -187,10 +188,12 @@ linter:
187188
- sort_constructors_first
188189
- sort_pub_dependencies # DIFFERENT FROM FLUTTER/FLUTTER: Flutter's use case for not sorting does not apply to this repository.
189190
- sort_unnamed_constructors_first
191+
- specify_nonobvious_local_variable_types
192+
- specify_nonobvious_property_types
190193
- test_types_in_equals
191194
- throw_in_finally
192195
- tighten_type_of_initializing_formals
193-
# - type_annotate_public_apis # subset of always_specify_types
196+
- type_annotate_public_apis
194197
- type_init_formals
195198
- type_literal_in_constant_pattern
196199
- unawaited_futures # DIFFERENT FROM FLUTTER/FLUTTER: It's disabled there for "too many false positives"; that's not an issue here, and missing awaits have caused production issues in plugins.

packages/animations/example/lib/container_transition.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ class _ExampleSingleTile extends StatelessWidget {
384384

385385
@override
386386
Widget build(BuildContext context) {
387-
const double height = 100.0;
387+
const height = 100.0;
388388

389389
return _InkWellOverlay(
390390
openContainer: openContainer,

packages/animations/example/lib/shared_axis_transition.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ class _CourseSwitchState extends State<_CourseSwitch> {
152152

153153
@override
154154
Widget build(BuildContext context) {
155-
final String subtitle = _value ? 'Bundled' : 'Shown Individually';
155+
final subtitle = _value ? 'Bundled' : 'Shown Individually';
156156
return SwitchListTile(
157157
title: Text(widget.course),
158158
subtitle: Text(subtitle),

packages/animations/lib/src/open_container.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -643,7 +643,7 @@ class _OpenContainerRoute<T> extends ModalRoute<T> {
643643
required BuildContext navigatorContext,
644644
bool delayForSourceRoute = false,
645645
}) {
646-
final RenderBox navigator =
646+
final navigator =
647647
Navigator.of(
648648
navigatorContext,
649649
rootNavigator: useRootNavigator,
@@ -679,8 +679,7 @@ class _OpenContainerRoute<T> extends ModalRoute<T> {
679679
Rect _getRect(GlobalKey key, RenderBox ancestor) {
680680
assert(key.currentContext != null);
681681
assert(ancestor.hasSize);
682-
final RenderBox render =
683-
key.currentContext!.findRenderObject()! as RenderBox;
682+
final render = key.currentContext!.findRenderObject()! as RenderBox;
684683
assert(render.hasSize);
685684
return MatrixUtils.transformRect(
686685
render.getTransformTo(ancestor),
@@ -689,8 +688,8 @@ class _OpenContainerRoute<T> extends ModalRoute<T> {
689688
}
690689

691690
bool get _transitionWasInterrupted {
692-
bool wasInProgress = false;
693-
bool isInProgress = false;
691+
var wasInProgress = false;
692+
var isInProgress = false;
694693

695694
switch (_currentAnimationStatus) {
696695
case AnimationStatus.completed:
@@ -884,8 +883,8 @@ class _FlippableTweenSequence<T> extends TweenSequence<T> {
884883

885884
_FlippableTweenSequence<T>? get flipped {
886885
if (_flipped == null) {
887-
final List<TweenSequenceItem<T>> newItems = <TweenSequenceItem<T>>[];
888-
for (int i = 0; i < _items.length; i++) {
886+
final newItems = <TweenSequenceItem<T>>[];
887+
for (var i = 0; i < _items.length; i++) {
889888
newItems.add(
890889
TweenSequenceItem<T>(
891890
tween: _items[i].tween,

packages/animations/lib/src/page_transition_switcher.dart

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -293,8 +293,8 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
293293
_activeEntries.forEach(_updateTransitionForEntry);
294294
}
295295

296-
final bool hasNewChild = widget.child != null;
297-
final bool hasOldChild = _currentEntry != null;
296+
final hasNewChild = widget.child != null;
297+
final hasOldChild = _currentEntry != null;
298298
if (hasNewChild != hasOldChild ||
299299
hasNewChild &&
300300
!Widget.canUpdate(widget.child!, _currentEntry!.widgetChild)) {
@@ -327,11 +327,11 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
327327
if (widget.child == null) {
328328
return;
329329
}
330-
final AnimationController primaryController = AnimationController(
330+
final primaryController = AnimationController(
331331
duration: widget.duration,
332332
vsync: this,
333333
);
334-
final AnimationController secondaryController = AnimationController(
334+
final secondaryController = AnimationController(
335335
duration: widget.duration,
336336
vsync: this,
337337
);
@@ -373,7 +373,7 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
373373
primaryController,
374374
secondaryController,
375375
);
376-
final _ChildEntry entry = _ChildEntry(
376+
final entry = _ChildEntry(
377377
widgetChild: child,
378378
transition: KeyedSubtree.wrap(transition, _childNumber),
379379
primaryController: primaryController,

packages/animations/test/dual_transition_builder_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import 'package:flutter_test/flutter_test.dart';
77

88
void main() {
99
testWidgets('runs animations', (WidgetTester tester) async {
10-
final AnimationController controller = AnimationController(
10+
final controller = AnimationController(
1111
vsync: const TestVSync(),
1212
duration: const Duration(milliseconds: 300),
1313
);
@@ -75,7 +75,7 @@ void main() {
7575
});
7676

7777
testWidgets('keeps state', (WidgetTester tester) async {
78-
final AnimationController controller = AnimationController(
78+
final controller = AnimationController(
7979
vsync: const TestVSync(),
8080
duration: const Duration(milliseconds: 300),
8181
);
@@ -146,7 +146,7 @@ void main() {
146146
testWidgets('does not jump when interrupted - forward', (
147147
WidgetTester tester,
148148
) async {
149-
final AnimationController controller = AnimationController(
149+
final controller = AnimationController(
150150
vsync: const TestVSync(),
151151
duration: const Duration(milliseconds: 300),
152152
);
@@ -212,7 +212,7 @@ void main() {
212212
testWidgets('does not jump when interrupted - reverse', (
213213
WidgetTester tester,
214214
) async {
215-
final AnimationController controller = AnimationController(
215+
final controller = AnimationController(
216216
value: 1.0,
217217
vsync: const TestVSync(),
218218
duration: const Duration(milliseconds: 300),

packages/animations/test/fade_scale_transition_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -361,7 +361,7 @@ void main() {
361361
});
362362

363363
testWidgets('should preserve state', (WidgetTester tester) async {
364-
final AnimationController controller = AnimationController(
364+
final controller = AnimationController(
365365
vsync: const TestVSync(),
366366
duration: const Duration(milliseconds: 300),
367367
);
@@ -416,7 +416,7 @@ double _getOpacity(GlobalKey key, WidgetTester tester) {
416416
matching: find.byType(FadeTransition),
417417
);
418418
return tester.widgetList(finder).fold<double>(1.0, (double a, Widget widget) {
419-
final FadeTransition transition = widget as FadeTransition;
419+
final transition = widget as FadeTransition;
420420
return a * transition.opacity.value;
421421
});
422422
}
@@ -427,7 +427,7 @@ double _getScale(GlobalKey key, WidgetTester tester) {
427427
matching: find.byType(ScaleTransition),
428428
);
429429
return tester.widgetList(finder).fold<double>(1.0, (double a, Widget widget) {
430-
final ScaleTransition transition = widget as ScaleTransition;
430+
final transition = widget as ScaleTransition;
431431
return a * transition.scale.value;
432432
});
433433
}

packages/animations/test/fade_through_transition_test.dart

Lines changed: 18 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,8 @@ void main() {
1010
testWidgets(
1111
'FadeThroughPageTransitionsBuilder builds a FadeThroughTransition',
1212
(WidgetTester tester) async {
13-
final AnimationController animation = AnimationController(
14-
vsync: const TestVSync(),
15-
);
16-
final AnimationController secondaryAnimation = AnimationController(
17-
vsync: const TestVSync(),
18-
);
13+
final animation = AnimationController(vsync: const TestVSync());
14+
final secondaryAnimation = AnimationController(vsync: const TestVSync());
1915

2016
await tester.pumpWidget(
2117
const FadeThroughPageTransitionsBuilder().buildTransitions<void>(
@@ -34,9 +30,9 @@ void main() {
3430
testWidgets('FadeThroughTransition runs forward', (
3531
WidgetTester tester,
3632
) async {
37-
final GlobalKey<NavigatorState> navigator = GlobalKey<NavigatorState>();
38-
const String bottomRoute = '/';
39-
const String topRoute = '/a';
33+
final navigator = GlobalKey<NavigatorState>();
34+
const bottomRoute = '/';
35+
const topRoute = '/a';
4036

4137
await tester.pumpWidget(_TestWidget(navigatorKey: navigator));
4238
expect(find.text(bottomRoute), findsOneWidget);
@@ -116,9 +112,9 @@ void main() {
116112
testWidgets('FadeThroughTransition runs backwards', (
117113
WidgetTester tester,
118114
) async {
119-
final GlobalKey<NavigatorState> navigator = GlobalKey<NavigatorState>();
120-
const String bottomRoute = '/';
121-
const String topRoute = '/a';
115+
final navigator = GlobalKey<NavigatorState>();
116+
const bottomRoute = '/';
117+
const topRoute = '/a';
122118

123119
await tester.pumpWidget(_TestWidget(navigatorKey: navigator));
124120
navigator.currentState!.pushNamed('/a');
@@ -206,9 +202,9 @@ void main() {
206202
testWidgets('FadeThroughTransition does not jump when interrupted', (
207203
WidgetTester tester,
208204
) async {
209-
final GlobalKey<NavigatorState> navigator = GlobalKey<NavigatorState>();
210-
const String bottomRoute = '/';
211-
const String topRoute = '/a';
205+
final navigator = GlobalKey<NavigatorState>();
206+
const bottomRoute = '/';
207+
const topRoute = '/a';
212208

213209
await tester.pumpWidget(_TestWidget(navigatorKey: navigator));
214210
expect(find.text(bottomRoute), findsOneWidget);
@@ -271,9 +267,9 @@ void main() {
271267
testWidgets('State is not lost when transitioning', (
272268
WidgetTester tester,
273269
) async {
274-
final GlobalKey<NavigatorState> navigator = GlobalKey<NavigatorState>();
275-
const String bottomRoute = '/';
276-
const String topRoute = '/a';
270+
final navigator = GlobalKey<NavigatorState>();
271+
const bottomRoute = '/';
272+
const topRoute = '/a';
277273

278274
await tester.pumpWidget(
279275
_TestWidget(
@@ -358,11 +354,11 @@ void main() {
358354
});
359355

360356
testWidgets('should keep state', (WidgetTester tester) async {
361-
final AnimationController animation = AnimationController(
357+
final animation = AnimationController(
362358
vsync: const TestVSync(),
363359
duration: const Duration(milliseconds: 300),
364360
);
365-
final AnimationController secondaryAnimation = AnimationController(
361+
final secondaryAnimation = AnimationController(
366362
vsync: const TestVSync(),
367363
duration: const Duration(milliseconds: 300),
368364
);
@@ -431,7 +427,7 @@ double _getOpacity(String key, WidgetTester tester) {
431427
matching: find.byType(FadeTransition),
432428
);
433429
return tester.widgetList(finder).fold<double>(1.0, (double a, Widget widget) {
434-
final FadeTransition transition = widget as FadeTransition;
430+
final transition = widget as FadeTransition;
435431
return a * transition.opacity.value;
436432
});
437433
}
@@ -442,7 +438,7 @@ double _getScale(String key, WidgetTester tester) {
442438
matching: find.byType(ScaleTransition),
443439
);
444440
return tester.widgetList(finder).fold<double>(1.0, (double a, Widget widget) {
445-
final ScaleTransition transition = widget as ScaleTransition;
441+
final transition = widget as ScaleTransition;
446442
return a * transition.scale.value;
447443
});
448444
}

packages/animations/test/modal_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ void main() {
430430
testWidgets('showModal builds a new route with specified route settings', (
431431
WidgetTester tester,
432432
) async {
433-
const RouteSettings routeSettings = RouteSettings(
433+
const routeSettings = RouteSettings(
434434
name: 'route-name',
435435
arguments: 'arguments',
436436
);
@@ -473,7 +473,7 @@ void main() {
473473
testWidgets('showModal builds a new route with specified image filter', (
474474
WidgetTester tester,
475475
) async {
476-
final ui.ImageFilter filter = ui.ImageFilter.blur(sigmaX: 1, sigmaY: 1);
476+
final filter = ui.ImageFilter.blur(sigmaX: 1, sigmaY: 1);
477477

478478
final Widget button = Builder(
479479
builder: (BuildContext context) {
@@ -518,7 +518,7 @@ double _getOpacity(GlobalKey key, WidgetTester tester) {
518518
matching: find.byType(FadeTransition),
519519
);
520520
return tester.widgetList(finder).fold<double>(1.0, (double a, Widget widget) {
521-
final FadeTransition transition = widget as FadeTransition;
521+
final transition = widget as FadeTransition;
522522
return a * transition.opacity.value;
523523
});
524524
}
@@ -529,7 +529,7 @@ double _getScale(GlobalKey key, WidgetTester tester) {
529529
matching: find.byType(ScaleTransition),
530530
);
531531
return tester.widgetList(finder).fold<double>(1.0, (double a, Widget widget) {
532-
final ScaleTransition transition = widget as ScaleTransition;
532+
final transition = widget as ScaleTransition;
533533
return a * transition.scale.value;
534534
});
535535
}

0 commit comments

Comments
 (0)