| # Copyright 2025 The Flutter Authors |
| # Use of this source code is governed by a BSD-style license that can be |
| # found in the LICENSE file or at https://developers.google.com/open-source/licenses/bsd. |
| include: package:flutter_lints/flutter.yaml |
| |
| analyzer: |
| language: |
| # strict-casts: true # Over 300 issues; mostly parsing JSON |
| # Enabling strict-inference requires adding type annotations to a bunch of |
| # silly locations; namely `Future.delayed`. Does not seem pragmatic right |
| # now. |
| # strict-inference: true # 34 issues |
| # strict-raw-types: true # Over 100 issues. |
| errors: |
| # treat missing required parameters as a warning (not a hint) |
| missing_required_param: warning |
| exclude: |
| - '**/build/**' |
| - '**.freezed.dart' |
| - tool/flutter-sdk/ |
| |
| linter: |
| rules: |
| # Added on top of the flutter/flutter lints: |
| - prefer_generic_function_type_aliases |
| |
| # From flutter/flutter: |
| # these rules are documented on and in the same order as |
| # the Dart Lint rules page to make maintenance easier |
| # https://github.com/dart-lang/linter/blob/master/example/all.yaml |
| - always_declare_return_types |
| # - always_put_control_body_on_new_line |
| # - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219 |
| # - always_specify_types |
| - annotate_overrides |
| # - avoid_annotating_with_dynamic # conflicts with always_specify_types |
| # - avoid_as # we use 'as' in this codebase |
| # - avoid_bool_literals_in_conditional_expressions # not yet tested |
| # - avoid_catches_without_on_clauses # we do this commonly |
| # - avoid_catching_errors # we do this commonly |
| - avoid_classes_with_only_static_members |
| # - avoid_double_and_int_checks # only useful when targeting JS runtime |
| - avoid_empty_else |
| - avoid_dynamic_calls |
| - avoid_field_initializers_in_const_classes |
| - avoid_function_literals_in_foreach_calls |
| - avoid_init_to_null |
| # - avoid_js_rounded_ints # only useful when targeting JS runtime |
| # - avoid_positional_boolean_parameters # not yet tested |
| - avoid_print |
| # - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356) |
| - avoid_redundant_argument_values |
| - avoid_relative_lib_imports |
| - avoid_renaming_method_parameters |
| - avoid_return_types_on_setters |
| # - avoid_returning_null # we do this commonly |
| # - avoid_returning_this # https://github.com/dart-lang/linter/issues/842 |
| # - avoid_setters_without_getters # not yet tested |
| # - avoid_single_cascade_in_expression_statements # not yet tested |
| - avoid_slow_async_io |
| # - avoid_types_as_parameter_names # https://github.com/dart-lang/linter/pull/954/files |
| # - avoid_types_on_closure_parameters # conflicts with always_specify_types |
| - avoid_unnecessary_containers |
| # - avoid_unused_constructor_parameters # https://github.com/dart-lang/linter/pull/847 |
| - await_only_futures |
| - camel_case_types |
| - cancel_subscriptions |
| # - cascade_invocations # not yet tested |
| # - close_sinks # https://github.com/flutter/flutter/issues/5789 |
| # - comment_references # blocked on https://github.com/dart-lang/dartdoc/issues/1153 |
| # - constant_identifier_names # https://github.com/dart-lang/linter/issues/204 |
| - control_flow_in_finally |
| - directives_ordering |
| - discarded_futures |
| - empty_catches |
| - empty_constructor_bodies |
| - empty_statements |
| - hash_and_equals |
| - implementation_imports |
| # - join_return_with_assignment # not yet tested |
| - library_names |
| - library_prefixes |
| # - literal_only_boolean_expressions # https://github.com/flutter/flutter/issues/5791 |
| - no_adjacent_strings_in_list |
| - no_duplicate_case_values |
| - non_constant_identifier_names |
| # - omit_local_variable_types # opposite of always_specify_types |
| # - one_member_abstracts # too many false positives |
| # - only_throw_errors # https://github.com/flutter/flutter/issues/5792 |
| - overridden_fields |
| - package_names |
| - package_prefixed_library_names |
| # - parameter_assignments # we do this commonly |
| - prefer_adjacent_string_concatenation |
| - prefer_asserts_in_initializer_lists |
| - prefer_collection_literals |
| - prefer_conditional_assignment |
| - prefer_const_constructors |
| - prefer_const_constructors_in_immutables |
| - prefer_const_declarations |
| - prefer_const_literals_to_create_immutables |
| # - prefer_constructors_over_static_methods # not yet tested |
| - prefer_contains |
| # - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/blob/master/docs/contributing/Style-guide-for-Flutter-repo.md#consider-using--for-short-functions-and-methods |
| - prefer_final_fields |
| - prefer_final_in_for_each |
| - prefer_final_locals |
| - prefer_foreach |
| # - prefer_function_declarations_over_variables # not yet tested |
| - prefer_initializing_formals |
| # - prefer_interpolation_to_compose_strings # not yet tested |
| # - prefer_iterable_whereType # https://github.com/dart-lang/sdk/issues/32463 |
| - prefer_is_empty |
| - prefer_is_not_empty |
| - prefer_relative_imports |
| - prefer_single_quotes |
| - prefer_typing_uninitialized_variables |
| # Obsolete with the new Dart formatter. |
| # - require_trailing_commas |
| - recursive_getters |
| - slash_for_doc_comments |
| - sort_child_properties_last |
| - sort_constructors_first |
| - sort_unnamed_constructors_first |
| - test_types_in_equals |
| - throw_in_finally |
| # - type_annotate_public_apis # subset of always_specify_types |
| - type_init_formals |
| - unawaited_futures |
| - unnecessary_brace_in_string_interps |
| - unnecessary_const |
| - unnecessary_getters_setters |
| # - unnecessary_lambdas # https://github.com/dart-lang/linter/issues/498 |
| - unnecessary_library_directive |
| - unnecessary_new |
| - unnecessary_null_aware_assignments |
| - unnecessary_null_in_if_null_operators |
| - unnecessary_overrides |
| - unnecessary_parenthesis |
| - unnecessary_statements |
| - unnecessary_this |
| - unrelated_type_equality_checks |
| - use_rethrow_when_possible |
| # - use_setters_to_change_properties # not yet tested |
| # - use_string_buffers # https://github.com/dart-lang/linter/pull/664 |
| - use_string_in_part_of_directives |
| # - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review |
| - valid_regexps |
| # - void_checks # not yet tested |
| |
| dart_code_metrics: |
| metrics: |
| cyclomatic-complexity: 20 |
| number-of-parameters: 4 |
| maximum-nesting-level: 5 |
| metrics-exclude: |
| - test/** |
| rules: |
| # - arguments-ordering Too strict |
| # - avoid-banned-imports # TODO(polina-c): add configuration |
| - avoid-importing-entrypoint-exports: |
| only-in-src: true |
| - avoid-cascade-after-if-null |
| - avoid-collection-methods-with-unrelated-types |
| - avoid-duplicate-exports |
| - avoid-dynamic |
| # - avoid-global-state TODO(jacobr): bunch of false positives around boolean flags. |
| # - avoid-ignoring-return-values |
| # - avoid-late-keyword |
| - avoid-missing-enum-constant-in-map |
| # - avoid-nested-conditional-expressions Worth enabling but currently too many violators. |
| # - avoid-non-ascii-symbols TODO(jacobr): probably worth enabling. |
| # - avoid-non-null-assertion |
| # - avoid-passing-async-when-sync-expected TODO(jacobr): consider re-enabliing. |
| - avoid-redundant-async |
| - avoid-throw-in-catch-block: |
| exclude: |
| - '*test.dart' |
| |
| # - avoid-top-level-members-in-tests Doesn't seem to match our style. |
| - avoid-unnecessary-type-assertions |
| - avoid-unnecessary-type-casts |
| - avoid-unrelated-type-assertions |
| - avoid-unused-parameters |
| - avoid-explicit-type-declaration |
| # - ban-name # TODO(polina-c): add configuration |
| # - binary-expression-operand-order Some nice catches but too many false positives to enable. |
| - double-literal-format |
| # - format-comment TODO(jacobr): enable this one after fixing violations. |
| # TODO(jacobr): enable member-ordering. This catches a bunch of real style |
| # issues but would be alot of work to migrate. |
| # - member-ordering |
| # - newline-before-return TODO(jacobr): should be in the formatter if it was a rule to adopt. |
| - no-boolean-literal-compare |
| # - no-empty-block Too many false positives. However it does flag a bunch of code smells so possibly worth re-enabling. |
| # This one seems interesting but has too many false positives. Gave it a try. |
| # - no-equal-arguments: |
| # ignored-parameters: |
| # - height |
| # - width |
| # - double-literal-format |
| # - defaultSortColumn |
| # - left |
| # - right |
| # - top |
| # - bottom |
| # - bottomLeft |
| # - topLeft |
| # - enabledBorder |
| - no-equal-then-else |
| # - no-magic-number |
| # - no-object-declaration Too difficult to use along with avoiding dynamic particular for JSON decoding logic. |
| # - prefer-async-await TODO(jacobr): evaluate enabling. |
| - prefer-commenting-analyzer-ignores |
| # - prefer-conditional-expressions Too many false positives involving large conditional expressions. |
| # - prefer-correct-identifier-length Too many false positives with fine names like i and id. |
| # - prefer-correct-test-file-name TODO(jacobr): enable and fix violations. |
| - prefer-correct-type-name |
| # - prefer-enums-by-name Cannot able unless lint adds a special case for orElse |
| # - prefer-first TODO(jacobr): enable as a follow up PR. |
| # - prefer-immediate-return TODO(jacobr): enable as a follow up PR. |
| - prefer-iterable-of |
| - prefer-last |
| # - prefer-match-file-name |
| # TODO(jacobr): consider enabling or enabling to periodically audit. |
| # This one has a lot of false positives but is also quite nice. |
| # - prefer-moving-to-variable: |
| # allowed-duplicated-chains: 2 |
| # - prefer-static-class |
| # Obsolete with the new Dart formatter. |
| # - prefer-trailing-comma |
| - always-remove-listener |
| # - avoid-border-all Micro-optimization to avoid a const constructor. |
| # - avoid-returning-widgets This one is nice but has a lot of false positives. |
| - avoid-shrink-wrap-in-lists |
| # - avoid-unnecessary-setstate It is unclear why to "Avoid calling sync methods that call 'setState'." |
| - avoid-expanded-as-spacer |
| - avoid-wrapping-in-padding |
| - check-for-equals-in-render-object-setters |
| - consistent-update-render-object |
| # - prefer-const-border-radius TODO(jacobr): enable. |
| - prefer-correct-edge-insets-constructor |
| # - prefer-extracting-callbacks I'm not clear this is always a good idea. Seems like a workaround. |
| # - prefer-single-widget-per-file |
| - prefer-using-list-view |
| - prefer-explicit-type-arguments |
| - prefer-explicit-function-type |