blob: c88c8521dac240a9749e0e136c98a063b7acdd93 [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:
Christopher Fujino5cfb16b2020-06-19 12:03:38 -070023 # allow self-reference to deprecated members (we do this because otherwise we have
24 # to annotate every member in every test, assert, etc, when we deprecate something)
25 deprecated_member_use_from_same_package: ignore
Michael Goderbauer0f91f0d2021-03-02 21:14:03 -080026 # Turned off until null-safe rollout is complete.
27 unnecessary_null_comparison: ignore
Devon Carew207451f2016-08-18 19:11:39 -070028 exclude:
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +020029 - "bin/cache/**"
Christopher Fujino4a7f2802021-04-19 15:04:04 -070030 # Ignore protoc generated files
Christopher Fujino62d00c62021-05-25 16:12:53 -070031 - "dev/conductor/lib/proto/*"
Dan Field8af3e482019-01-11 13:38:02 -080032
33linter:
34 rules:
Michael Goderbauercae740b2022-04-08 11:15:34 -070035 # This list is derived from the list of all available lints located at
Dan Field8af3e482019-01-11 13:38:02 -080036 # https://github.com/dart-lang/linter/blob/master/example/all.yaml
37 - always_declare_return_types
38 - always_put_control_body_on_new_line
39 # - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
40 - always_require_non_null_named_parameters
41 - always_specify_types
Alexandre Ardhuin73301a32020-10-16 00:37:04 +020042 # - always_use_package_imports # we do this commonly
Dan Field8af3e482019-01-11 13:38:02 -080043 - annotate_overrides
44 # - avoid_annotating_with_dynamic # conflicts with always_specify_types
Alexandre Ardhuinfecf99f2019-06-25 17:40:05 +020045 - avoid_bool_literals_in_conditional_expressions
Ian Hickson299d4842021-10-14 22:03:03 -070046 # - avoid_catches_without_on_clauses # blocked on https://github.com/dart-lang/linter/issues/3023
47 # - avoid_catching_errors # blocked on https://github.com/dart-lang/linter/issues/3023
Dan Field8af3e482019-01-11 13:38:02 -080048 - avoid_classes_with_only_static_members
Ian Hickson299d4842021-10-14 22:03:03 -070049 - avoid_double_and_int_checks
Greg Spencer88f38112021-06-14 14:16:57 -070050 - avoid_dynamic_calls
Dan Field8af3e482019-01-11 13:38:02 -080051 - avoid_empty_else
Alexandre Ardhuinf5a99022020-04-06 22:36:01 +020052 - avoid_equals_and_hash_code_on_mutable_classes
Hattomo (TomohiroHattori)08a70e72021-05-20 01:54:02 +090053 - avoid_escaping_inner_quotes
Dan Field8af3e482019-01-11 13:38:02 -080054 - avoid_field_initializers_in_const_classes
Michael Goderbauer2a529bc2022-01-07 13:50:18 -080055 # - avoid_final_parameters # incompatible with prefer_final_parameters
Dan Field8af3e482019-01-11 13:38:02 -080056 - avoid_function_literals_in_foreach_calls
Ian Hickson2bab6512021-10-04 13:48:04 -070057 - avoid_implementing_value_types
Dan Field8af3e482019-01-11 13:38:02 -080058 - avoid_init_to_null
Ian Hickson299d4842021-10-14 22:03:03 -070059 - avoid_js_rounded_ints
Ian Hicksonbb5cbdc2021-10-12 11:28:02 -070060 # - avoid_multiple_declarations_per_line # seems to be a stylistic choice we don't subscribe to
Dan Field8af3e482019-01-11 13:38:02 -080061 - avoid_null_checks_in_equality_operators
Ian Hicksonf25b8332021-10-07 16:48:04 -070062 # - avoid_positional_boolean_parameters # would have been nice to enable this but by now there's too many places that break it
63 - avoid_print
Dan Field8af3e482019-01-11 13:38:02 -080064 # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
Ian Hickson61a0add2021-10-08 09:25:14 -070065 - avoid_redundant_argument_values
Dan Field8af3e482019-01-11 13:38:02 -080066 - avoid_relative_lib_imports
67 - avoid_renaming_method_parameters
68 - avoid_return_types_on_setters
Michael Goderbauer3d1f7072022-07-29 16:41:02 -070069 - avoid_returning_null
Ian Hickson989f8642021-10-01 00:58:05 -070070 - avoid_returning_null_for_future
Dan Field8af3e482019-01-11 13:38:02 -080071 - avoid_returning_null_for_void
Ian Hickson299d4842021-10-14 22:03:03 -070072 # - 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 -070073 - avoid_setters_without_getters
Ian Hickson6cff3382020-11-16 11:07:37 -080074 - avoid_shadowing_type_parameters
Alexandre Ardhuinc2ae6542020-03-05 08:03:26 +010075 - avoid_single_cascade_in_expression_statements
Dan Field8af3e482019-01-11 13:38:02 -080076 - avoid_slow_async_io
Michael Goderbauer3594d1a2021-03-01 15:50:04 -080077 - avoid_type_to_string
Dan Field8af3e482019-01-11 13:38:02 -080078 - avoid_types_as_parameter_names
79 # - avoid_types_on_closure_parameters # conflicts with always_specify_types
Michael Goderbauered755fb2021-03-04 15:29:03 -080080 - avoid_unnecessary_containers
Dan Field8af3e482019-01-11 13:38:02 -080081 - avoid_unused_constructor_parameters
82 - avoid_void_async
Ian Hicksonb3f63d32021-10-09 04:03:03 -070083 # - 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 -080084 - await_only_futures
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +010085 - camel_case_extensions
Dan Field8af3e482019-01-11 13:38:02 -080086 - camel_case_types
87 - cancel_subscriptions
Ian Hicksonb3f63d32021-10-09 04:03:03 -070088 # - cascade_invocations # doesn't match the typical style of this repo
Alexandre Ardhuin4acc7902020-10-08 21:05:43 +020089 - cast_nullable_to_non_nullable
Dan Field8af3e482019-01-11 13:38:02 -080090 # - close_sinks # not reliable enough
Michael Goderbauerfdd2d7d2022-12-20 14:15:39 -080091 - collection_methods_unrelated_type
Alexandre Ardhuinccd33632022-07-19 00:04:07 +020092 - combinators_ordering
Michael Goderbauer1512af72021-03-02 08:34:03 -080093 # - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142
Michael Goderbauerc7eb5b92022-08-01 15:59:04 -070094 - conditional_uri_does_not_exist
Dan Field8af3e482019-01-11 13:38:02 -080095 # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
96 - control_flow_in_finally
Michael Goderbauer10a7c9b2022-07-28 09:07:49 -070097 - curly_braces_in_flow_control_structures
Michael Goderbauerb3085552022-12-20 16:03:21 -080098 - dangling_library_doc_comments
Ian Hicksonbb5cbdc2021-10-12 11:28:02 -070099 - depend_on_referenced_packages
Kate Lovettfd890292021-03-08 14:49:03 -0600100 - deprecated_consistency
Ian Hicksonb3f63d32021-10-09 04:03:03 -0700101 # - diagnostic_describe_all_properties # enabled only at the framework level (packages/flutter/lib)
Phil Quitslund44157cf2021-04-30 17:29:04 -0700102 - directives_ordering
Michael Goderbauerfa3777b2022-12-20 11:07:15 -0800103 # - discarded_futures # too many false positives, similar to unawaited_futures
Ian Hicksonb3f63d32021-10-09 04:03:03 -0700104 # - 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 -0800105 - empty_catches
106 - empty_constructor_bodies
107 - empty_statements
Michael Goderbauerfdd2d7d2022-12-20 14:15:39 -0800108 - enable_null_safety
Ian Hickson66dd2ad2021-10-12 11:33:04 -0700109 - eol_at_end_of_file
Alexandre Ardhuin73301a32020-10-16 00:37:04 +0200110 - exhaustive_cases
Michael Goderbauer7e017d32021-03-02 15:24:04 -0800111 - file_names
Dan Field8af3e482019-01-11 13:38:02 -0800112 - flutter_style_todos
113 - hash_and_equals
114 - implementation_imports
Michael Goderbauerfdd2d7d2022-12-20 14:15:39 -0800115 - implicit_call_tearoffs
Dan Field8af3e482019-01-11 13:38:02 -0800116 - iterable_contains_unrelated_type
Ian Hickson6cff3382020-11-16 11:07:37 -0800117 # - join_return_with_assignment # not required by flutter style
Alexandre Ardhuin73301a32020-10-16 00:37:04 +0200118 - leading_newlines_in_multiline_strings
Michael Goderbauerb3085552022-12-20 16:03:21 -0800119 - library_annotations
Dan Field8af3e482019-01-11 13:38:02 -0800120 - library_names
121 - library_prefixes
Michael Goderbauerb8a24562021-05-10 16:26:16 -0700122 - library_private_types_in_public_api
Ian Hickson6cff3382020-11-16 11:07:37 -0800123 # - lines_longer_than_80_chars # not required by flutter style
Dan Field8af3e482019-01-11 13:38:02 -0800124 - list_remove_unrelated_type
Ian Hicksonb3f63d32021-10-09 04:03:03 -0700125 # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/linter/issues/453
Michael Goderbauerfc99e7c2021-03-01 18:30:17 -0800126 - missing_whitespace_between_adjacent_strings
Dan Field8af3e482019-01-11 13:38:02 -0800127 - no_adjacent_strings_in_list
Ian Hickson7b013462021-10-11 10:23:04 -0700128 - no_default_cases
Dan Field8af3e482019-01-11 13:38:02 -0800129 - no_duplicate_case_values
Michael Goderbauer5ac97142022-01-11 17:35:13 -0800130 - no_leading_underscores_for_library_prefixes
Michael Goderbauer5684b9f2022-01-21 14:43:59 -0800131 - no_leading_underscores_for_local_identifiers
Ian Hickson6cff3382020-11-16 11:07:37 -0800132 - no_logic_in_create_state
133 # - no_runtimeType_toString # ok in tests; we enable this only in packages/
Dan Field8af3e482019-01-11 13:38:02 -0800134 - non_constant_identifier_names
Ian Hicksonbb5cbdc2021-10-12 11:28:02 -0700135 - noop_primitive_operations
Alexandre Ardhuind2858f02020-10-08 09:39:13 +0200136 - null_check_on_nullable_type_parameter
Michael Goderbauerea8e6162021-03-02 15:25:31 -0800137 - null_closures
Dan Field8af3e482019-01-11 13:38:02 -0800138 # - omit_local_variable_types # opposite of always_specify_types
139 # - one_member_abstracts # too many false positives
Ian Hickson94216272021-10-11 14:13:03 -0700140 - 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 -0800141 - overridden_fields
142 - package_api_docs
Michael Goderbauer7e017d32021-03-02 15:24:04 -0800143 - package_names
Dan Field8af3e482019-01-11 13:38:02 -0800144 - package_prefixed_library_names
145 # - parameter_assignments # we do this commonly
146 - prefer_adjacent_string_concatenation
147 - prefer_asserts_in_initializer_lists
Ian Hickson6cff3382020-11-16 11:07:37 -0800148 # - prefer_asserts_with_message # not required by flutter style
Phil Quitslund802eca22019-03-06 11:05:16 -0800149 - prefer_collection_literals
Dan Field8af3e482019-01-11 13:38:02 -0800150 - prefer_conditional_assignment
Dan Fieldfe9512f2019-04-29 16:02:42 -0700151 - prefer_const_constructors
Dan Field8af3e482019-01-11 13:38:02 -0800152 - prefer_const_constructors_in_immutables
153 - prefer_const_declarations
154 - prefer_const_literals_to_create_immutables
Ian Hickson6cff3382020-11-16 11:07:37 -0800155 # - prefer_constructors_over_static_methods # far too many false positives
Dan Field8af3e482019-01-11 13:38:02 -0800156 - prefer_contains
Alexandre Ardhuin9a3a7492019-06-25 15:59:15 +0200157 # - prefer_double_quotes # opposite of prefer_single_quotes
Dan Field8af3e482019-01-11 13:38:02 -0800158 - prefer_equal_for_default_values
159 # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
160 - prefer_final_fields
Alexandre Ardhuin4f9b6cf2020-01-07 16:32:04 +0100161 - prefer_final_in_for_each
Dan Field8af3e482019-01-11 13:38:02 -0800162 - prefer_final_locals
Michael Goderbauerbabfcb92021-12-13 14:44:10 -0800163 # - 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 +0100164 - prefer_for_elements_to_map_fromIterable
Dan Field8af3e482019-01-11 13:38:02 -0800165 - prefer_foreach
Michael Goderbauer807bb292021-03-05 18:29:04 -0800166 - prefer_function_declarations_over_variables
Dan Field8af3e482019-01-11 13:38:02 -0800167 - prefer_generic_function_type_aliases
Alexandre Ardhuindf4bf452019-09-17 16:23:44 +0200168 - prefer_if_elements_to_conditional_expressions
Alexandre Ardhuinb041a582019-07-09 10:53:35 +0200169 - prefer_if_null_operators
Dan Field8af3e482019-01-11 13:38:02 -0800170 - prefer_initializing_formals
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +0200171 - prefer_inlined_adds
Michael Goderbauer0f568292021-03-02 10:14:02 -0800172 # - 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 +0200173 - prefer_interpolation_to_compose_strings
Dan Field8af3e482019-01-11 13:38:02 -0800174 - prefer_is_empty
Alexandre Ardhuinc0125cb2019-05-20 17:00:45 +0200175 - prefer_is_not_empty
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +0100176 - prefer_is_not_operator
Dan Field8af3e482019-01-11 13:38:02 -0800177 - prefer_iterable_whereType
Michael Goderbauerfa3777b2022-12-20 11:07:15 -0800178 # - prefer_mixin # has false positives, see https://github.com/dart-lang/linter/issues/3018
Ian Hickson66dd2ad2021-10-12 11:33:04 -0700179 # - 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 -0800180 - prefer_null_aware_operators
Ian Hicksonf90b0192021-10-11 10:28:07 -0700181 - prefer_relative_imports
Dan Field8af3e482019-01-11 13:38:02 -0800182 - prefer_single_quotes
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +0200183 - prefer_spread_collections
Dan Field8af3e482019-01-11 13:38:02 -0800184 - prefer_typing_uninitialized_variables
185 - prefer_void_to_null
Michael Goderbauerd3209372021-03-02 16:34:05 -0800186 - provide_deprecation_message
Dan Field8af3e482019-01-11 13:38:02 -0800187 # - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
188 - recursive_getters
Michael Goderbauerfa3777b2022-12-20 11:07:15 -0800189 # - 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
Michael Goderbauer2a529bc2022-01-07 13:50:18 -0800190 - secure_pubspec_urls
Greg Spencerc6ef4c72021-03-04 01:29:02 +0000191 - sized_box_for_whitespace
Michael Goderbauerfa3777b2022-12-20 11:07:15 -0800192 - sized_box_shrink_expand
Dan Field8af3e482019-01-11 13:38:02 -0800193 - slash_for_doc_comments
Ian Hickson6d5fc422021-10-11 21:23:02 -0700194 - sort_child_properties_last
Dan Field8af3e482019-01-11 13:38:02 -0800195 - sort_constructors_first
Phil Quitslund1fef5912020-09-23 21:37:08 -0700196 # - sort_pub_dependencies # prevents separating pinned transitive dependencies
Dan Field8af3e482019-01-11 13:38:02 -0800197 - sort_unnamed_constructors_first
Dan Field8af3e482019-01-11 13:38:02 -0800198 - test_types_in_equals
199 - throw_in_finally
Alexandre Ardhuind2858f02020-10-08 09:39:13 +0200200 - tighten_type_of_initializing_formals
Dan Field8af3e482019-01-11 13:38:02 -0800201 # - type_annotate_public_apis # subset of always_specify_types
202 - type_init_formals
Ian Hickson299d4842021-10-14 22:03:03 -0700203 # - unawaited_futures # too many false positives, especially with the way AnimationController works
Michael Goderbauercb867bb2021-03-05 18:38:15 -0800204 - unnecessary_await_in_return
Dan Field8af3e482019-01-11 13:38:02 -0800205 - unnecessary_brace_in_string_interps
206 - unnecessary_const
Ian Hickson66dd2ad2021-10-12 11:33:04 -0700207 - unnecessary_constructor_name
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +0100208 # - unnecessary_final # conflicts with prefer_final_locals
Dan Field8af3e482019-01-11 13:38:02 -0800209 - unnecessary_getters_setters
210 # - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
Michael Goderbauer40a26892022-01-12 21:10:19 -0800211 - unnecessary_late
Michael Goderbauerfdd2d7d2022-12-20 14:15:39 -0800212 - unnecessary_library_directive
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
Michael Goderbauerfdd2d7d2022-12-20 14:15:39 -0800227 - unreachable_from_main
Dan Field8af3e482019-01-11 13:38:02 -0800228 - unrelated_type_equality_checks
Ian Hickson299d4842021-10-14 22:03:03 -0700229 - unsafe_html
Ian Hickson66dd2ad2021-10-12 11:33:04 -0700230 - use_build_context_synchronously
Michael Goderbauer81bc54b2022-12-20 14:09:55 -0800231 - use_colored_box
Michael Goderbauerfa3777b2022-12-20 11:07:15 -0800232 # - use_decorated_box # leads to bugs: DecoratedBox and Container are not equivalent (Container inserts extra padding)
Michael Goderbauer0220afd2022-12-20 12:06:24 -0800233 - use_enums
Alexandre Ardhuinb5ce0612019-06-25 17:58:19 +0200234 - use_full_hex_values_for_flutter_colors
Michael Goderbauer7b251f52021-03-04 08:59:17 -0800235 - use_function_type_syntax_for_parameters
Tomasz Gucioe4351ff2022-02-22 23:39:20 +0100236 - use_if_null_to_convert_nulls_to_bools
Alexandre Ardhuinc0176c92020-10-16 20:20:00 +0200237 - use_is_even_rather_than_modulo
Michael Goderbauer0f568292021-03-02 10:14:02 -0800238 - use_key_in_widget_constructors
Ian Hickson8a6a76a2020-08-27 16:38:10 -0700239 - use_late_for_private_fields_and_variables
Abhishek Ghaskata254c9f12021-05-14 01:59:06 +0530240 - use_named_constants
Alexandre Ardhuin17cdf552020-10-26 20:42:05 +0100241 - use_raw_strings
Dan Field8af3e482019-01-11 13:38:02 -0800242 - use_rethrow_when_possible
Ian Hickson299d4842021-10-14 22:03:03 -0700243 - use_setters_to_change_properties
Dan Field8af3e482019-01-11 13:38:02 -0800244 # - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
Michael Goderbauerfdd2d7d2022-12-20 14:15:39 -0800245 - use_string_in_part_of_directives
Michael Goderbauercc4cc692022-04-14 13:26:18 -0700246 - use_super_parameters
Alexandre Ardhuincfc08592021-06-04 07:14:03 +0200247 - use_test_throws_matchers
Dan Field8af3e482019-01-11 13:38:02 -0800248 # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
249 - valid_regexps
Ian Hicksone2b169e2020-01-13 10:03:01 -0800250 - void_checks