analysis_options.yaml 11.5 KB
Newer Older
1 2 3 4 5 6 7
# Specify analysis options.
#
# Until there are meta linter rules, each desired lint must be explicitly enabled.
# See: https://github.com/dart-lang/linter/issues/288
#
# For a list of lints, see: http://dart-lang.github.io/linter/lints/
# See the configuration guide for more
8
# https://github.com/dart-lang/sdk/tree/main/pkg/analyzer#configuring-the-analyzer
9 10 11 12 13 14 15
#
# There are other similar analysis options files in the flutter repos,
# which should be kept in sync with this file:
#
#   - analysis_options.yaml (this file)
#   - https://github.com/flutter/plugins/blob/master/analysis_options.yaml
#   - https://github.com/flutter/engine/blob/master/analysis_options.yaml
16
#   - https://github.com/flutter/packages/blob/master/analysis_options.yaml
17 18 19
#
# This file contains the analysis options used by Flutter tools, such as IntelliJ,
# Android Studio, and the `flutter analyze` command.
20 21

analyzer:
22 23
  language:
    strict-raw-types: true
24
  strong-mode:
25
    implicit-casts: false
26
  errors:
27 28 29 30
    # treat missing required parameters as a warning (not a hint)
    missing_required_param: warning
    # treat missing returns as a warning (not a hint)
    missing_return: warning
31
    # allow having TODO comments in the code
32
    todo: ignore
33 34 35
    # allow self-reference to deprecated members (we do this because otherwise we have
    # to annotate every member in every test, assert, etc, when we deprecate something)
    deprecated_member_use_from_same_package: ignore
36
    # TODO(ianh): https://github.com/flutter/flutter/issues/74381
37 38
    # Clean up existing unnecessary imports, and remove line to ignore.
    unnecessary_import: ignore
39 40
    # Turned off until null-safe rollout is complete.
    unnecessary_null_comparison: ignore
41
  exclude:
42
    - "bin/cache/**"
43
      # Ignore protoc generated files
44
    - "dev/conductor/lib/proto/*"
45 46 47 48 49 50 51 52 53 54 55

linter:
  rules:
    # these rules are documented on and in the same order as
    # the Dart Lint rules page to make maintenance easier
    # https://github.com/dart-lang/linter/blob/master/example/all.yaml
    - always_declare_return_types
    - always_put_control_body_on_new_line
    # - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
    - always_require_non_null_named_parameters
    - always_specify_types
56
    # - always_use_package_imports # we do this commonly
57 58
    - annotate_overrides
    # - avoid_annotating_with_dynamic # conflicts with always_specify_types
59
    - avoid_bool_literals_in_conditional_expressions
60 61
    # - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023
    # - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/3023
62
    - avoid_classes_with_only_static_members
63
    - avoid_double_and_int_checks
64
    - avoid_dynamic_calls
65
    - avoid_empty_else
66
    - avoid_equals_and_hash_code_on_mutable_classes
67
    - avoid_escaping_inner_quotes
68
    - avoid_field_initializers_in_const_classes
69
    # - avoid_final_parameters # incompatible with prefer_final_parameters
70
    - avoid_function_literals_in_foreach_calls
71
    - avoid_implementing_value_types
72
    - avoid_init_to_null
73
    - avoid_js_rounded_ints
74
    # - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to
75
    - avoid_null_checks_in_equality_operators
76 77
    # - avoid_positional_boolean_parameters # would have been nice to enable this but by now there's too many places that break it
    - avoid_print
78
    # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
79
    - avoid_redundant_argument_values
80 81 82
    - avoid_relative_lib_imports
    - avoid_renaming_method_parameters
    - avoid_return_types_on_setters
83 84
    # - avoid_returning_null # still violated by some pre-nnbd code that we haven't yet migrated
    - avoid_returning_null_for_future
85
    - avoid_returning_null_for_void
