blob: a733a58a24eb40d0d8488e7f6dbcd5b70b1296e1 [file] [log] [blame]
Dan Field8af3e482019-01-11 13:38:02 -08001# Specify analysis options.
2#
Dan Field8af3e482019-01-11 13:38:02 -08003# For a list of lints, see: http://dart-lang.github.io/linter/lints/
4# See the configuration guide for more
Phil Quitslund975fcc12021-09-10 15:42:03 -07005# https://github.com/dart-lang/sdk/tree/main/pkg/analyzer#configuring-the-analyzer
Dan Field8af3e482019-01-11 13:38:02 -08006#
7# There are other similar analysis options files in the flutter repos,
8# which should be kept in sync with this file:
9#
10# - analysis_options.yaml (this file)
Dan Field8af3e482019-01-11 13:38:02 -080011# - https://github.com/flutter/plugins/blob/master/analysis_options.yaml
12# - https://github.com/flutter/engine/blob/master/analysis_options.yaml
Michael Goderbauer2bf42e72021-05-10 23:44:02 -070013# - https://github.com/flutter/packages/blob/master/analysis_options.yaml
Dan Field8af3e482019-01-11 13:38:02 -080014#
Michael Goderbauercae740b2022-04-08 11:15:34 -070015# This file contains the analysis options used for code in the flutter/flutter
16# repository.
krisgiesing07b5f832016-05-04 10:15:15 -070017
18analyzer:
Sam Rawlins2cdef812022-01-20 15:45:09 -080019 language:
Michael Goderbauercae740b2022-04-08 11:15:34 -070020 strict-casts: true
Sam Rawlins2cdef812022-01-20 15:45:09 -080021 strict-raw-types: true
krisgiesing07b5f832016-05-04 10:15:15 -070022 errors:
Dan Field8af3e482019-01-11 13:38:02 -080023 # treat missing required parameters as a warning (not a hint)
24 missing_required_param: warning
25 # treat missing returns as a warning (not a hint)
26 missing_return: warning
Ian Hicksonb3f63d32021-10-09 04:03:03 -070027 # allow having TODO comments in the code
Dan Field8af3e482019-01-11 13:38:02 -080028 todo: ignore
Christopher Fujino5cfb16b2020-06-19 12:03:38 -070029 # allow self-reference to deprecated members (we do this because otherwise we have
30 # to annotate every member in every test, assert, etc, when we deprecate something)
31 deprecated_member_use_from_same_package: ignore
Michael Goderbauer0f91f0d2021-03-02 21:14:03 -080032 # Turned off until null-safe rollout is complete.
33 unnecessary_null_comparison: ignore
Devon Carew207451f2016-08-18 19:11:39 -070034 exclude:
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +020035 - "bin/cache/**"
Christopher Fujino4a7f2802021-04-19 15:04:04 -070036 # Ignore protoc generated files
Christopher Fujino62d00c62021-05-25 16:12:53 -070037 - "dev/conductor/lib/proto/*"
Dan Field8af3e482019-01-11 13:38:02 -080038
39linter:
40 rules:
Michael Goderbauercae740b2022-04-08 11:15:34 -070041 # This list is derived from the list of all available lints located at
Dan Field8af3e482019-01-11 13:38:02 -080042 # https://github.com/dart-lang/linter/blob/master/example/all.yaml
43 - always_declare_return_types
44 - always_put_control_body_on_new_line
45 # - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
46 - always_require_non_null_named_parameters
47 - always_specify_types
Alexandre Ardhuin73301a32020-10-16 00:37:04 +020048 # - always_use_package_imports # we do this commonly
Dan Field8af3e482019-01-11 13:38:02 -080049 - annotate_overrides
50 # - avoid_annotating_with_dynamic # conflicts with always_specify_types
Alexandre Ardhuinfecf99f2019-06-25 17:40:05 +020051 - avoid_bool_literals_in_conditional_expressions
Ian Hickson299d4842021-10-14 22:03:03 -070052 # - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023
53 # - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/3023
Dan Field8af3e482019-01-11 13:38:02 -080054 - avoid_classes_with_only_static_members
Ian Hickson299d4842021-10-14 22:03:03 -070055 - avoid_double_and_int_checks
Greg Spencer88f38112021-06-14 14:16:57 -070056 - avoid_dynamic_calls
Dan Field8af3e482019-01-11 13:38:02 -080057 - avoid_empty_else
Alexandre Ardhuinf5a99022020-04-06 22:36:01 +020058 - avoid_equals_and_hash_code_on_mutable_classes
Hattomo (TomohiroHattori)08a70e72021-05-20 01:54:02 +090059 - avoid_escaping_inner_quotes
Dan Field8af3e482019-01-11 13:38:02 -080060 - avoid_field_initializers_in_const_classes
Michael Goderbauer2a529bc2022-01-07 13:50:18 -080061 # - avoid_final_parameters # incompatible with prefer_final_parameters
Dan Field8af3e482019-01-11 13:38:02 -080062 - avoid_function_literals_in_foreach_calls
Ian Hickson2bab6512021-10-04 13:48:04 -070063 - avoid_implementing_value_types
Dan Field8af3e482019-01-11 13:38:02 -080064 - avoid_init_to_null
Ian Hickson299d4842021-10-14 22:03:03 -070065 - avoid_js_rounded_ints
Ian Hicksonbb5cbdc2021-10-12 11:28:02 -070066 # - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to
Dan Field8af3e482019-01-11 13:38:02 -080067 - avoid_null_checks_in_equality_operators
Ian Hicksonf25b8332021-10-07 16:48:04 -070068 # - avoid_positional_boolean_parameters # would have been nice to enable this but by now there's too many places that break it
69 - avoid_print
Dan Field8af3e482019-01-11 13:38:02 -080070 # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
Ian Hickson61a0add2021-10-08 09:25:14 -070071 - avoid_redundant_argument_values
Dan Field8af3e482019-01-11 13:38:02 -080072 - avoid_relative_lib_imports
73 - avoid_renaming_method_parameters
74 - avoid_return_types_on_setters
Ian Hickson989f8642021-10-01 00:58:05 -070075 # - avoid_returning_null # still violated by some pre-nnbd code that we haven't yet migrated
76 - avoid_returning_null_for_future
Dan Field8af3e482019-01-11 13:38:02 -080077 - avoid_returning_null_for_void
Ian Hickson299d4842021-10-14 22:03:03 -070078 # - avoid_returning_this # there are enough valid reasons to return `this` that this lint ends up with too many false positives
Ian Hickson989f8642021-10-01 00:58:05 -070079 - avoid_setters_without_getters
Ian Hickson6cff3382020-11-16 11:07:37 -080080 - avoid_shadowing_type_parameters
Alexandre Ardhuinc2ae6542020-03-05 08:03:26 +010081 - avoid_single_cascade_in_expression_statements
Dan Field8af3e482019-01-11 13:38:02 -080082 - avoid_slow_async_io
Michael Goderbauer3594d1a2021-03-01 15:50:04 -080083 - avoid_type_to_string
Dan Field8af3e482019-01-11 13:38:02 -080084 - avoid_types_as_parameter_names
85 # - avoid_types_on_closure_parameters # conflicts with always_specify_types
Michael Goderbauered755fb2021-03-04 15:29:03 -080086 - avoid_unnecessary_containers
Dan Field8af3e482019-01-11 13:38:02 -080087 - avoid_unused_constructor_parameters
88 - avoid_void_async
Ian Hicksonb3f63d32021-10-09 04:03:03 -070089 # - avoid_web_libraries_in_flutter # we use web libraries in web-specific code, and our tests prevent us from using them elsewhere
Dan Field8af3e482019-01-11 13:38:02 -080090 - await_only_futures
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +010091 - camel_case_extensions
Dan Field8af3e482019-01-11 13:38:02 -080092 - camel_case_types
93 - cancel_subscriptions
Ian Hicksonb3f63d32021-10-09 04:03:03 -070094 # - cascade_invocations # doesn't match the typical style of this repo
Alexandre Ardhuin4acc7902020-10-08 21:05:43 +020095 - cast_nullable_to_non_nullable
Dan Field8af3e482019-01-11 13:38:02 -080096 # - close_sinks # not reliable enough
Alexandre Ardhuinccd33632022-07-19 00:04:07 +020097 - combinators_ordering
Michael Goderbauer1512af72021-03-02 08:34:03 -080098 # - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142
Michael Goderbauer2a529bc2022-01-07 13:50:18 -080099 # - conditional_uri_does_not_exist # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -0800100 # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
101 - control_flow_in_finally
Michael Goderbauer10a7c9b2022-07-28 09:07:49 -0700102 - curly_braces_in_flow_control_structures
Ian Hicksonbb5cbdc2021-10-12 11:28:02 -0700103 - depend_on_referenced_packages
Kate Lovettfd890292021-03-08 14:49:03 -0600104 - deprecated_consistency
Ian Hicksonb3f63d32021-10-09 04:03:03 -0700105 # - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib)
Phil Quitslund44157cf2021-04-30 17:29:04 -0700106 - directives_ordering
Alexandre Ardhuinccd33632022-07-19 00:04:07 +0200107 # - discarded_futures # not yet tested
Ian Hicksonb3f63d32021-10-09 04:03:03 -0700108 # - do_not_use_environment # there are appropriate times to use the environment, especially in our tests and build logic
Dan Field8af3e482019-01-11 13:38:02 -0800109 - empty_catches
110 - empty_constructor_bodies
111 - empty_statements
Ian Hickson66dd2ad2021-10-12 11:33:04 -0700112 - eol_at_end_of_file
Alexandre Ardhuin73301a32020-10-16 00:37:04 +0200113 - exhaustive_cases
Michael Goderbauer7e017d32021-03-02 15:24:04 -0800114 - file_names
Dan Field8af3e482019-01-11 13:38:02 -0800115 - flutter_style_todos
116 - hash_and_equals
117 - implementation_imports
Dan Field8af3e482019-01-11 13:38:02 -0800118 - iterable_contains_unrelated_type
Ian Hickson6cff3382020-11-16 11:07:37 -0800119 # - join_return_with_assignment # not required by flutter style
Alexandre Ardhuin73301a32020-10-16 00:37:04 +0200120 - leading_newlines_in_multiline_strings
Dan Field8af3e482019-01-11 13:38:02 -0800121 - library_names
122 - library_prefixes
Michael Goderbauerb8a24562021-05-10 16:26:16 -0700123 - library_private_types_in_public_api
Ian Hickson6cff3382020-11-16 11:07:37 -0800124 # - lines_longer_than_80_chars # not required by flutter style
Dan Field8af3e482019-01-11 13:38:02 -0800125 - list_remove_unrelated_type
Ian Hicksonb3f63d32021-10-09 04:03:03 -0700126 # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/linter/issues/453
Michael Goderbauerfc99e7c2021-03-01 18:30:17 -0800127 - missing_whitespace_between_adjacent_strings
Dan Field8af3e482019-01-11 13:38:02 -0800128 - no_adjacent_strings_in_list
Ian Hickson7b013462021-10-11 10:23:04 -0700129 - no_default_cases
Dan Field8af3e482019-01-11 13:38:02 -0800130 - no_duplicate_case_values
Michael Goderbauer5ac97142022-01-11 17:35:13 -0800131 - no_leading_underscores_for_library_prefixes
Michael Goderbauer5684b9f2022-01-21 14:43:59 -0800132 - no_leading_underscores_for_local_identifiers
Ian Hickson6cff3382020-11-16 11:07:37 -0800133 - no_logic_in_create_state
134 # - no_runtimeType_toString # ok in tests; we enable this only in packages/
Dan Field8af3e482019-01-11 13:38:02 -0800135 - non_constant_identifier_names
Ian Hicksonbb5cbdc2021-10-12 11:28:02 -0700136 - noop_primitive_operations
Alexandre Ardhuind2858f02020-10-08 09:39:13 +0200137 - null_check_on_nullable_type_parameter
Michael Goderbauerea8e6162021-03-02 15:25:31 -0800138 - null_closures
Dan Field8af3e482019-01-11 13:38:02 -0800139 # - omit_local_variable_types # opposite of always_specify_types
140 # - one_member_abstracts # too many false positives
Ian Hickson94216272021-10-11 14:13:03 -0700141 - only_throw_errors # this does get disabled in a few places where we have legacy code that uses strings et al
Dan Field8af3e482019-01-11 13:38:02 -0800142 - overridden_fields
143 - package_api_docs
Michael Goderbauer7e017d32021-03-02 15:24:04 -0800144 - package_names
Dan Field8af3e482019-01-11 13:38:02 -0800145 - package_prefixed_library_names
146 # - parameter_assignments # we do this commonly
147 - prefer_adjacent_string_concatenation
148 - prefer_asserts_in_initializer_lists
Ian Hickson6cff3382020-11-16 11:07:37 -0800149 # - prefer_asserts_with_message # not required by flutter style
Phil Quitslund802eca22019-03-06 11:05:16 -0800150 - prefer_collection_literals
Dan Field8af3e482019-01-11 13:38:02 -0800151 - prefer_conditional_assignment
Dan Fieldfe9512f2019-04-29 16:02:42 -0700152 - prefer_const_constructors
Dan Field8af3e482019-01-11 13:38:02 -0800153 - prefer_const_constructors_in_immutables
154 - prefer_const_declarations
155 - prefer_const_literals_to_create_immutables
Ian Hickson6cff3382020-11-16 11:07:37 -0800156 # - prefer_constructors_over_static_methods # far too many false positives
Dan Field8af3e482019-01-11 13:38:02 -0800157 - prefer_contains
Alexandre Ardhuin9a3a7492019-06-25 15:59:15 +0200158 # - prefer_double_quotes # opposite of prefer_single_quotes
Dan Field8af3e482019-01-11 13:38:02 -0800159 - prefer_equal_for_default_values
160 # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
161 - prefer_final_fields
Alexandre Ardhuin4f9b6cf2020-01-07 16:32:04 +0100162 - prefer_final_in_for_each
Dan Field8af3e482019-01-11 13:38:02 -0800163 - prefer_final_locals
Michael Goderbauerbabfcb92021-12-13 14:44:10 -0800164 # - 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
Alexandre Ardhuina5419342020-01-08 17:03:02 +0100165 - prefer_for_elements_to_map_fromIterable
Dan Field8af3e482019-01-11 13:38:02 -0800166 - prefer_foreach
Michael Goderbauer807bb292021-03-05 18:29:04 -0800167 - prefer_function_declarations_over_variables
Dan Field8af3e482019-01-11 13:38:02 -0800168 - prefer_generic_function_type_aliases
Alexandre Ardhuindf4bf452019-09-17 16:23:44 +0200169 - prefer_if_elements_to_conditional_expressions
Alexandre Ardhuinb041a582019-07-09 10:53:35 +0200170 - prefer_if_null_operators
Dan Field8af3e482019-01-11 13:38:02 -0800171 - prefer_initializing_formals
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +0200172 - prefer_inlined_adds
Michael Goderbauer0f568292021-03-02 10:14:02 -0800173 # - prefer_int_literals # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-double-literals-for-double-constants
Alexandre Ardhuin34059ee2021-06-01 20:14:06 +0200174 - prefer_interpolation_to_compose_strings
Dan Field8af3e482019-01-11 13:38:02 -0800175 - prefer_is_empty
Alexandre Ardhuinc0125cb2019-05-20 17:00:45 +0200176 - prefer_is_not_empty
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +0100177 - prefer_is_not_operator
Dan Field8af3e482019-01-11 13:38:02 -0800178 - prefer_iterable_whereType
Ian Hicksonf90b0192021-10-11 10:28:07 -0700179 # - prefer_mixin # Has false positives, see https://github.com/dart-lang/linter/issues/3018
Ian Hickson66dd2ad2021-10-12 11:33:04 -0700180 # - prefer_null_aware_method_calls # "call()" is confusing to people new to the language since it's not documented anywhere
Michael Goderbauer2a529bc2022-01-07 13:50:18 -0800181 - prefer_null_aware_operators
Ian Hicksonf90b0192021-10-11 10:28:07 -0700182 - prefer_relative_imports
Dan Field8af3e482019-01-11 13:38:02 -0800183 - prefer_single_quotes
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +0200184 - prefer_spread_collections
Dan Field8af3e482019-01-11 13:38:02 -0800185 - prefer_typing_uninitialized_variables
186 - prefer_void_to_null
Michael Goderbauerd3209372021-03-02 16:34:05 -0800187 - provide_deprecation_message
Dan Field8af3e482019-01-11 13:38:02 -0800188 # - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
189 - recursive_getters
Ian Hickson66dd2ad2021-10-12 11:33:04 -0700190 # - require_trailing_commas # blocked on https://github.com/dart-lang/sdk/issues/47441
Michael Goderbauer2a529bc2022-01-07 13:50:18 -0800191 - secure_pubspec_urls
Greg Spencerc6ef4c72021-03-04 01:29:02 +0000192 - sized_box_for_whitespace
Michael Goderbauer2a529bc2022-01-07 13:50:18 -0800193 # - sized_box_shrink_expand # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -0800194 - slash_for_doc_comments
Ian Hickson6d5fc422021-10-11 21:23:02 -0700195 - sort_child_properties_last
Dan Field8af3e482019-01-11 13:38:02 -0800196 - sort_constructors_first
Phil Quitslund1fef5912020-09-23 21:37:08 -0700197 # - sort_pub_dependencies # prevents separating pinned transitive dependencies
Dan Field8af3e482019-01-11 13:38:02 -0800198 - sort_unnamed_constructors_first
Dan Field8af3e482019-01-11 13:38:02 -0800199 - test_types_in_equals
200 - throw_in_finally
Alexandre Ardhuind2858f02020-10-08 09:39:13 +0200201 - tighten_type_of_initializing_formals
Dan Field8af3e482019-01-11 13:38:02 -0800202 # - type_annotate_public_apis # subset of always_specify_types
203 - type_init_formals
Ian Hickson299d4842021-10-14 22:03:03 -0700204 # - unawaited_futures # too many false positives, especially with the way AnimationController works
Michael Goderbauercb867bb2021-03-05 18:38:15 -0800205 - unnecessary_await_in_return
Dan Field8af3e482019-01-11 13:38:02 -0800206 - unnecessary_brace_in_string_interps
207 - unnecessary_const
Ian Hickson66dd2ad2021-10-12 11:33:04 -0700208 - unnecessary_constructor_name
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +0100209 # - unnecessary_final # conflicts with prefer_final_locals
Dan Field8af3e482019-01-11 13:38:02 -0800210 - unnecessary_getters_setters
211 # - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
Michael Goderbauer40a26892022-01-12 21:10:19 -0800212 - unnecessary_late
Dan Field8af3e482019-01-11 13:38:02 -0800213 - unnecessary_new
214 - unnecessary_null_aware_assignments
Alexandre Ardhuinccd33632022-07-19 00:04:07 +0200215 - unnecessary_null_aware_operator_on_extension_on_nullable
Abhishek Ghaskatab554f892021-05-14 23:14:03 +0530216 - unnecessary_null_checks
Dan Field8af3e482019-01-11 13:38:02 -0800217 - unnecessary_null_in_if_null_operators
Alexandre Ardhuin71c1f6c2020-09-23 06:39:47 +0200218 - unnecessary_nullable_for_final_variable_declarations
Dan Field8af3e482019-01-11 13:38:02 -0800219 - unnecessary_overrides
220 - unnecessary_parenthesis
Ian Hickson299d4842021-10-14 22:03:03 -0700221 # - unnecessary_raw_strings # what's "necessary" is a matter of opinion; consistency across strings can help readability more than this lint
Dan Field8af3e482019-01-11 13:38:02 -0800222 - unnecessary_statements
Alexandre Ardhuin17cdf552020-10-26 20:42:05 +0100223 - unnecessary_string_escapes
Alexandre Ardhuin0bd45bc2020-02-14 09:43:52 +0100224 - unnecessary_string_interpolations
Dan Field8af3e482019-01-11 13:38:02 -0800225 - unnecessary_this
Alexandre Ardhuinccd33632022-07-19 00:04:07 +0200226 - unnecessary_to_list_in_spreads
Dan Field8af3e482019-01-11 13:38:02 -0800227 - unrelated_type_equality_checks
Ian Hickson299d4842021-10-14 22:03:03 -0700228 - unsafe_html
Ian Hickson66dd2ad2021-10-12 11:33:04 -0700229 - use_build_context_synchronously
Michael Goderbauercc4cc692022-04-14 13:26:18 -0700230 # - use_colored_box # not yet tested
Michael Goderbauer2a529bc2022-01-07 13:50:18 -0800231 # - use_decorated_box # not yet tested
Michael Goderbauercc4cc692022-04-14 13:26:18 -0700232 # - use_enums # not yet tested
Alexandre Ardhuinb5ce0612019-06-25 17:58:19 +0200233 - use_full_hex_values_for_flutter_colors
Michael Goderbauer7b251f52021-03-04 08:59:17 -0800234 - use_function_type_syntax_for_parameters
Tomasz Gucioe4351ff2022-02-22 23:39:20 +0100235 - use_if_null_to_convert_nulls_to_bools
Alexandre Ardhuinc0176c92020-10-16 20:20:00 +0200236 - use_is_even_rather_than_modulo
Michael Goderbauer0f568292021-03-02 10:14:02 -0800237 - use_key_in_widget_constructors
Ian Hickson8a6a76a2020-08-27 16:38:10 -0700238 - use_late_for_private_fields_and_variables
Abhishek Ghaskata254c9f12021-05-14 01:59:06 +0530239 - use_named_constants
Alexandre Ardhuin17cdf552020-10-26 20:42:05 +0100240 - use_raw_strings
Dan Field8af3e482019-01-11 13:38:02 -0800241 - use_rethrow_when_possible
Ian Hickson299d4842021-10-14 22:03:03 -0700242 - use_setters_to_change_properties
Dan Field8af3e482019-01-11 13:38:02 -0800243 # - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
Michael Goderbauercc4cc692022-04-14 13:26:18 -0700244 - use_super_parameters
Alexandre Ardhuincfc08592021-06-04 07:14:03 +0200245 - use_test_throws_matchers
Dan Field8af3e482019-01-11 13:38:02 -0800246 # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
247 - valid_regexps
Ian Hicksone2b169e2020-01-13 10:03:01 -0800248 - void_checks