Skip to content

Commit 4d781dd

Browse files
authored
Merge pull request #444 from AhmedLSayed9/update_analysis_options
Update lint rules to match flutter's new lint set
2 parents 38f2619 + 42f2f61 commit 4d781dd

8 files changed

Lines changed: 79 additions & 59 deletions

File tree

analysis_options.yaml

Lines changed: 46 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
11
# Lint rules of flutter/packages with some modifications.
22
#
33
# This file is a copy of analysis_options.yaml from flutter repo
4-
# as of 2022-07-27, but with some modifications marked with
4+
# as of 2023-12-18, but with some modifications marked with
55
# "DIFFERENT FROM FLUTTER/FLUTTER" below. The file is expected to
66
# be kept in sync with the master file from the flutter repo.
77

88
analyzer:
99
language:
1010
strict-casts: true
11-
strict-raw-types: true
1211
strict-inference: true
12+
strict-raw-types: true
1313
errors:
14+
# deprecated_member_use: ignore # DIFFERENT FROM FLUTTER/FLUTTER: keep visible as migration signals.
1415
# allow self-reference to deprecated members (we do this because otherwise we have
1516
# to annotate every member in every test, assert, etc, when we deprecate something)
1617
deprecated_member_use_from_same_package: ignore
1718
exclude: # DIFFERENT FROM FLUTTER/FLUTTER
1819
# Ignore generated files
20+
- "**/*.pb.dart"
1921
- "**/*.g.dart"
2022
- "**/*.mocks.dart" # Mockito @GenerateMocks
2123