86
    # - avoid_returning_this # there are enough valid reasons to return `this` that this lint ends up with too many false positives
87
    - avoid_setters_without_getters
Ian Hickson's avatar
Ian Hickson committed
88
    - avoid_shadowing_type_parameters
89
    - avoid_single_cascade_in_expression_statements
90
    - avoid_slow_async_io
91
    - avoid_type_to_string
92 93
    - avoid_types_as_parameter_names
    # - avoid_types_on_closure_parameters # conflicts with always_specify_types
94
    - avoid_unnecessary_containers
95 96
    - avoid_unused_constructor_parameters
    - avoid_void_async
97
    # - avoid_web_libraries_in_flutter # we use web libraries in web-specific code, and our tests prevent us from using them elsewhere
98
    - await_only_futures
99
    - camel_case_extensions
100 101
    - camel_case_types
    - cancel_subscriptions
102
    # - cascade_invocations # doesn't match the typical style of this repo
103
    - cast_nullable_to_non_nullable
104
    # - close_sinks # not reliable enough
105
    # - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142
106
    # - conditional_uri_does_not_exist # not yet tested
107 108
    # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
    - control_flow_in_finally
Ian Hickson's avatar
Ian Hickson committed
109
    # - curly_braces_in_flow_control_structures # not required by flutter style
110
    - depend_on_referenced_packages
111
    - deprecated_consistency
112
    # - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib)
113
    - directives_ordering
114
    # - do_not_use_environment # there are appropriate times to use the environment, especially in our tests and build logic
115 116 117
    - empty_catches
    - empty_constructor_bodies
    - empty_statements
118
    - eol_at_end_of_file
119
    - exhaustive_cases
120
    - file_names
121 122 123 124 125
    - flutter_style_todos
    - hash_and_equals
    - implementation_imports
    # - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
    - iterable_contains_unrelated_type
Ian Hickson's avatar
Ian Hickson committed
126
    # - join_return_with_assignment # not required by flutter style
127
    - leading_newlines_in_multiline_strings
128 129
    - library_names
    - library_prefixes
130
    - library_private_types_in_public_api
Ian Hickson's avatar
Ian Hickson committed
131
    # - lines_longer_than_80_chars # not required by flutter style
132
    - list_remove_unrelated_type
133
    # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/linter/issues/453
134
    - missing_whitespace_between_adjacent_strings
135
    - no_adjacent_strings_in_list
136
    - no_default_cases
137
    - no_duplicate_case_values
138
    - no_leading_underscores_for_library_prefixes
139
    - no_leading_underscores_for_local_identifiers
Ian Hickson's avatar
Ian Hickson committed
140 141
    - no_logic_in_create_state
    # - no_runtimeType_toString # ok in tests; we enable this only in packages/
142
    - non_constant_identifier_names
143
    - noop_primitive_operations
144
    - null_check_on_nullable_type_parameter
145
    - null_closures
146 147
    # - omit_local_variable_types # opposite of always_specify_types
    # - one_member_abstracts # too many false positives
148
    - only_throw_errors # this does get disabled in a few places where we have legacy code that uses strings et al
149 150
    - overridden_fields
    - package_api_docs
151
    - package_names
152 153 154 155
    - package_prefixed_library_names
    # - parameter_assignments # we do this commonly
    - prefer_adjacent_string_concatenation
    - prefer_asserts_in_initializer_lists
Ian Hickson's avatar
Ian Hickson committed
156
    # - prefer_asserts_with_message # not required by flutter style
157
    - prefer_collection_literals
158
    - prefer_conditional_assignment
Dan Field's avatar
Dan Field committed
159
    - prefer_const_constructors
160 161 162
    - prefer_const_constructors_in_immutables
    - prefer_const_declarations
    - prefer_const_literals_to_create_immutables
Ian Hickson's avatar
Ian Hickson committed
163
    # - prefer_constructors_over_static_methods # far too many false positives
