dart-code-checker/dart-code-metrics

[BUG] Getting `avoid-collection-methods-with-unrelated-types` error for a valid code

saileshbro opened this issue · 5 comments

Environment and configuration

DCM version: ^5.6.0
Dart SDK version: 2.19.3

Configuration
include: package:very_good_analysis/analysis_options.yaml

dart_code_metrics:
  metrics-exclude:
    - test/**
    - "**/*.router.dart"
    - "**/*.gen.dart"
    - "**/*.locator.dart"
    - "**/*.freezed.dart"
    - "**/*.config.dart"
    - "**/*.logger.dart"
    - "**/*.form.dart"
    - "**/*.mocks.dart"
    - "**/*.g.dart"
    - "**/firebase_options*.dart"
  rules:
    - no-boolean-literal-compare
    - prefer-trailing-comma
    - no-equal-then-else
    - always-remove-listener:
        severity: warning
    - avoid-returning-widgets
    - prefer-const-border-radius:
        severity: warning
    - prefer-correct-edge-insets-constructor:
        severity: warning
    - avoid-collection-methods-with-unrelated-types
    - avoid-duplicate-exports
    - avoid-global-state
    - avoid-missing-enum-constant-in-map
    - avoid-redundant-async
    - avoid-unnecessary-type-casts:
        severity: warning
    - avoid-unrelated-type-assertions
    - avoid-unused-parameters:
        severity: warning
    - binary-expression-operand-order
    - double-literal-format
    - prefer-immediate-return:
        severity: warning
    - prefer-iterable-of:
        severity: warning
    - prefer-last:
        severity: warning

analyzer:
  plugins:
    - dart_code_metrics
  errors:
    missing_required_param: error
    missing_return: error
    must_be_immutable: error
    parameter_assignments: error
    sort_pub_dependencies: ignore
    sort_unnamed_constructors_first: warning
    avoid_renaming_method_parameters: warning
    unnecessary_getters_setters: ignore
    directives_ordering: ignore
    todo: ignore
    library_private_types_in_public_api: ignore
    no_leading_underscores_for_local_identifiers: ignore
    public_member_api_docs: ignore
    omit_local_variable_types: ignore
    lines_longer_than_80_chars: ignore
    unawaited_futures: ignore
    unnecessary_lambdas: warning
    avoid_equals_and_hash_code_on_mutable_classes: warning
    avoid_positional_boolean_parameters: ignore
    use_setters_to_change_properties: ignore
    prefer_constructors_over_static_methods: warning

  exclude:
    - "**/*.router.dart"
    - "**/*.gen.dart"
    - "**/*.locator.dart"
    - "**/*.freezed.dart"
    - "**/*.config.dart"
    - "**/*.logger.dart"
    - "**/*.form.dart"
    - "**/*.mocks.dart"
    - "**/*.g.dart"

What did you do?

  final List<String> _selectedFriends = [];

  bool get isFriendsSelected => _selectedFriends.isNotEmpty;

  bool isSelected(Friend friend) => _selectedFriends.contains(friend.ref.id);

  void onFriendSelected(Friend friend) {
    final value = !isSelected(friend);
    if (value) {
      _selectedFriends.add(friend.ref.id);
    } else {
      _selectedFriends.remove(friend.ref.id);
    }
    notifyListeners();
  }

What did you expect to happen?

I am getting a linting error for Avoid collection methods with unrelated types., with a valid dart code. It should not show the linting error for this piece of code.
image

What actually happened?

Avoid collection methods with unrelated types.
dart[avoid-collection-methods-with-unrelated-types](https://dcm.dev/docs/individuals/rules/common/avoid-collection-methods-with-unrelated-types)

Participation

  • I am willing to submit a pull request for this issue.

Additional comments

No response

@saileshbro can you hover on the id field and show the type?

@incendial id is String
image

@incendial I think this happens specially after i run build_runner

@saileshbro could you provide a repro?

Without additional information, we are unfortunately not sure how to resolve this issue. We are therefore reluctantly going to close this issue for now. Please don't hesitate to comment on the issue if you have any more information for us; we will reopen it right away! Thanks for your contribution!