@@ -27,18 +29,18 @@ formatter:
2729
linter:
2830
rules:
2931
# This list is derived from the list of all available lints located at
30-
# https://github.com/dart-lang/linter/blob/master/example/all.yaml
32+
# https://github.com/dart-lang/linter/blob/main/example/all.yaml
3133
- always_declare_return_types
3234
- always_put_control_body_on_new_line
3335
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
34-
# - always_specify_types # removed for redundancy: https://github.com/dart-lang/linter/issues/1848
36+
# - always_specify_types # removed for redundancy: https://github.com/dart-lang/linter/issues/1848
3537
# - always_use_package_imports # we do this commonly
3638
- annotate_overrides
3739
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
3840
- avoid_bool_literals_in_conditional_expressions
3941
# - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023
4042
# - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/3023
41-
# - avoid_classes_with_only_static_members: false # False positive for custom enum-like classes (such as Flutter's "Colors")
43+
# - avoid_classes_with_only_static_members # we do this commonly for `abstract final class`es
4244
- avoid_double_and_int_checks
4345
- avoid_dynamic_calls
4446
- avoid_empty_else
@@ -47,11 +49,10 @@ linter:
4749
- avoid_field_initializers_in_const_classes
4850
# - avoid_final_parameters # incompatible with prefer_final_parameters
4951
- avoid_function_literals_in_foreach_calls
50-
- avoid_implementing_value_types
52+
# - avoid_implementing_value_types # see https://github.com/dart-lang/linter/issues/4558
5153
- avoid_init_to_null
5254
- avoid_js_rounded_ints
5355
# - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to
54-
- avoid_null_checks_in_equality_operators
5556
# - avoid_positional_boolean_parameters # would have been nice to enable this but by now there's too many places that break it
5657
- avoid_print
5758
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
@@ -79,17 +80,20 @@ linter:
7980
# - cascade_invocations # doesn't match the typical style of this repo
8081
- cast_nullable_to_non_nullable
8182
# - close_sinks # not reliable enough
82-
# - combinators_ordering # DIFFERENT FROM FLUTTER/FLUTTER: This isn't available on stable yet.
83+
- collection_methods_unrelated_type
84+
- combinators_ordering
8385
# - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142
8486
- conditional_uri_does_not_exist
8587
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
8688
- control_flow_in_finally
8789
- curly_braces_in_flow_control_structures
90+
- dangling_library_doc_comments
8891
- depend_on_referenced_packages
8992
- deprecated_consistency
93+
# - deprecated_member_use_from_same_package # we allow self-references to deprecated members
9094
# - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib)
9195
- directives_ordering
92-
# - discarded_futures # not yet tested
96+
# - discarded_futures # too many false positives, similar to unawaited_futures
9397
# - do_not_use_environment # there are appropriate times to use the environment, especially in our tests and build logic
9498
- empty_catches
9599
- empty_constructor_bodies
@@ -100,30 +104,40 @@ linter:
100104
- flutter_style_todos
101105
- hash_and_equals
102106
- implementation_imports
103-
- collection_methods_unrelated_type
107+
- implicit_call_tearoffs
108+
- implicit_reopen
109+
- invalid_case_patterns
104110
# - join_return_with_assignment # not required by flutter style
105111
- leading_newlines_in_multiline_strings
112+
- library_annotations
106113
- library_names
107114
- library_prefixes
108115
- library_private_types_in_public_api
109116
# - lines_longer_than_80_chars # not required by flutter style
110-
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/linter/issues/453
117+
- literal_only_boolean_expressions
118+
# - matching_super_parameters # blocked on https://github.com/dart-lang/language/issues/2509
119+
- missing_code_block_language_in_doc_comment
111120
- missing_whitespace_between_adjacent_strings
112-
- no_adjacent_strings_in_list
121+
# - no_adjacent_strings_in_list # conflicts with prefer_adjacent_string_concatenation
113122
- no_default_cases
114123
- no_duplicate_case_values
115124
- no_leading_underscores_for_library_prefixes
116125
- no_leading_underscores_for_local_identifiers
126+
- no_literal_bool_comparisons
117127
- no_logic_in_create_state
118128
- no_runtimeType_toString # DIFFERENT FROM FLUTTER/FLUTTER
129+
- no_self_assignments
130+
- no_wildcard_variable_uses
119131
- non_constant_identifier_names
120132
- noop_primitive_operations
121133
- null_check_on_nullable_type_parameter
122134
- null_closures
123-
# - omit_local_variable_types # opposite of always_specify_types
135+
# - omit_local_variable_types # conflicts with specify_nonobvious_local_variable_types
136+
- omit_obvious_local_variable_types
124137
# - one_member_abstracts # too many false positives
125138
- only_throw_errors # this does get disabled in a few places where we have legacy code that uses strings et al
126139
- overridden_fields
140+
# - package_api_docs # Deprecated (https://github.com/dart-lang/linter/issues/5107)
127141
- package_names
128142
- package_prefixed_library_names
129143
# - parameter_assignments # we do this commonly
@@ -139,11 +153,11 @@ linter:
139153
# - prefer_constructors_over_static_methods # far too many false positives
140154
- prefer_contains
141155
# - prefer_double_quotes # opposite of prefer_single_quotes
142-
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
156+
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md#consider-using--for-short-functions-and-methods
143157
- prefer_final_fields
144158
- prefer_final_in_for_each
145159
- prefer_final_locals
146-
# - prefer_final_parameters # we should enable this one day when it can be auto-fixed (https://github.com/dart-lang/linter/issues/3104), see also parameter_assignments
160+
# - prefer_final_parameters # adds too much verbosity
147161
- prefer_for_elements_to_map_fromIterable
148162
- prefer_foreach
149163
- prefer_function_declarations_over_variables
@@ -152,13 +166,13 @@ linter:
152166
- prefer_if_null_operators
153167
- prefer_initializing_formals
154168
- prefer_inlined_adds
155-
# - prefer_int_literals # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-double-literals-for-double-constants
169+
# - prefer_int_literals # conflicts with https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md#use-double-literals-for-double-constants
156170
- prefer_interpolation_to_compose_strings
157171
- prefer_is_empty
158172
- prefer_is_not_empty
159173
- prefer_is_not_operator
160174
- prefer_iterable_whereType
161-
# - prefer_mixin # Has false positives, see https://github.com/dart-lang/linter/issues/3018
175+
- prefer_mixin
162176
# - prefer_null_aware_method_calls # "call()" is confusing to people new to the language since it's not documented anywhere
163177
- prefer_null_aware_operators
164178
- prefer_relative_imports
@@ -169,28 +183,35 @@ linter:
169183
- provide_deprecation_message
170184
- public_member_api_docs # DIFFERENT FROM FLUTTER/FLUTTER
171185
- recursive_getters
172-
# - require_trailing_commas # blocked on https://github.com/dart-lang/sdk/issues/47441
186+
# - require_trailing_commas # would be nice, but requires a lot of manual work: 10,000+ code locations would need to be reformatted by hand after bulk fix is applied
173187
- secure_pubspec_urls
174188
- sized_box_for_whitespace
175-
# - sized_box_shrink_expand # not yet tested
189+
- sized_box_shrink_expand
176190
- slash_for_doc_comments
177191
- sort_child_properties_last
178192
- sort_constructors_first
193+
# - sort_pub_dependencies
179194
- sort_unnamed_constructors_first
195+
# - specify_nonobvious_local_variable_types # DIFFERENT FROM FLUTTER/FLUTTER: prefer not requiring explicit types for locals as hover/IDE shows them anyway.
196+
- specify_nonobvious_property_types
180197
- test_types_in_equals
181198
- throw_in_finally
182199
- tighten_type_of_initializing_formals
183-
- type_annotate_public_apis # subset of always_specify_types
200+
- type_annotate_public_apis
184201
- type_init_formals
202+
- type_literal_in_constant_pattern
203+
- unintended_html_in_doc_comment # DIFFERENT FROM FLUTTER/FLUTTER: Disabled due to an issue that has been fixed, so just hasn't been adopted there yet.
185204
- 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.
186205
- unnecessary_await_in_return
187206
- unnecessary_brace_in_string_interps
207+
- unnecessary_breaks
188208
- unnecessary_const
189209
- unnecessary_constructor_name
190210
# - unnecessary_final # conflicts with prefer_final_locals
191211
- unnecessary_getters_setters
192212
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
193213
- unnecessary_late
214+
- unnecessary_library_directive
194215
- unnecessary_new
195216
- unnecessary_null_aware_assignments
196217
- unnecessary_null_aware_operator_on_extension_on_nullable
@@ -205,11 +226,12 @@ linter:
205226
- unnecessary_string_interpolations
206227
- unnecessary_this
207228
- unnecessary_to_list_in_spreads
229+
- unreachable_from_main
208230
- unrelated_type_equality_checks
209231
- use_build_context_synchronously
210-
# - use_colored_box # not yet tested
211-
# - use_decorated_box # not yet tested
212-
# - use_enums # not yet tested
232+
- use_colored_box
233+
# - use_decorated_box # leads to bugs: DecoratedBox and Container are not equivalent (Container inserts extra padding)
234+
- use_enums
213235
- use_full_hex_values_for_flutter_colors
214236
- use_function_type_syntax_for_parameters
215237
- use_if_null_to_convert_nulls_to_bools
@@ -221,6 +243,7 @@ linter:
221243
- use_rethrow_when_possible
222244
- use_setters_to_change_properties
223245
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
246+
- use_string_in_part_of_directives
224247
- use_super_parameters
225248
- use_test_throws_matchers
226249
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1 @@
1-
library dropdown_button2;
2-
31
export 'src/dropdown_button2.dart';

