avoid-collection-methods-with-unrelated-types
preset: recommended
Warns when a collection method is used with an expression of an unrelated type.
Using unrelated types to access collection items or perform some operation (e.g. a contains
check) will always result in null
or false
(depending on the used method or access type).
⚙️ Config
Set strict
(default is true
) to exclude dynamic
and Object
types (example).
analysis_options.yaml
dart_code_metrics:
rules:
- avoid-collection-methods-with-unrelated-types:
strict: true