164
    - prefer_contains
165
    # - prefer_double_quotes # opposite of prefer_single_quotes
166 167 168
    - prefer_equal_for_default_values
    # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
    - prefer_final_fields
169
    - prefer_final_in_for_each
170
    - prefer_final_locals
171
    # - 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
172
    - prefer_for_elements_to_map_fromIterable
173
    - prefer_foreach
174
    - prefer_function_declarations_over_variables
175
    - prefer_generic_function_type_aliases
176
    - prefer_if_elements_to_conditional_expressions
177
    - prefer_if_null_operators
178
    - prefer_initializing_formals
179
    - prefer_inlined_adds
180
    # - prefer_int_literals # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-double-literals-for-double-constants
181
    - prefer_interpolation_to_compose_strings
182
    - prefer_is_empty
183
    - prefer_is_not_empty
184
    - prefer_is_not_operator
185
    - prefer_iterable_whereType
186
    # - prefer_mixin # Has false positives, see https://github.com/dart-lang/linter/issues/3018
187
    # - prefer_null_aware_method_calls # "call()" is confusing to people new to the language since it's not documented anywhere
188
    - prefer_null_aware_operators
189
    - prefer_relative_imports
190
    - prefer_single_quotes
191
    - prefer_spread_collections
192 193
    - prefer_typing_uninitialized_variables
    - prefer_void_to_null
194
    - provide_deprecation_message
195 196
    # - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
    - recursive_getters
197
    # - require_trailing_commas # blocked on https://github.com/dart-lang/sdk/issues/47441
198
    - secure_pubspec_urls
199
    - sized_box_for_whitespace
200
    # - sized_box_shrink_expand # not yet tested
201
    - slash_for_doc_comments
202
    - sort_child_properties_last
203
    - sort_constructors_first
204
    # - sort_pub_dependencies # prevents separating pinned transitive dependencies
205 206 207
    - sort_unnamed_constructors_first
    - test_types_in_equals
    - throw_in_finally
208
    - tighten_type_of_initializing_formals
209 210
    # - type_annotate_public_apis # subset of always_specify_types
    - type_init_formals
211
    # - unawaited_futures # too many false positives, especially with the way AnimationController works
212
    - unnecessary_await_in_return
213 214
    - unnecessary_brace_in_string_interps
    - unnecessary_const
215
    - unnecessary_constructor_name
216
    # - unnecessary_final # conflicts with prefer_final_locals
217 218
    - unnecessary_getters_setters
    # - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
219
    - unnecessary_late
220 221
    - unnecessary_new
    - unnecessary_null_aware_assignments
222
    - unnecessary_null_checks
223
    - unnecessary_null_in_if_null_operators
224
    - unnecessary_nullable_for_final_variable_declarations
225 226
    - unnecessary_overrides
    - unnecessary_parenthesis
227
    # - unnecessary_raw_strings # what's "necessary" is a matter of opinion; consistency across strings can help readability more than this lint
228
    - unnecessary_statements
229
    - unnecessary_string_escapes
230
    - unnecessary_string_interpolations
231 232
    - unnecessary_this
    - unrelated_type_equality_checks
233
    - unsafe_html
234
    - use_build_context_synchronously
235
    # - use_decorated_box # not yet tested
236
    - use_full_hex_values_for_flutter_colors
237
    - use_function_type_syntax_for_parameters
238
    # - use_if_null_to_convert_nulls_to_bools # blocked on https://github.com/dart-lang/sdk/issues/47436
239
    - use_is_even_rather_than_modulo
240
    - use_key_in_widget_constructors
241
    - use_late_for_private_fields_and_variables
242
    - use_named_constants
243
    - use_raw_strings
244
    - use_rethrow_when_possible
245
    - use_setters_to_change_properties
246
    # - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
247
    - use_test_throws_matchers
248 249
    # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
    - valid_regexps
250
    - void_checks