1
1
# Specify analysis options.
2
2
#
3
- # Until there are meta linter rules, each desired lint must be explicitly enabled.
4
- # See: https://github.com/dart-lang/linter/issues/288
5
- #
6
3
# For a list of lints, see: http://dart-lang.github.io/linter/lints/
7
4
# See the configuration guide for more
8
- # https://github.com/dart-lang/sdk/tree/master /pkg/analyzer#configuring-the-analyzer
5
+ # https://github.com/dart-lang/sdk/tree/main /pkg/analyzer#configuring-the-analyzer
9
6
#
10
7
# There are other similar analysis options files in the flutter repos,
11
8
# which should be kept in sync with this file:
12
9
#
13
10
# - analysis_options.yaml (this file)
14
- # - packages/flutter/lib/analysis_options_user.yaml
15
11
# - https://github.com/flutter/plugins/blob/master/analysis_options.yaml
16
12
# - https://github.com/flutter/engine/blob/master/analysis_options.yaml
13
+ # - https://github.com/flutter/packages/blob/master/analysis_options.yaml
17
14
#
18
- # This file contains the analysis options used by Flutter tools, such as IntelliJ,
19
- # Android Studio, and the `flutter analyze` command .
15
+ # This file contains the analysis options used for code in the flutter/flutter
16
+ # repository .
20
17
21
18
analyzer :
22
- strong-mode :
23
- implicit -casts : false
24
- implicit-dynamic : false
19
+ language :
20
+ strict -casts : true
21
+ strict-raw-types : true
25
22
errors :
26
23
# treat missing required parameters as a warning (not a hint)
27
24
missing_required_param : warning
28
25
# treat missing returns as a warning (not a hint)
29
26
missing_return : warning
30
- # allow having TODOs in the code
27
+ # allow having TODO comments in the code
31
28
todo : ignore
32
- # allow self-reference to deprecated members (we do this because otherwise we have
33
- # to annotate every member in every test, assert, etc, when we deprecate something)
34
- deprecated_member_use_from_same_package : ignore
35
- # Ignore analyzer hints for updating pubspecs when using Future or
36
- # Stream and not importing dart:async
37
- # Please see https://github.com/flutter/flutter/pull/24528 for details.
38
- sdk_version_async_exported_from_core : ignore
39
- exclude :
40
- - " bin/cache/**"
41
- # the following two are relative to the stocks example and the flutter package respectively
42
- # see https://github.com/dart-lang/sdk/issues/28463
43
- - " lib/i18n/messages_*.dart"
44
- - " lib/src/http/**"
45
- - " test_fixes/**"
46
29
47
30
linter :
48
31
rules :
49
- # these rules are documented on and in the same order as
50
- # the Dart Lint rules page to make maintenance easier
32
+ # This list is derived from the list of all available lints located at
51
33
# https://github.com/dart-lang/linter/blob/master/example/all.yaml
52
34
- always_declare_return_types
53
35
- always_put_control_body_on_new_line
@@ -57,62 +39,68 @@ linter:
57
39
# - always_use_package_imports # we do this commonly
58
40
- annotate_overrides
59
41
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
60
- # - avoid_as # required for implicit-casts: true
61
42
- avoid_bool_literals_in_conditional_expressions
62
- # - avoid_catches_without_on_clauses # we do this commonly
63
- # - avoid_catching_errors # we do this commonly
43
+ # - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023
44
+ # - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/3023
64
45
- avoid_classes_with_only_static_members
65
- # - avoid_double_and_int_checks # only useful when targeting JS runtime
46
+ - avoid_double_and_int_checks
47
+ - avoid_dynamic_calls
66
48
- avoid_empty_else
67
49
- avoid_equals_and_hash_code_on_mutable_classes
68
- # - avoid_escaping_inner_quotes # not yet tested
50
+ - avoid_escaping_inner_quotes
69
51
- avoid_field_initializers_in_const_classes
52
+ # - avoid_final_parameters # incompatible with prefer_final_parameters
70
53
- avoid_function_literals_in_foreach_calls
71
- # - avoid_implementing_value_types # not yet tested
54
+ - avoid_implementing_value_types
72
55
- avoid_init_to_null
73
- # - avoid_js_rounded_ints # only useful when targeting JS runtime
56
+ - avoid_js_rounded_ints
57
+ # - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to
74
58
- avoid_null_checks_in_equality_operators
75
- # - avoid_positional_boolean_parameters # not yet tested
76
- # - avoid_print # not yet tested
59
+ # - avoid_positional_boolean_parameters # would have been nice to enable this but by now there's too many places that break it
60
+ - avoid_print
77
61
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
78
- # - avoid_redundant_argument_values # not yet tested
62
+ - avoid_redundant_argument_values
79
63
- avoid_relative_lib_imports
80
64
- avoid_renaming_method_parameters
81
65
- avoid_return_types_on_setters
82
- # - avoid_returning_null # there are plenty of valid reasons to return null
83
- # - avoid_returning_null_for_future # not yet tested
66
+ # - avoid_returning_null # still violated by some pre-nnbd code that we haven't yet migrated
67
+ - avoid_returning_null_for_future
84
68
- avoid_returning_null_for_void
85
- # - avoid_returning_this # there are plenty of valid reasons to return this
86
- # - avoid_setters_without_getters # not yet tested
69
+ # - avoid_returning_this # there are enough valid reasons to return ` this` that this lint ends up with too many false positives
70
+ - avoid_setters_without_getters
87
71
- avoid_shadowing_type_parameters
88
72
- avoid_single_cascade_in_expression_statements
89
73
- avoid_slow_async_io
90
- # - avoid_type_to_string # we do this commonly
74
+ - avoid_type_to_string
91
75
- avoid_types_as_parameter_names
92
76
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
93
- # - avoid_unnecessary_containers # not yet tested
77
+ - avoid_unnecessary_containers
94
78
- avoid_unused_constructor_parameters
95
79
- avoid_void_async
96
- # - avoid_web_libraries_in_flutter # not yet tested
80
+ # - avoid_web_libraries_in_flutter # we use web libraries in web-specific code, and our tests prevent us from using them elsewhere
97
81
- await_only_futures
98
82
- camel_case_extensions
99
83
- camel_case_types
100
84
- cancel_subscriptions
101
- # - cascade_invocations # not yet tested
85
+ # - cascade_invocations # doesn't match the typical style of this repo
102
86
- cast_nullable_to_non_nullable
103
87
# - close_sinks # not reliable enough
104
- # - comment_references # blocked on https://github.com/flutter/flutter/issues/20765
88
+ # - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142
89
+ # - conditional_uri_does_not_exist # not yet tested
105
90
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
106
91
- control_flow_in_finally
107
92
# - curly_braces_in_flow_control_structures # not required by flutter style
108
- # - diagnostic_describe_all_properties # not yet tested
93
+ - depend_on_referenced_packages
94
+ - deprecated_consistency
95
+ # - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib)
109
96
- directives_ordering
110
- # - do_not_use_environment # we do this commonly
97
+ # - do_not_use_environment # there are appropriate times to use the environment, especially in our tests and build logic
111
98
- empty_catches
112
99
- empty_constructor_bodies
113
100
- empty_statements
101
+ - eol_at_end_of_file
114
102
- exhaustive_cases
115
- # - file_names # not yet tested
103
+ - file_names
116
104
- flutter_style_todos
117
105
- hash_and_equals
118
106
- implementation_imports
@@ -122,24 +110,28 @@ linter:
122
110
- leading_newlines_in_multiline_strings
123
111
- library_names
124
112
- library_prefixes
113
+ - library_private_types_in_public_api
125
114
# - lines_longer_than_80_chars # not required by flutter style
126
115
- list_remove_unrelated_type
127
- # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk /issues/34181
128
- # - missing_whitespace_between_adjacent_strings # not yet tested
116
+ # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/linter /issues/453
117
+ - missing_whitespace_between_adjacent_strings
129
118
- no_adjacent_strings_in_list
130
- # - no_default_cases # too many false positives
119
+ - no_default_cases
131
120
- no_duplicate_case_values
121
+ - no_leading_underscores_for_library_prefixes
122
+ - no_leading_underscores_for_local_identifiers
132
123
- no_logic_in_create_state
133
124
# - no_runtimeType_toString # ok in tests; we enable this only in packages/
134
125
- non_constant_identifier_names
126
+ - noop_primitive_operations
135
127
- null_check_on_nullable_type_parameter
136
- # - null_closures # not required by flutter style
128
+ - null_closures
137
129
# - omit_local_variable_types # opposite of always_specify_types
138
130
# - one_member_abstracts # too many false positives
139
131
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
140
132
- overridden_fields
141
133
- package_api_docs
142
- # - package_names # non conforming packages in sdk
134
+ - package_names
143
135
- package_prefixed_library_names
144
136
# - parameter_assignments # we do this commonly
145
137
- prefer_adjacent_string_concatenation
@@ -159,33 +151,38 @@ linter:
159
151
- prefer_final_fields
160
152
- prefer_final_in_for_each
161
153
- prefer_final_locals
154
+ # - 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
162
155
- prefer_for_elements_to_map_fromIterable
163
156
- prefer_foreach
164
- # - prefer_function_declarations_over_variables # not yet tested
157
+ - prefer_function_declarations_over_variables
165
158
- prefer_generic_function_type_aliases
166
159
- prefer_if_elements_to_conditional_expressions
167
160
- prefer_if_null_operators
168
161
- prefer_initializing_formals
169
162
- prefer_inlined_adds
170
- # - prefer_int_literals # not yet tested
171
- # - prefer_interpolation_to_compose_strings # not yet tested
163
+ # - prefer_int_literals # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-double-literals-for-double-constants
164
+ - prefer_interpolation_to_compose_strings
172
165
- prefer_is_empty
173
166
- prefer_is_not_empty
174
167
- prefer_is_not_operator
175
168
- prefer_iterable_whereType
176
- # - prefer_mixin # https://github.com/dart-lang/language/issues/32
177
- # - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932
178
- # - prefer_relative_imports # not yet tested
169
+ # - prefer_mixin # Has false positives, see https://github.com/dart-lang/linter/issues/3018
170
+ # - prefer_null_aware_method_calls # "call()" is confusing to people new to the language since it's not documented anywhere
171
+ - prefer_null_aware_operators
172
+ - prefer_relative_imports
179
173
- prefer_single_quotes
180
174
- prefer_spread_collections
181
175
- prefer_typing_uninitialized_variables
182
176
- prefer_void_to_null
183
- # - provide_deprecation_message # not yet tested
177
+ - provide_deprecation_message
184
178
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
185
179
- recursive_getters
186
- # - sized_box_for_whitespace # not yet tested
180
+ # - require_trailing_commas # blocked on https://github.com/dart-lang/sdk/issues/47441
181
+ - secure_pubspec_urls
182
+ - sized_box_for_whitespace
183
+ # - sized_box_shrink_expand # not yet tested
187
184
- slash_for_doc_comments
188
- # - sort_child_properties_last # not yet tested
185
+ - sort_child_properties_last
189
186
- sort_constructors_first
190
187
# - sort_pub_dependencies # prevents separating pinned transitive dependencies
191
188
- sort_unnamed_constructors_first
@@ -194,36 +191,46 @@ linter:
194
191
- tighten_type_of_initializing_formals
195
192
# - type_annotate_public_apis # subset of always_specify_types
196
193
- type_init_formals
197
- # - unawaited_futures # too many false positives
198
- # - unnecessary_await_in_return # not yet tested
194
+ # - unawaited_futures # too many false positives, especially with the way AnimationController works
195
+ - unnecessary_await_in_return
199
196
- unnecessary_brace_in_string_interps
200
197
- unnecessary_const
198
+ - unnecessary_constructor_name
201
199
# - unnecessary_final # conflicts with prefer_final_locals
202
200
- unnecessary_getters_setters
203
201
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
202
+ - unnecessary_late
204
203
- unnecessary_new
205
204
- unnecessary_null_aware_assignments
206
- # - unnecessary_null_checks # not yet tested
205
+ - unnecessary_null_checks
207
206
- unnecessary_null_in_if_null_operators
208
207
- unnecessary_nullable_for_final_variable_declarations
209
208
- unnecessary_overrides
210
209
- unnecessary_parenthesis
211
- # - unnecessary_raw_strings # not yet tested
210
+ # - unnecessary_raw_strings # what's "necessary" is a matter of opinion; consistency across strings can help readability more than this lint
212
211
- unnecessary_statements
213
212
- unnecessary_string_escapes
214
213
- unnecessary_string_interpolations
215
214
- unnecessary_this
216
215
- unrelated_type_equality_checks
217
- # - unsafe_html # not yet tested
216
+ - unsafe_html
217
+ # - use_build_context_synchronously
218
+ # - use_colored_box # not yet tested
219
+ # - use_decorated_box # not yet tested
220
+ # - use_enums # not yet tested
218
221
- use_full_hex_values_for_flutter_colors
219
- # - use_function_type_syntax_for_parameters # not yet tested
222
+ - use_function_type_syntax_for_parameters
223
+ - use_if_null_to_convert_nulls_to_bools
220
224
- use_is_even_rather_than_modulo
221
- # - use_key_in_widget_constructors # not yet tested
225
+ - use_key_in_widget_constructors
222
226
- use_late_for_private_fields_and_variables
227
+ - use_named_constants
223
228
- use_raw_strings
224
229
- use_rethrow_when_possible
225
- # - use_setters_to_change_properties # not yet tested
230
+ - use_setters_to_change_properties
226
231
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
232
+ - use_super_parameters
233
+ - use_test_throws_matchers
227
234
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
228
235
- valid_regexps
229
- - void_checks
236
+ - void_checks
0 commit comments