packages/dropdown_button2/lib/src/dropdown_button2.dart

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -448,7 +448,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
448448
// Using ValueNotifier for tracking when menu is open/close to update the button icon.
449449
final ValueNotifier<bool> _isMenuExpanded = ValueNotifier<bool>(false);
450450

451-
final _buttonRectKey = GlobalKey();
451+
final GlobalKey<State<StatefulWidget>> _buttonRectKey = GlobalKey();
452452

453453
// Using ValueNotifier for the Rect of DropdownButton so the dropdown menu listen and
454454
// update its position if DropdownButton's position has changed, as when keyboard open.
@@ -583,7 +583,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
583583
return;
584584
}
585585

586-
for (int itemIndex = 0; itemIndex < widget.items!.length; itemIndex++) {
586+
for (var itemIndex = 0; itemIndex < widget.items!.length; itemIndex++) {
587587
if (widget.items![itemIndex].value == _currentValue) {
588588
_selectedIndex = itemIndex;
589589
return;
@@ -623,7 +623,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
623623
rootNavigator: _dropdownStyle.isFullScreen ?? _dropdownStyle.useRootNavigator,
624624
);
625625

626-
final RenderBox itemBox = _buttonRectKey.currentContext!.findRenderObject()! as RenderBox;
626+
final itemBox = _buttonRectKey.currentContext!.findRenderObject()! as RenderBox;
627627
final Rect itemRect =
628628
itemBox.localToGlobal(Offset.zero, ancestor: navigator.context.findRenderObject()) &
629629
itemBox.size;
@@ -850,7 +850,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
850850
// We should explicitly type the items list to be a list of <Widget>,
851851
// otherwise, no explicit type adding items maybe trigger a crash/failure
852852
// when hint and selectedItemBuilder are provided.
853-
final List<Widget> buttonItems = widget.selectedItemBuilder == null
853+
final buttonItems = widget.selectedItemBuilder == null
854854
? (widget.items != null ? List<Widget>.of(widget.items!) : <Widget>[])
855855
: List<Widget>.of(widget.selectedItemBuilder!(context));
856856

@@ -968,7 +968,7 @@ class _DropdownButton2State<T> extends State<DropdownButton2<T>> with WidgetsBin
968968
);
969969

970970
if (!DropdownButtonHideUnderline.at(context)) {
971-
final double bottom = widget.isDense ? 0.0 : 8.0;
971+
final bottom = widget.isDense ? 0.0 : 8.0;
972972
result = Stack(
973973
children: <Widget>[
974974
result,
@@ -1160,8 +1160,7 @@ class DropdownButtonFormField2<T> extends FormField<T> {
11601160
: multiValueListenable?.value.lastOrNull,
11611161
autovalidateMode: autovalidateMode ?? AutovalidateMode.disabled,
11621162
builder: (FormFieldState<T> field) {
1163-
final _DropdownButtonFormField2State<T> state =
1164-
field as _DropdownButtonFormField2State<T>;
1163+
final state = field as _DropdownButtonFormField2State<T>;
11651164
InputDecoration effectiveDecoration = (decoration ?? const InputDecoration())
11661165
.applyDefaults(Theme.of(field.context).inputDecorationTheme);
11671166

packages/dropdown_button2/lib/src/dropdown_menu.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -294,19 +294,19 @@ class _DropdownMenuPainter extends CustomPainter {
294294

295295
@override
296296
void paint(Canvas canvas, Size size) {
297-
final Tween<double> top = Tween<double>(
297+
final top = Tween<double>(
298298
//Begin at 0.0 instead of selectedItemOffset so that the menu open animation
299299
//always start from top to bottom instead of starting from the selected item
300300
begin: 0.0,
301301
end: 0.0,
302302
);
303303

304-
final Tween<double> bottom = Tween<double>(
304+
final bottom = Tween<double>(
305305
begin: clampDouble(top.begin! + itemHeight, math.min(itemHeight, size.height), size.height),
306306
end: size.height,
307307
);
308308

309-
final Rect rect = Rect.fromLTRB(0.0, top.evaluate(resize), size.width, bottom.evaluate(resize));
309+
final rect = Rect.fromLTRB(0.0, top.evaluate(resize), size.width, bottom.evaluate(resize));
310310

311311
_painter.paint(
312312
canvas,

packages/dropdown_button2/lib/src/dropdown_route.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
211211
bool Function(DropdownItem<T> item)? itemPredicate,
212212
}) {
213213
var itemsHeight = 0.0;
214-
for (int i = 0; i < index; i++) {
214+
for (var i = 0; i < index; i++) {
215215
if (itemPredicate == null || itemPredicate(items[i])) {
216216
itemsHeight += _itemHeightWithSeparator(i);
217217
}
@@ -223,7 +223,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
223223
final double paddingTop = dropdownStyle.padding != null
224224
? dropdownStyle.padding!.resolve(null).top
225225
: kMaterialListPadding.top;
226-
double offset = paddingTop;
226+
var offset = paddingTop;
227227

228228
if (items.isNotEmpty && index > 0) {
229229
if (searchData?.searchController?.text case final searchText?) {
@@ -279,7 +279,7 @@ class _DropdownRoute<T> extends PopupRoute<_DropdownRouteResult<T>> {
279279
final double menuHeight = math.min(maxHeight, actualMenuHeight);
280280

281281
// The computed top and bottom of the menu
282-
double menuTop = menuAnchoredTop;
282+
var menuTop = menuAnchoredTop;
283283
double menuBottom = menuTop + menuHeight;
284284

285285
// If the computed top or bottom of the menu are outside of the range
@@ -633,7 +633,7 @@ class _DropdownBarrierPainter extends CustomPainter {
633633
canvas.saveLayer(pageRect, Paint());
634634
canvas.drawRect(pageRect, Paint()..color = barrierColor!);
635635

636-
final RRect buttonRRect = RRect.fromRectAndCorners(
636+
final buttonRRect = RRect.fromRectAndCorners(
637637
buttonRect,
638638
topLeft: buttonBorderRadius.topLeft,
639639
topRight: buttonBorderRadius.topRight,

0 commit comments

Comments
 (0)