blob: da4cf6e35cdeac02391ee4909ca00e655dc3c662 [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
Sivab1109222019-01-03 10:55:50 -080032 # Ignore analyzer hints for updating pubspecs when using Future or
33 # Stream and not importing dart:async
34 # Please see https://github.com/flutter/flutter/pull/24528 for details.
Alexander Aprelevfe1a51a2018-12-27 14:55:07 -080035 sdk_version_async_exported_from_core: ignore
Devon Carew207451f2016-08-18 19:11:39 -070036 exclude:
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +020037 - "bin/cache/**"
Ian Hicksoncbda2082017-01-22 16:43:24 -080038 # the following two are relative to the stocks example and the flutter package respectively
39 # see https://github.com/dart-lang/sdk/issues/28463
Shi-Hao Hong3e4bf572019-11-06 12:52:03 -080040 - "lib/i18n/messages_*.dart"
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +020041 - "lib/src/http/**"
Dan Field8af3e482019-01-11 13:38:02 -080042
43linter:
44 rules:
45 # these rules are documented on and in the same order as
46 # the Dart Lint rules page to make maintenance easier
47 # https://github.com/dart-lang/linter/blob/master/example/all.yaml
48 - always_declare_return_types
49 - always_put_control_body_on_new_line
50 # - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
51 - always_require_non_null_named_parameters
52 - always_specify_types
53 - annotate_overrides
54 # - avoid_annotating_with_dynamic # conflicts with always_specify_types
Alexandre Ardhuine6935ef2019-11-25 21:03:29 +010055 # - avoid_as # required for implicit-casts: true
Alexandre Ardhuinfecf99f2019-06-25 17:40:05 +020056 - avoid_bool_literals_in_conditional_expressions
Dan Field8af3e482019-01-11 13:38:02 -080057 # - avoid_catches_without_on_clauses # we do this commonly
58 # - avoid_catching_errors # we do this commonly
59 - avoid_classes_with_only_static_members
60 # - avoid_double_and_int_checks # only useful when targeting JS runtime
61 - avoid_empty_else
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +010062 # - avoid_equals_and_hash_code_on_mutable_classes # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -080063 - avoid_field_initializers_in_const_classes
64 - avoid_function_literals_in_foreach_calls
65 # - avoid_implementing_value_types # not yet tested
66 - avoid_init_to_null
67 # - avoid_js_rounded_ints # only useful when targeting JS runtime
68 - avoid_null_checks_in_equality_operators
69 # - avoid_positional_boolean_parameters # not yet tested
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +010070 # - avoid_print # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -080071 # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
Alexandre Ardhuin0bd45bc2020-02-14 09:43:52 +010072 # - avoid_redundant_argument_values # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -080073 - avoid_relative_lib_imports
74 - avoid_renaming_method_parameters
75 - avoid_return_types_on_setters
76 # - avoid_returning_null # there are plenty of valid reasons to return null
77 # - avoid_returning_null_for_future # not yet tested
78 - avoid_returning_null_for_void
79 # - avoid_returning_this # there are plenty of valid reasons to return this
80 # - avoid_setters_without_getters # not yet tested
81 # - avoid_shadowing_type_parameters # not yet tested
82 # - avoid_single_cascade_in_expression_statements # not yet tested
83 - avoid_slow_async_io
84 - avoid_types_as_parameter_names
85 # - avoid_types_on_closure_parameters # conflicts with always_specify_types
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +010086 # - avoid_unnecessary_containers # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -080087 - avoid_unused_constructor_parameters
88 - avoid_void_async
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +010089 # - avoid_web_libraries_in_flutter # not yet tested
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
94 # - cascade_invocations # not yet tested
95 # - close_sinks # not reliable enough
96 # - comment_references # blocked on https://github.com/flutter/flutter/issues/20765
97 # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
98 - control_flow_in_finally
99 # - curly_braces_in_flow_control_structures # not yet tested
Alexandre Ardhuin9a3a7492019-06-25 15:59:15 +0200100 # - diagnostic_describe_all_properties # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -0800101 - directives_ordering
102 - empty_catches
103 - empty_constructor_bodies
104 - empty_statements
105 # - file_names # not yet tested
106 - flutter_style_todos
107 - hash_and_equals
108 - implementation_imports
109 # - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
110 - iterable_contains_unrelated_type
111 # - join_return_with_assignment # not yet tested
112 - library_names
113 - library_prefixes
114 # - lines_longer_than_80_chars # not yet tested
115 - list_remove_unrelated_type
116 # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
Alexandre Ardhuin0bd45bc2020-02-14 09:43:52 +0100117 # - missing_whitespace_between_adjacent_strings # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -0800118 - no_adjacent_strings_in_list
119 - no_duplicate_case_values
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +0100120 # - no_logic_in_create_state # not yet tested
Alexandre Ardhuin0bd45bc2020-02-14 09:43:52 +0100121 # - no_runtimeType_toString # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -0800122 - non_constant_identifier_names
123 # - null_closures # not yet tested
124 # - omit_local_variable_types # opposite of always_specify_types
125 # - one_member_abstracts # too many false positives
126 # - only_throw_errors # https://github.com/flutter/flutter/issues/5792
127 - overridden_fields
128 - package_api_docs
129 - package_names
130 - package_prefixed_library_names
131 # - parameter_assignments # we do this commonly
132 - prefer_adjacent_string_concatenation
133 - prefer_asserts_in_initializer_lists
Alexandre Ardhuin9a3a7492019-06-25 15:59:15 +0200134 # - prefer_asserts_with_message # not yet tested
Phil Quitslund802eca22019-03-06 11:05:16 -0800135 - prefer_collection_literals
Dan Field8af3e482019-01-11 13:38:02 -0800136 - prefer_conditional_assignment
Dan Fieldfe9512f2019-04-29 16:02:42 -0700137 - prefer_const_constructors
Dan Field8af3e482019-01-11 13:38:02 -0800138 - prefer_const_constructors_in_immutables
139 - prefer_const_declarations
140 - prefer_const_literals_to_create_immutables
141 # - prefer_constructors_over_static_methods # not yet tested
142 - prefer_contains
Alexandre Ardhuin9a3a7492019-06-25 15:59:15 +0200143 # - prefer_double_quotes # opposite of prefer_single_quotes
Dan Field8af3e482019-01-11 13:38:02 -0800144 - prefer_equal_for_default_values
145 # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
146 - prefer_final_fields
Alexandre Ardhuin4f9b6cf2020-01-07 16:32:04 +0100147 - prefer_final_in_for_each
Dan Field8af3e482019-01-11 13:38:02 -0800148 - prefer_final_locals
Alexandre Ardhuina5419342020-01-08 17:03:02 +0100149 - prefer_for_elements_to_map_fromIterable
Dan Field8af3e482019-01-11 13:38:02 -0800150 - prefer_foreach
151 # - prefer_function_declarations_over_variables # not yet tested
152 - prefer_generic_function_type_aliases
Alexandre Ardhuindf4bf452019-09-17 16:23:44 +0200153 - prefer_if_elements_to_conditional_expressions
Alexandre Ardhuinb041a582019-07-09 10:53:35 +0200154 - prefer_if_null_operators
Dan Field8af3e482019-01-11 13:38:02 -0800155 - prefer_initializing_formals
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +0200156 - prefer_inlined_adds
Dan Field8af3e482019-01-11 13:38:02 -0800157 # - prefer_int_literals # not yet tested
158 # - prefer_interpolation_to_compose_strings # not yet tested
159 - prefer_is_empty
Alexandre Ardhuinc0125cb2019-05-20 17:00:45 +0200160 - prefer_is_not_empty
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +0100161 - prefer_is_not_operator
Dan Field8af3e482019-01-11 13:38:02 -0800162 - prefer_iterable_whereType
163 # - prefer_mixin # https://github.com/dart-lang/language/issues/32
Alexandre Ardhuinc0125cb2019-05-20 17:00:45 +0200164 # - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +0100165 # - prefer_relative_imports # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -0800166 - prefer_single_quotes
Alexandre Ardhuin919dcf52019-06-27 21:23:16 +0200167 - prefer_spread_collections
Dan Field8af3e482019-01-11 13:38:02 -0800168 - prefer_typing_uninitialized_variables
169 - prefer_void_to_null
Alexandre Ardhuin9a3a7492019-06-25 15:59:15 +0200170 # - provide_deprecation_message # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -0800171 # - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
172 - recursive_getters
173 - slash_for_doc_comments
Alexandre Ardhuin9a3a7492019-06-25 15:59:15 +0200174 # - sort_child_properties_last # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -0800175 - sort_constructors_first
176 - sort_pub_dependencies
177 - sort_unnamed_constructors_first
Dan Field8af3e482019-01-11 13:38:02 -0800178 - test_types_in_equals
179 - throw_in_finally
180 # - type_annotate_public_apis # subset of always_specify_types
181 - type_init_formals
182 # - unawaited_futures # too many false positives
183 # - unnecessary_await_in_return # not yet tested
184 - unnecessary_brace_in_string_interps
185 - unnecessary_const
Alexandre Ardhuin4adad2c2019-12-23 18:40:56 +0100186 # - unnecessary_final # conflicts with prefer_final_locals
Dan Field8af3e482019-01-11 13:38:02 -0800187 - unnecessary_getters_setters
188 # - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
189 - unnecessary_new
190 - unnecessary_null_aware_assignments
191 - unnecessary_null_in_if_null_operators
192 - unnecessary_overrides
193 - unnecessary_parenthesis
194 - unnecessary_statements
Alexandre Ardhuin0bd45bc2020-02-14 09:43:52 +0100195 - unnecessary_string_interpolations
Dan Field8af3e482019-01-11 13:38:02 -0800196 - unnecessary_this
197 - unrelated_type_equality_checks
Alexandre Ardhuin9a3a7492019-06-25 15:59:15 +0200198 # - unsafe_html # not yet tested
Alexandre Ardhuinb5ce0612019-06-25 17:58:19 +0200199 - use_full_hex_values_for_flutter_colors
Dan Field8af3e482019-01-11 13:38:02 -0800200 # - use_function_type_syntax_for_parameters # not yet tested
Alexandre Ardhuin0bd45bc2020-02-14 09:43:52 +0100201 # - use_key_in_widget_constructors # not yet tested
Dan Field8af3e482019-01-11 13:38:02 -0800202 - use_rethrow_when_possible
203 # - use_setters_to_change_properties # not yet tested
204 # - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
205 # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
206 - valid_regexps
Ian Hicksone2b169e2020-01-13 10:03:01 -0800207 - void_checks