Skip to content

Commit a164beb

Browse files
authored
Sync lints and fix offenders (flutter#308)
1 parent 106fe50 commit a164beb

File tree

58 files changed

+310
-218
lines changed

Some content is hidden

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

58 files changed

+310
-218
lines changed

analysis_options.yaml

Lines changed: 59 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,6 @@
77
# See the configuration guide for more
88
# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer
99
#
10-
# This file contains the analysis options used by Flutter tools, such as
11-
# IntelliJ, Android Studio, and the 'flutter analyze' command.
12-
#
1310
# This file is derived from the master file in the flutter repo, and should be
1411
# kept in sync with it.
1512

@@ -23,8 +20,8 @@ analyzer:
2320
missing_return: warning
2421
# allow having TODOs in the code
2522
todo: ignore
26-
exclude:
27-
- 'flutter/**'
23+
# Turned off until null-safe rollout is complete.
24+
unnecessary_null_comparison: ignore
2825

2926
linter:
3027
rules:
@@ -36,23 +33,28 @@ linter:
3633
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
3734
- always_require_non_null_named_parameters
3835
- always_specify_types
36+
# - always_use_package_imports # we do this commonly
3937
- annotate_overrides
4038
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
41-
# - avoid_as # no longer relevant with null safety
4239
- avoid_bool_literals_in_conditional_expressions
4340
# - avoid_catches_without_on_clauses # we do this commonly
4441
# - avoid_catching_errors # we do this commonly
4542
- avoid_classes_with_only_static_members
4643
# - avoid_double_and_int_checks # only useful when targeting JS runtime
44+
# - avoid_dynamic_calls # not yet tested
4745
- avoid_empty_else
46+
- avoid_equals_and_hash_code_on_mutable_classes
47+
# - avoid_escaping_inner_quotes # not yet tested
4848
- avoid_field_initializers_in_const_classes
4949
- avoid_function_literals_in_foreach_calls
5050
# - avoid_implementing_value_types # not yet tested
5151
- avoid_init_to_null
5252
# - avoid_js_rounded_ints # only useful when targeting JS runtime
5353
- avoid_null_checks_in_equality_operators
5454
# - avoid_positional_boolean_parameters # not yet tested
55+
# - avoid_print # not yet tested
5556
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
57+
# - avoid_redundant_argument_values # not yet tested
5658
- avoid_relative_lib_imports
5759
- avoid_renaming_method_parameters
5860
- avoid_return_types_on_setters
@@ -61,43 +63,57 @@ linter:
6163
- avoid_returning_null_for_void
6264
# - avoid_returning_this # there are plenty of valid reasons to return this
6365
# - avoid_setters_without_getters # not yet tested
64-
# - avoid_shadowing_type_parameters # not yet tested
65-
# - avoid_single_cascade_in_expression_statements # not yet tested
66+
- avoid_shadowing_type_parameters
67+
- avoid_single_cascade_in_expression_statements
6668
- avoid_slow_async_io
69+
- avoid_type_to_string
6770
- avoid_types_as_parameter_names
6871
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
72+
- avoid_unnecessary_containers
6973
- avoid_unused_constructor_parameters
7074
- avoid_void_async
75+
# - avoid_web_libraries_in_flutter # not yet tested
7176
- await_only_futures
77+
- camel_case_extensions
7278
- camel_case_types
7379
- cancel_subscriptions
7480
# - cascade_invocations # not yet tested
81+
- cast_nullable_to_non_nullable
7582
# - close_sinks # not reliable enough
76-
# - comment_references # blocked on https://github.com/flutter/flutter/issues/20765
83+
# - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142
7784
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
7885
- control_flow_in_finally
79-
# - curly_braces_in_flow_control_structures # not yet tested
86+
# - curly_braces_in_flow_control_structures # not required by flutter style
87+
- deprecated_consistency
8088
# - diagnostic_describe_all_properties # not yet tested
8189
- directives_ordering
90+
# - do_not_use_environment # we do this commonly
8291
- empty_catches
8392
- empty_constructor_bodies
8493
- empty_statements
85-
# - file_names # not yet tested
94+
- exhaustive_cases
95+
- file_names
8696
- flutter_style_todos
8797
- hash_and_equals
8898
- implementation_imports
8999
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
90100
- iterable_contains_unrelated_type
91-
# - join_return_with_assignment # not yet tested
101+
# - join_return_with_assignment # not required by flutter style
102+
- leading_newlines_in_multiline_strings
92103
- library_names
93104
- library_prefixes
94-
# - lines_longer_than_80_chars # not yet tested
105+
# - lines_longer_than_80_chars # not required by flutter style
95106
- list_remove_unrelated_type
96107
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
108+
- missing_whitespace_between_adjacent_strings
97109
- no_adjacent_strings_in_list
110+
# - no_default_cases # too many false positives
98111
- no_duplicate_case_values
112+
- no_logic_in_create_state
113+
# - no_runtimeType_toString # ok in tests; we enable this only in packages/
99114
- non_constant_identifier_names
100-
# - null_closures # not yet tested
115+
- null_check_on_nullable_type_parameter
116+
- null_closures
101117
# - omit_local_variable_types # opposite of always_specify_types
102118
# - one_member_abstracts # too many false positives
103119
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
@@ -108,72 +124,88 @@ linter:
108124
# - parameter_assignments # we do this commonly
109125
- prefer_adjacent_string_concatenation
110126
- prefer_asserts_in_initializer_lists
111-
# - prefer_asserts_with_message # not yet tested
127+
# - prefer_asserts_with_message # not required by flutter style
112128
- prefer_collection_literals
113129
- prefer_conditional_assignment
114130
- prefer_const_constructors
115131
- prefer_const_constructors_in_immutables
116132
- prefer_const_declarations
117133
- prefer_const_literals_to_create_immutables
118-
# - prefer_constructors_over_static_methods # not yet tested
134+
# - prefer_constructors_over_static_methods # far too many false positives
119135
- prefer_contains
120136
# - prefer_double_quotes # opposite of prefer_single_quotes
121137
- prefer_equal_for_default_values
122138
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
123139
- prefer_final_fields
124-
# - prefer_final_in_for_each # not yet tested
140+
- prefer_final_in_for_each
125141
- prefer_final_locals
126-
# - prefer_for_elements_to_map_fromIterable # not yet tested
142+
- prefer_for_elements_to_map_fromIterable
127143
- prefer_foreach
128-
# - prefer_function_declarations_over_variables # not yet tested
144+
- prefer_function_declarations_over_variables
129145
- prefer_generic_function_type_aliases
130-
# - prefer_if_elements_to_conditional_expressions # not yet tested
146+
- prefer_if_elements_to_conditional_expressions
131147
- prefer_if_null_operators
132148
- prefer_initializing_formals
133149
- prefer_inlined_adds
134-
# - prefer_int_literals # not yet tested
135-
# - prefer_interpolation_to_compose_strings # not yet tested
150+
# - prefer_int_literals # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-double-literals-for-double-constants
151+
# - prefer_interpolation_to_compose_strings # doesn't work with raw strings, see https://github.com/dart-lang/linter/issues/2490
136152
- prefer_is_empty
137153
- prefer_is_not_empty
154+
- prefer_is_not_operator
138155
- prefer_iterable_whereType
139156
# - prefer_mixin # https://github.com/dart-lang/language/issues/32
140-
# - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932
157+
- prefer_null_aware_operators
158+
# - prefer_relative_imports # incompatible with sub-package imports
141159
- prefer_single_quotes
142160
- prefer_spread_collections
143161
- prefer_typing_uninitialized_variables
144162
- prefer_void_to_null
145-
# - provide_deprecation_message # not yet tested
163+
- provide_deprecation_message
146164
- public_member_api_docs
147165
- recursive_getters
166+
- sized_box_for_whitespace
148167
- slash_for_doc_comments
149168
# - sort_child_properties_last # not yet tested
150169
- sort_constructors_first
151170
- sort_pub_dependencies
152171
- sort_unnamed_constructors_first
153172
- test_types_in_equals
154173
- throw_in_finally
174+
- tighten_type_of_initializing_formals
155175
# - type_annotate_public_apis # subset of always_specify_types
156176
- type_init_formals
157177
# - unawaited_futures # too many false positives
158-
# - unnecessary_await_in_return # not yet tested
178+
- unnecessary_await_in_return
159179
- unnecessary_brace_in_string_interps
160180
- unnecessary_const
181+
# - unnecessary_final # conflicts with prefer_final_locals
161182
- unnecessary_getters_setters
162183
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
163184
- unnecessary_new
164185
- unnecessary_null_aware_assignments
186+
# - unnecessary_null_checks # not yet tested
165187
- unnecessary_null_in_if_null_operators
188+
- unnecessary_nullable_for_final_variable_declarations
166189
- unnecessary_overrides
167190
- unnecessary_parenthesis
191+
# - unnecessary_raw_strings # not yet tested
168192
- unnecessary_statements
193+
- unnecessary_string_escapes
194+
- unnecessary_string_interpolations
169195
- unnecessary_this
170196
- unrelated_type_equality_checks
171197
# - unsafe_html # not yet tested
172198
- use_full_hex_values_for_flutter_colors
173-
# - use_function_type_syntax_for_parameters # not yet tested
199+
- use_function_type_syntax_for_parameters
200+
# - use_if_null_to_convert_nulls_to_bools # not yet tested
201+
- use_is_even_rather_than_modulo
202+
- use_key_in_widget_constructors
203+
- use_late_for_private_fields_and_variables
204+
# - use_named_constants # not yet yested
205+
- use_raw_strings
174206
- use_rethrow_when_possible
175207
# - use_setters_to_change_properties # not yet tested
176208
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
177209
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
178210
- valid_regexps
179-
# - void_checks # not yet tested
211+
- void_checks

packages/animations/example/lib/container_transition.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,9 @@ const double _fabDimension = 56.0;
4040

4141
/// The demo page for [OpenContainerTransform].
4242
class OpenContainerTransformDemo extends StatefulWidget {
43+
/// Creates the demo page for [OpenContainerTransform].
44+
const OpenContainerTransformDemo({Key? key}) : super(key: key);
45+
4346
@override
4447
_OpenContainerTransformDemoState createState() {
4548
return _OpenContainerTransformDemoState();

packages/animations/example/lib/fade_scale_transition.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import 'package:animations/animations.dart';
77

88
/// The demo page for [FadeScaleTransition].
99
class FadeScaleTransitionDemo extends StatefulWidget {
10+
/// Creates the demo page for [FadeScaleTransition].
11+
const FadeScaleTransitionDemo({Key? key}) : super(key: key);
12+
1013
@override
1114
_FadeScaleTransitionDemoState createState() =>
1215
_FadeScaleTransitionDemoState();

packages/animations/example/lib/fade_through_transition.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import 'package:animations/animations.dart';
77

88
/// The demo page for [FadeThroughTransition].
99
class FadeThroughTransitionDemo extends StatefulWidget {
10+
/// Creates the demo page for [FadeThroughTransition].
11+
const FadeThroughTransitionDemo({Key? key}) : super(key: key);
12+
1013
@override
1114
_FadeThroughTransitionDemoState createState() =>
1215
_FadeThroughTransitionDemoState();

packages/animations/example/lib/main.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ class _TransitionsHomePageState extends State<_TransitionsHomePage> {
5151
Navigator.of(context).push(
5252
MaterialPageRoute<void>(
5353
builder: (BuildContext context) {
54-
return OpenContainerTransformDemo();
54+
return const OpenContainerTransformDemo();
5555
},
5656
),
5757
);
@@ -64,7 +64,7 @@ class _TransitionsHomePageState extends State<_TransitionsHomePage> {
6464
Navigator.of(context).push(
6565
MaterialPageRoute<void>(
6666
builder: (BuildContext context) {
67-
return SharedAxisTransitionDemo();
67+
return const SharedAxisTransitionDemo();
6868
},
6969
),
7070
);
@@ -77,7 +77,7 @@ class _TransitionsHomePageState extends State<_TransitionsHomePage> {
7777
Navigator.of(context).push(
7878
MaterialPageRoute<void>(
7979
builder: (BuildContext context) {
80-
return FadeThroughTransitionDemo();
80+
return const FadeThroughTransitionDemo();
8181
},
8282
),
8383
);
@@ -90,7 +90,7 @@ class _TransitionsHomePageState extends State<_TransitionsHomePage> {
9090
Navigator.of(context).push(
9191
MaterialPageRoute<void>(
9292
builder: (BuildContext context) {
93-
return FadeScaleTransitionDemo();
93+
return const FadeScaleTransitionDemo();
9494
},
9595
),
9696
);

packages/animations/example/lib/shared_axis_transition.dart

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@ import 'package:animations/animations.dart';
77

88
/// The demo page for [SharedAxisPageTransitionsBuilder].
99
class SharedAxisTransitionDemo extends StatefulWidget {
10+
/// Creates the demo page for [SharedAxisPageTransitionsBuilder].
11+
const SharedAxisTransitionDemo({Key? key}) : super(key: key);
12+
1013
@override
1114
_SharedAxisTransitionDemoState createState() {
1215
return _SharedAxisTransitionDemoState();

packages/animations/lib/src/fade_through_transition.dart

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,11 +163,12 @@ class FadeThroughTransition extends StatelessWidget {
163163
/// The [animation] and [secondaryAnimation] argument are required and must
164164
/// not be null.
165165
const FadeThroughTransition({
166+
Key? key,
166167
required this.animation,
167168
required this.secondaryAnimation,
168169
this.fillColor,
169170
this.child,
170-
});
171+
}) : super(key: key);
171172

172173
/// The animation that drives the [child]'s entrance and exit.
173174
///

packages/animations/lib/src/open_container.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ class _OpenContainerRoute<T> extends ModalRoute<T> {
649649
final RenderBox navigator = Navigator.of(
650650
navigatorContext,
651651
rootNavigator: useRootNavigator,
652-
).context.findRenderObject() as RenderBox;
652+
).context.findRenderObject()! as RenderBox;
653653
final Size navSize = _getSize(navigator);
654654
_rectTween.end = Offset.zero & navSize;
655655

@@ -680,7 +680,7 @@ class _OpenContainerRoute<T> extends ModalRoute<T> {
680680
assert(key.currentContext != null);
681681
assert(ancestor.hasSize);
682682
final RenderBox render =
683-
key.currentContext!.findRenderObject() as RenderBox;
683+
key.currentContext!.findRenderObject()! as RenderBox;
684684
assert(render.hasSize);
685685
return MatrixUtils.transformRect(
686686
render.getTransformTo(ancestor),

packages/animations/lib/src/page_transition_switcher.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -423,7 +423,7 @@ class _PageTransitionSwitcherState extends State<PageTransitionSwitcher>
423423

424424
@override
425425
void dispose() {
426-
for (_ChildEntry entry in _activeEntries) {
426+
for (final _ChildEntry entry in _activeEntries) {
427427
entry.dispose();
428428
}
429429
super.dispose();

packages/animations/test/fade_through_transition_test.dart

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -477,11 +477,9 @@ class _TestWidget extends StatelessWidget {
477477
builder: (BuildContext context) {
478478
return contentBuilder != null
479479
? contentBuilder!(settings)
480-
: Container(
481-
child: Center(
482-
key: ValueKey<String?>(settings.name),
483-
child: Text(settings.name!),
484-
),
480+
: Center(
481+
key: ValueKey<String?>(settings.name),
482+
child: Text(settings.name!),
485483
);
486484
},
487485
);

0 commit comments

Comments
 (0)