blob: 577432e3d6e98562408832057d14ff370bd2c414 [file] [log] [blame]
Dan Field8af3e482019-01-11 13:38:02 -08001# Specify analysis options.
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# For a list of lints, see: http://dart-lang.github.io/linter/lints/
7# See the configuration guide for more
8# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer
9#
10# There are other similar analysis options files in the flutter repos,
11# which should be kept in sync with this file:
12#
13# - analysis_options.yaml (this file)
14# - packages/flutter/lib/analysis_options_user.yaml
15# - https://github.com/flutter/plugins/blob/master/analysis_options.yaml
16# - https://github.com/flutter/engine/blob/master/analysis_options.yaml
17#
18# This file contains the analysis options used by Flutter tools, such as IntelliJ,
19# Android Studio, and the `flutter analyze` command.
krisgiesing07b5f832016-05-04 10:15:15 -070020
21analyzer:
Dan Field8af3e482019-01-11 13:38:02 -080022 strong-mode:
Alexandre Ardhuin78db9652019-12-19 11:23:01 +010023 implicit-casts: false
Dan Field8af3e482019-01-11 13:38:02 -080024 implicit-dynamic: false
krisgiesing07b5f832016-05-04 10:15:15 -070025 errors:
Dan Field8af3e482019-01-11 13:38:02 -080026 # treat missing required parameters as a warning (not a hint)
27 missing_required_param: warning
28 # treat missing returns as a warning (not a hint)
29 missing_return: warning
30 # allow having TODOs in the code
31 todo: ignore
Christopher Fujino5cfb16b2020-06-19 12:03:38 -070032 # 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
Sivab1109222019-01-03 10:55:50 -080035 # 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.
Alexander Aprelevfe1a51a2018-12-27 14:55:07 -080038 sdk_version_async_exported_from_core: ignore
Michael Goderbauer0f91f0d2021-03-02 21:14:03 -080039 # Turned off until null-safe rollout is complete.
40 unnecessary_null_comparison: ignore
Devon Carew207451f2016-08-18 19:11:39 -070041 exclude:
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +020042 - "bin/cache/**"
Christopher Fujino4a7f2802021-04-19 15:04:04 -070043 # Ignore protoc generated files
44 - "dev/tools/lib/proto/*"
Dan Field8af3e482019-01-11 13:38:02 -080045
46linter:
47 rules:
48 # these rules are documented on and in the same order as
49 # the Dart Lint rules page to make maintenance easier
50 # https://github.com/dart-lang/linter/blob/master/example/all.yaml
51 - always_declare_return_types
52 - always_put_control_body_on_new_line
53 # - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
54 - always_require_non_null_named_parameters
55 - always_specify_types
Alexandre Ardhuin73301a32020-10-16 00:37:04 +020056 # - always_use_package_imports # we do this commonly
Dan Field8af3e482019-01-11 13:38:02 -080057 - annotate_overrides
58 # - avoid_annotating_with_dynamic # conflicts with always_specify_types
Alexandre Ardhuinfecf99f2019-06-25 17:40:05 +020059 - avoid_bool_literals_in_conditional_expressions
Dan Field8af3e482019-01-11 13:38:02 -080060 # - avoid_catches_without_on_clauses # we do this commonly
61 # - avoid_catching_errors # we do this commonly
62 - avoid_classes_with_only_static_members
63 # - avoid_double_and_int_checks # only useful when targeting JS runtime
Michael Goderbauer1512af72021-03-02 08:34:03 -080064 # - avoid_dynamic_calls # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -080065 - avoid_empty_else
Alexandre Ardhuinf5a99022020-04-06 22:36:01 +020066 - avoid_equals_and_hash_code_on_mutable_classes
Alexandre Ardhuin73301a32020-10-16 00:37:04 +020067 # - avoid_escaping_inner_quotes # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -080068 - avoid_field_initializers_in_const_classes
69 - avoid_function_literals_in_foreach_calls
70 # - avoid_implementing_value_types # not yet tested
71 - avoid_init_to_null
72 # - avoid_js_rounded_ints # only useful when targeting JS runtime
73 - avoid_null_checks_in_equality_operators
74 # - avoid_positional_boolean_parameters # not yet tested
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +010075 # - avoid_print # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -080076 # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
Alexandre Ardhuin0bd45bc2020-02-14 09:43:52 +010077 # - avoid_redundant_argument_values # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -080078 - avoid_relative_lib_imports
79 - avoid_renaming_method_parameters
80 - avoid_return_types_on_setters
81 # - avoid_returning_null # there are plenty of valid reasons to return null
82 # - avoid_returning_null_for_future # not yet tested
83 - avoid_returning_null_for_void
84 # - avoid_returning_this # there are plenty of valid reasons to return this
85 # - avoid_setters_without_getters # not yet tested
Ian Hickson6cff3382020-11-16 11:07:37 -080086 - avoid_shadowing_type_parameters
Alexandre Ardhuinc2ae6542020-03-05 08:03:26 +010087 - avoid_single_cascade_in_expression_statements
Dan Field8af3e482019-01-11 13:38:02 -080088 - avoid_slow_async_io
Michael Goderbauer3594d1a2021-03-01 15:50:04 -080089 - avoid_type_to_string
Dan Field8af3e482019-01-11 13:38:02 -080090 - avoid_types_as_parameter_names
91 # - avoid_types_on_closure_parameters # conflicts with always_specify_types
Michael Goderbauered755fb2021-03-04 15:29:03 -080092 - avoid_unnecessary_containers
Dan Field8af3e482019-01-11 13:38:02 -080093 - avoid_unused_constructor_parameters
94 - avoid_void_async
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +010095 # - avoid_web_libraries_in_flutter # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -080096 - await_only_futures
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +010097 - camel_case_extensions
Dan Field8af3e482019-01-11 13:38:02 -080098 - camel_case_types
99 - cancel_subscriptions
100 # - cascade_invocations # not yet tested
Alexandre Ardhuin4acc7902020-10-08 21:05:43 +0200101 - cast_nullable_to_non_nullable
Dan Field8af3e482019-01-11 13:38:02 -0800102 # - close_sinks # not reliable enough
Michael Goderbauer1512af72021-03-02 08:34:03 -0800103 # - comment_references # blocked on https://github.com/dart-lang/linter/issues/1142
Dan Field8af3e482019-01-11 13:38:02 -0800104 # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
105 - control_flow_in_finally
Ian Hickson6cff3382020-11-16 11:07:37 -0800106 # - curly_braces_in_flow_control_structures # not required by flutter style
Kate Lovettfd890292021-03-08 14:49:03 -0600107 - deprecated_consistency
Alexandre Ardhuin9a3a7492019-06-25 15:59:15 +0200108 # - diagnostic_describe_all_properties # not yet tested
Phil Quitslund44157cf2021-04-30 17:29:04 -0700109 - directives_ordering
Alexandre Ardhuin73301a32020-10-16 00:37:04 +0200110 # - do_not_use_environment # we do this commonly
Dan Field8af3e482019-01-11 13:38:02 -0800111 - empty_catches
112 - empty_constructor_bodies
113 - empty_statements
Alexandre Ardhuin73301a32020-10-16 00:37:04 +0200114 - exhaustive_cases
Michael Goderbauer7e017d32021-03-02 15:24:04 -0800115 - file_names
Dan Field8af3e482019-01-11 13:38:02 -0800116 - flutter_style_todos
117 - hash_and_equals
118 - implementation_imports
119 # - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
120 - iterable_contains_unrelated_type
Ian Hickson6cff3382020-11-16 11:07:37 -0800121 # - join_return_with_assignment # not required by flutter style
Alexandre Ardhuin73301a32020-10-16 00:37:04 +0200122 - leading_newlines_in_multiline_strings
Dan Field8af3e482019-01-11 13:38:02 -0800123 - library_names
124 - library_prefixes
Michael Goderbauerb8a24562021-05-10 16:26:16 -0700125 - library_private_types_in_public_api
Ian Hickson6cff3382020-11-16 11:07:37 -0800126 # - lines_longer_than_80_chars # not required by flutter style
Dan Field8af3e482019-01-11 13:38:02 -0800127 - list_remove_unrelated_type
128 # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
Michael Goderbauerfc99e7c2021-03-01 18:30:17 -0800129 - missing_whitespace_between_adjacent_strings
Dan Field8af3e482019-01-11 13:38:02 -0800130 - no_adjacent_strings_in_list
Alexandre Ardhuin73301a32020-10-16 00:37:04 +0200131 # - no_default_cases # too many false positives
Dan Field8af3e482019-01-11 13:38:02 -0800132 - no_duplicate_case_values
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
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
140 # - only_throw_errors # https://github.com/flutter/flutter/issues/5792
141 - 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
Alexandre Ardhuina5419342020-01-08 17:03:02 +0100163 - prefer_for_elements_to_map_fromIterable
Dan Field8af3e482019-01-11 13:38:02 -0800164 - prefer_foreach
Michael Goderbauer807bb292021-03-05 18:29:04 -0800165 - prefer_function_declarations_over_variables
Dan Field8af3e482019-01-11 13:38:02 -0800166 - prefer_generic_function_type_aliases
Alexandre Ardhuindf4bf452019-09-17 16:23:44 +0200167 - prefer_if_elements_to_conditional_expressions
Alexandre Ardhuinb041a582019-07-09 10:53:35 +0200168 - prefer_if_null_operators
Dan Field8af3e482019-01-11 13:38:02 -0800169 - prefer_initializing_formals
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +0200170 - prefer_inlined_adds
Michael Goderbauer0f568292021-03-02 10:14:02 -0800171 # - prefer_int_literals # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#use-double-literals-for-double-constants
172 # - prefer_interpolation_to_compose_strings # doesn't work with raw strings, see https://github.com/dart-lang/linter/issues/2490
Dan Field8af3e482019-01-11 13:38:02 -0800173 - prefer_is_empty
Alexandre Ardhuinc0125cb2019-05-20 17:00:45 +0200174 - prefer_is_not_empty
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +0100175 - prefer_is_not_operator
Dan Field8af3e482019-01-11 13:38:02 -0800176 - prefer_iterable_whereType
177 # - prefer_mixin # https://github.com/dart-lang/language/issues/32
Michael Goderbauer6586a062021-03-02 16:14:03 -0800178 - prefer_null_aware_operators
Michael Goderbauercb867bb2021-03-05 18:38:15 -0800179 # - prefer_relative_imports # incompatible with sub-package imports
Dan Field8af3e482019-01-11 13:38:02 -0800180 - prefer_single_quotes
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +0200181 - prefer_spread_collections
Dan Field8af3e482019-01-11 13:38:02 -0800182 - prefer_typing_uninitialized_variables
183 - prefer_void_to_null
Michael Goderbauerd3209372021-03-02 16:34:05 -0800184 - provide_deprecation_message
Dan Field8af3e482019-01-11 13:38:02 -0800185 # - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
186 - recursive_getters
Greg Spencerc6ef4c72021-03-04 01:29:02 +0000187 - sized_box_for_whitespace
Dan Field8af3e482019-01-11 13:38:02 -0800188 - slash_for_doc_comments
Alexandre Ardhuin9a3a7492019-06-25 15:59:15 +0200189 # - sort_child_properties_last # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -0800190 - sort_constructors_first
Phil Quitslund1fef5912020-09-23 21:37:08 -0700191 # - sort_pub_dependencies # prevents separating pinned transitive dependencies
Dan Field8af3e482019-01-11 13:38:02 -0800192 - sort_unnamed_constructors_first
Dan Field8af3e482019-01-11 13:38:02 -0800193 - test_types_in_equals
194 - throw_in_finally
Alexandre Ardhuind2858f02020-10-08 09:39:13 +0200195 - tighten_type_of_initializing_formals
Dan Field8af3e482019-01-11 13:38:02 -0800196 # - type_annotate_public_apis # subset of always_specify_types
197 - type_init_formals
198 # - unawaited_futures # too many false positives
Michael Goderbauercb867bb2021-03-05 18:38:15 -0800199 - unnecessary_await_in_return
Dan Field8af3e482019-01-11 13:38:02 -0800200 - unnecessary_brace_in_string_interps
201 - unnecessary_const
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +0100202 # - unnecessary_final # conflicts with prefer_final_locals
Dan Field8af3e482019-01-11 13:38:02 -0800203 - unnecessary_getters_setters
204 # - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
205 - unnecessary_new
206 - unnecessary_null_aware_assignments
Alexandre Ardhuin73301a32020-10-16 00:37:04 +0200207 # - unnecessary_null_checks # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -0800208 - unnecessary_null_in_if_null_operators
Alexandre Ardhuin71c1f6c2020-09-23 06:39:47 +0200209 - unnecessary_nullable_for_final_variable_declarations
Dan Field8af3e482019-01-11 13:38:02 -0800210 - unnecessary_overrides
211 - unnecessary_parenthesis
Alexandre Ardhuin73301a32020-10-16 00:37:04 +0200212 # - unnecessary_raw_strings # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -0800213 - unnecessary_statements
Alexandre Ardhuin17cdf552020-10-26 20:42:05 +0100214 - unnecessary_string_escapes
Alexandre Ardhuin0bd45bc2020-02-14 09:43:52 +0100215 - unnecessary_string_interpolations
Dan Field8af3e482019-01-11 13:38:02 -0800216 - unnecessary_this
217 - unrelated_type_equality_checks
Alexandre Ardhuin9a3a7492019-06-25 15:59:15 +0200218 # - unsafe_html # not yet tested
Alexandre Ardhuinb5ce0612019-06-25 17:58:19 +0200219 - use_full_hex_values_for_flutter_colors
Michael Goderbauer7b251f52021-03-04 08:59:17 -0800220 - use_function_type_syntax_for_parameters
Michael Goderbauer1512af72021-03-02 08:34:03 -0800221 # - use_if_null_to_convert_nulls_to_bools # not yet tested
Alexandre Ardhuinc0176c92020-10-16 20:20:00 +0200222 - use_is_even_rather_than_modulo
Michael Goderbauer0f568292021-03-02 10:14:02 -0800223 - use_key_in_widget_constructors
Ian Hickson8a6a76a2020-08-27 16:38:10 -0700224 - use_late_for_private_fields_and_variables
Jehun Seem(심제훈)78a1a0c2021-03-17 11:05:03 -0700225 # - use_named_constants # not yet tested
Alexandre Ardhuin17cdf552020-10-26 20:42:05 +0100226 - use_raw_strings
Dan Field8af3e482019-01-11 13:38:02 -0800227 - use_rethrow_when_possible
228 # - use_setters_to_change_properties # not yet tested
229 # - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
230 # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
231 - valid_regexps
Ian Hicksone2b169e2020-01-13 10:03:01 -0800232 - void_checks