analysis_options.yaml 7.21 KB
Newer Older
1
# Specify analysis options.
2 3 4 5 6 7 8 9
#
# 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
# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer
#
10 11 12
# There are other similar analysis options files in the flutter repos,
# which should be kept in sync with this file:
#
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 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
  strong-mode:
    implicit-dynamic: false
24
  errors:
25 26
    # treat missing required parameters as a warning (not a hint)
    missing_required_param: warning
27
    # treat missing returns as a warning (not a hint)
28
    missing_return: warning
29
    # allow having TODOs in the code
30
    todo: ignore
31
  exclude:
32
    - 'bin/cache/**'
33 34 35 36
    # the following two are relative to the stocks example and the flutter package respectively
    # see https://github.com/dart-lang/sdk/issues/28463
    - 'lib/i18n/stock_messages_*.dart'
    - 'lib/src/http/**'
37

38 39
linter:
  rules:
40 41
    # these rules are documented on and in the same order as
    # the Dart Lint rules page to make maintenance easier
42
    # 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 48
    - always_specify_types
    - annotate_overrides
49
    # - avoid_annotating_with_dynamic # conflicts with always_specify_types
50
    - avoid_as
51
    # - avoid_bool_literals_in_conditional_expressions # not yet tested
52 53
    # - avoid_catches_without_on_clauses # we do this commonly
    # - avoid_catching_errors # we do this commonly
54
    - avoid_classes_with_only_static_members
55
    # - avoid_double_and_int_checks # only useful when targeting JS runtime
56
    - avoid_empty_else
57
    - avoid_field_initializers_in_const_classes
58
    - avoid_function_literals_in_foreach_calls
59
    - avoid_init_to_null
60
    # - avoid_js_rounded_ints # only useful when targeting JS runtime
61
    - avoid_null_checks_in_equality_operators
62
    # - avoid_positional_boolean_parameters # not yet tested
63
    # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
64
    - avoid_relative_lib_imports
65
    - avoid_renaming_method_parameters
66
    - avoid_return_types_on_setters
67 68
    # - avoid_returning_null # there are plenty of valid reasons to return null
    # - avoid_returning_this # there are plenty of valid reasons to return this
69
    # - avoid_setters_without_getters # not yet tested
70
    # - avoid_single_cascade_in_expression_statements # not yet tested
71
    - avoid_slow_async_io
72
    - avoid_types_as_parameter_names
73
    # - avoid_types_on_closure_parameters # conflicts with always_specify_types
74
    - avoid_unused_constructor_parameters
75
    - avoid_void_async
76
    - await_only_futures
77
    - camel_case_types
78
    - cancel_subscriptions
79
    # - cascade_invocations # not yet tested
80 81 82
    # - close_sinks # not reliable enough
    # - comment_references # blocked on https://github.com/flutter/flutter/issues/20765
    # - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
83
    - control_flow_in_finally
84
    # - curly_braces_in_flow_control_structures # not yet tested
85
    - directives_ordering
86
    - empty_catches
87
    - empty_constructor_bodies
88
    - empty_statements
89
    # - file_names # not yet tested
90
    - hash_and_equals
91
    - implementation_imports
92
    # - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
93
    - iterable_contains_unrelated_type
94
    # - join_return_with_assignment # not yet tested
95 96
    - library_names
    - library_prefixes
97
    # - lines_longer_than_80_chars # not yet tested
98
    - list_remove_unrelated_type
99
    # - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
100 101
    - no_adjacent_strings_in_list
    - no_duplicate_case_values
102
    - non_constant_identifier_names
103
    # - null_closures  # not yet tested
104
    # - omit_local_variable_types # opposite of always_specify_types
105
    # - one_member_abstracts # too many false positives
106
    # - only_throw_errors # https://github.com/flutter/flutter/issues/5792
107
    - overridden_fields
108
    - package_api_docs
109
    - package_names
110
    - package_prefixed_library_names
111
    # - parameter_assignments # we do this commonly
112
    - prefer_adjacent_string_concatenation
113
    - prefer_asserts_in_initializer_lists
114
    - prefer_bool_in_asserts
115
    - prefer_collection_literals
116
    - prefer_conditional_assignment
117
    - prefer_const_constructors
118
    - prefer_const_constructors_in_immutables
119 120
    - prefer_const_declarations
    - prefer_const_literals_to_create_immutables
121
    # - prefer_constructors_over_static_methods # not yet tested
122
    - prefer_contains
123
    - prefer_equal_for_default_values
124
    # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
125
    - prefer_final_fields
126
    - prefer_final_locals
127
    - prefer_foreach
128
    # - prefer_function_declarations_over_variables # not yet tested
129
    - prefer_generic_function_type_aliases
130
    - prefer_initializing_formals
131
    # - prefer_interpolation_to_compose_strings # not yet tested
132
    - prefer_is_empty
133
    - prefer_is_not_empty
134
    - prefer_iterable_whereType
135
    # - prefer_mixin # https://github.com/dart-lang/language/issues/32
136
    - prefer_single_quotes
137
    - prefer_typing_uninitialized_variables
138
    - prefer_void_to_null
139
    # - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
140
    - recursive_getters
141 142 143 144
    - slash_for_doc_comments
    - sort_constructors_first
    - sort_unnamed_constructors_first
    - super_goes_last
145 146
    - test_types_in_equals
    - throw_in_finally
147
    # - type_annotate_public_apis # subset of always_specify_types
148
    - type_init_formals
149
    # - unawaited_futures # too many false positives
150
    - unnecessary_brace_in_string_interps
151
    - unnecessary_const
152
    - unnecessary_getters_setters
153
    # - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
154
    - unnecessary_new
155 156
    - unnecessary_null_aware_assignments
    - unnecessary_null_in_if_null_operators
157
    - unnecessary_overrides
158
    - unnecessary_parenthesis
159
    - unnecessary_statements
160
    - unnecessary_this
161
    - unrelated_type_equality_checks
162
    - use_rethrow_when_possible
163
    # - use_setters_to_change_properties # not yet tested
164
    # - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
165
    # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
166
    - valid_regexps
167
    # - void_checks # not yet tested