Skip to content

Commit 9d96df2

Browse files
authored
Modernize framework lints (flutter#179089)
WIP Commits separated as follows: - Update lints in analysis_options files - Run `dart fix --apply` - Clean up leftover analysis issues - Run `dart format .` in the right places. Local analysis and testing passes. Checking CI now. Part of flutter#178827 - Adoption of flutter_lints in examples/api coming in a separate change (cc @loic-sharma) ## Pre-launch Checklist - [ ] I read the [Contributor Guide] and followed the process outlined there for submitting PRs. - [ ] I read the [Tree Hygiene] wiki page, which explains my responsibilities. - [ ] I read and followed the [Flutter Style Guide], including [Features we expect every widget to implement]. - [ ] I signed the [CLA]. - [ ] I listed at least one issue that this PR fixes in the description above. - [ ] I updated/added relevant documentation (doc comments with `///`). - [ ] I added new tests to check the change I am making, or this PR is [test-exempt]. - [ ] I followed the [breaking change policy] and added [Data Driven Fixes] where supported. - [ ] All existing and new tests are passing. If you need help, consider asking for advice on the #hackers-new channel on [Discord]. **Note**: The Flutter team is currently trialing the use of [Gemini Code Assist for GitHub](https://developers.google.com/gemini-code-assist/docs/review-github-code). Comments from the `gemini-code-assist` bot should not be taken as authoritative feedback from the Flutter team. If you find its comments useful you can update your code accordingly, but if you are unsure or disagree with the feedback, please feel free to wait for a Flutter team member's review for guidance on which automated comments should be addressed. <!-- Links --> [Contributor Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#overview [Tree Hygiene]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md [test-exempt]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#tests [Flutter Style Guide]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md [Features we expect every widget to implement]: https://github.com/flutter/flutter/blob/main/docs/contributing/Style-guide-for-Flutter-repo.md#features-we-expect-every-widget-to-implement [CLA]: https://cla.developers.google.com/ [flutter/tests]: https://github.com/flutter/tests [breaking change policy]: https://github.com/flutter/flutter/blob/main/docs/contributing/Tree-hygiene.md#handling-breaking-changes [Discord]: https://github.com/flutter/flutter/blob/main/docs/contributing/Chat.md [Data Driven Fixes]: https://github.com/flutter/flutter/blob/main/docs/contributing/Data-driven-Fixes.md
1 parent 0e4cb8e commit 9d96df2

File tree

2,494 files changed

+38512
-42443
lines changed

Some content is hidden

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

2,494 files changed

+38512
-42443
lines changed

analysis_options.yaml

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ linter:
4040
- always_declare_return_types
4141
- always_put_control_body_on_new_line
4242
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
43-
- always_specify_types
43+
# - always_specify_types # conflicts with omit_obvious_local_variable_types
4444
# - always_use_package_imports # we do this commonly
4545
- annotate_overrides
4646
- annotate_redeclares
47-
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
47+
# - avoid_annotating_with_dynamic # conflicts with type_annotate_public_apis
4848
- avoid_bool_literals_in_conditional_expressions
4949
# - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023
5050
# - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/4998
@@ -78,7 +78,7 @@ linter:
7878
- avoid_slow_async_io
7979
- avoid_type_to_string
8080
- avoid_types_as_parameter_names
81-
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
81+
# - avoid_types_on_closure_parameters # not yet tested
8282
- avoid_unnecessary_containers
8383
- avoid_unused_constructor_parameters
8484
- avoid_void_async
@@ -144,9 +144,9 @@ linter:
144144
- noop_primitive_operations
145145
- null_check_on_nullable_type_parameter
146146
- null_closures
147-
# - omit_local_variable_types # opposite of always_specify_types
148-
# - omit_obvious_local_variable_types # not yet tested
149-
# - omit_obvious_property_types # not yet tested
147+
# - omit_local_variable_types # superset of omit_obvious_local_variable_types
148+
- omit_obvious_local_variable_types # not yet tested
149+
# - omit_obvious_property_types # conflicts with type_annotate_public_apis
150150
# - one_member_abstracts # too many false positives
151151
- only_throw_errors # this does get disabled in a few places where we have legacy code that uses strings et al
152152
- overridden_fields
@@ -204,13 +204,13 @@ linter:
204204
- sort_constructors_first
205205
# - sort_pub_dependencies # prevents separating pinned transitive dependencies
206206
- sort_unnamed_constructors_first
207-
# - specify_nonobvious_local_variable_types # not yet tested
208-
# - specify_nonobvious_property_types # not yet tested
207+
- specify_nonobvious_local_variable_types
208+
- specify_nonobvious_property_types
209209
- strict_top_level_inference
210210
- test_types_in_equals
211211
- throw_in_finally
212212
- tighten_type_of_initializing_formals
213-
# - type_annotate_public_apis # subset of always_specify_types
213+
- type_annotate_public_apis
214214
- type_init_formals
215215
- type_literal_in_constant_pattern
216216
# - unawaited_futures # too many false positives, especially with the way AnimationController works

dev/a11y_assessments/lib/main.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,21 +20,21 @@ class App extends StatelessWidget {
2020

2121
@override
2222
Widget build(BuildContext context) {
23-
final ThemeData lightTheme = ThemeData(
23+
final lightTheme = ThemeData(
2424
colorScheme: ColorScheme.fromSeed(
2525
seedColor: const Color(0xff6750a4),
2626
contrastLevel: MediaQuery.highContrastOf(context) ? 1.0 : 0.0,
2727
),
2828
);
29-
final ThemeData darkTheme = ThemeData(
29+
final darkTheme = ThemeData(
3030
colorScheme: ColorScheme.fromSeed(
3131
brightness: Brightness.dark,
3232
seedColor: const Color(0xff6750a4),
3333
contrastLevel: MediaQuery.highContrastOf(context) ? 1.0 : 0.0,
3434
),
3535
);
3636

37-
final Map<String, WidgetBuilder> routes = Map<String, WidgetBuilder>.fromEntries(
37+
final routes = Map<String, WidgetBuilder>.fromEntries(
3838
useCases.map(
3939
(UseCase useCase) => MapEntry<String, WidgetBuilder>(
4040
useCase.route,

dev/a11y_assessments/test/accessibility_guideline_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ void main() {
4242
final SemanticsFinder tappables = find.semantics.byAction(SemanticsAction.tap);
4343
final int tappableCount = tappables.evaluate().length;
4444

45-
for (int i = 0; i < tappableCount; i++) {
45+
for (var i = 0; i < tappableCount; i++) {
4646
final FinderBase<SemanticsNode> tappable = tappables.at(i);
4747
final SemanticsNode node = tappable.evaluate().first;
4848

dev/a11y_assessments/test/auto_complete_test.dart

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,9 @@ void main() {
3636
await pumpsUseCase(tester, AutoCompleteUseCase());
3737
await tester.pumpAndSettle();
3838

39-
const List<String> kOptions = <String>['apple', 'banana', 'lemon'];
40-
const String label = 'Fruit';
41-
final String message =
42-
'Type below to autocomplete the following possible results: $kOptions.\n$label';
39+
const kOptions = <String>['apple', 'banana', 'lemon'];
40+
const label = 'Fruit';
41+
final message = 'Type below to autocomplete the following possible results: $kOptions.\n$label';
4342

4443
final SemanticsNode node = tester.semantics.find(find.bySemanticsLabel(message));
4544
expect(node.flagsCollection.isTextField, isTrue);

dev/a11y_assessments/test/home_page_test.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import 'test_utils.dart';
3333
void main() {
3434
testWidgets('Has light and dark theme', (WidgetTester tester) async {
3535
await tester.pumpWidget(const App());
36-
final MaterialApp app = find.byType(MaterialApp).evaluate().first.widget as MaterialApp;
36+
final app = find.byType(MaterialApp).evaluate().first.widget as MaterialApp;
3737
expect(app.theme!.brightness, equals(Brightness.light));
3838
expect(app.darkTheme!.brightness, equals(Brightness.dark));
3939
});
@@ -43,7 +43,7 @@ void main() {
4343
const MediaQuery(data: MediaQueryData(highContrast: true), child: App()),
4444
);
4545

46-
final MaterialApp app = find.byType(MaterialApp).evaluate().first.widget as MaterialApp;
46+
final app = find.byType(MaterialApp).evaluate().first.widget as MaterialApp;
4747

4848
final DynamicScheme highContrastScheme = SchemeTonalSpot(
4949
sourceColorHct: Hct.fromInt(const Color(0xff6750a4).value),
@@ -214,7 +214,7 @@ void main() {
214214
});
215215

216216
testWidgets('Each A11y Assessments page has a unique page title.', (WidgetTester tester) async {
217-
final List<MethodCall> log = <MethodCall>[];
217+
final log = <MethodCall>[];
218218

219219
tester.binding.defaultBinaryMessenger.setMockMethodCallHandler(SystemChannels.platform, (
220220
MethodCall methodCall,

dev/a11y_assessments/test/snack_bar_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import 'test_utils.dart';
1010
void main() {
1111
testWidgets('snack bar can run', (WidgetTester tester) async {
1212
await pumpsUseCase(tester, SnackBarUseCase());
13-
const String snackBarText = 'Awesome Snackbar!';
13+
const snackBarText = 'Awesome Snackbar!';
1414
expect(find.text(snackBarText), findsNothing);
1515
await tester.tap(find.text('Show Snackbar'));
1616
expect(find.text(snackBarText), findsNothing);

dev/a11y_assessments/test/text_field_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ void main() {
5959

6060
testWidgets('text field wrapper exists', (WidgetTester tester) async {
6161
await pumpsUseCase(tester, TextFieldUseCase());
62-
const String textFieldLabel = 'Input field with suffix @gmail.com';
62+
const textFieldLabel = 'Input field with suffix @gmail.com';
6363

6464
final Finder semanticsWidgets = find.bySemanticsLabel(RegExp(textFieldLabel));
6565
expect(semanticsWidgets, findsExactly(2));

dev/automated_tests/flutter_test/flutter_gold_test.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -87,12 +87,12 @@ const List<int> _kFailPngBytes = <int>[
8787
];
8888

8989
void main() {
90-
final List<String> log = <String>[];
91-
final MemoryFileSystem fs = MemoryFileSystem();
90+
final log = <String>[];
91+
final fs = MemoryFileSystem();
9292
final Directory basedir = fs.directory('flutter/test/library/')..createSync(recursive: true);
93-
final FakeSkiaGoldClient fakeSkiaClient = FakeSkiaGoldClient()
93+
final fakeSkiaClient = FakeSkiaGoldClient()
9494
..expectationForTestValues['flutter.new_golden_test.1'] = '';
95-
final FlutterLocalFileComparator comparator = FlutterLocalFileComparator(
95+
final comparator = FlutterLocalFileComparator(
9696
basedir.uri,
9797
fakeSkiaClient,
9898
fs: fs,
@@ -112,7 +112,7 @@ void main() {
112112
),
113113
isTrue,
114114
);
115-
const String expectation =
115+
const expectation =
116116
'No expectations provided by Skia Gold for test: library.flutter.new_golden_test.1.png. '
117117
'This may be a new test. If this is an unexpected result, check https://flutter-gold.skia.org.\n'
118118
'Validate image output found at flutter/test/library/';
@@ -128,7 +128,7 @@ void main() {
128128
),
129129
isTrue,
130130
);
131-
const String expectation =
131+
const expectation =
132132
'No expectations provided by Skia Gold for test: library.flutter.new_golden_test.2.png. '
133133
'This may be a new test. If this is an unexpected result, check https://flutter-gold.skia.org.\n'
134134
'Validate image output found at flutter/test/library/';

dev/automated_tests/test_smoke_test/fail_test_on_exception_after_test.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:flutter_test/flutter_test.dart';
1111
// See //flutter/dev/bots/test.dart
1212

1313
void main() {
14-
final Completer<void> complete = Completer<void>();
14+
final complete = Completer<void>();
1515

1616
testWidgets('test smoke test -- this test SHOULD FAIL', (WidgetTester tester) async {
1717
tester.runAsync(() async {

dev/benchmarks/complex_layout/lib/src/app.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ class ItemGalleryBox extends StatelessWidget {
514514

515515
@override
516516
Widget build(BuildContext context) {
517-
final List<String> tabNames = <String>['A', 'B', 'C', 'D'];
517+
final tabNames = <String>['A', 'B', 'C', 'D'];
518518

519519
return SizedBox(
520520
height: 200.0,

0 commit comments

Comments
 (0)