Skip to content

proposal: equality_operator_override_with_nullable_parameter #58965

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
5 tasks
srawlins opened this issue Dec 14, 2022 · 1 comment
Closed
5 tasks

proposal: equality_operator_override_with_nullable_parameter #58965

srawlins opened this issue Dec 14, 2022 · 1 comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-lint-proposal linter-set-recommended linter-status-pending

Comments

@srawlins
Copy link
Member

srawlins commented Dec 14, 2022

equality_operator_override_with_nullable_parameter

Description

Do not override the equality operator to have a nullable parameter.

Details

No Dart implementation will ever pass null to an equality operator, so no equality operator should accept a nullable parameter. Object.== accepts an Object.

Kind

Improves readability, guards against misunderstanding...

Bad Examples

class C {
  @override
  bool operator ==(Object? other) {
    return true;
  }
}

Good Examples

class C {
  @override
  bool operator ==(Object other) {
    return true;
  }
}

Discussion

I have found a number of cases of classes which override to accept a dynamic parameter, while switching mockito-dependant tests to use code-generated mockito. Code-generated mockito includes an override for ==, which stumbles, trying to re-narrow the parameter type to Object.

This rule would more-or-less replace https://dart-lang.github.io/linter/lints/avoid_null_checks_in_equality_operators.html.

Discussion checklist

  • List any existing rules this proposal modifies, complements, overlaps or conflicts with.
  • List any relevant issues (reported here, the SDK Tracker, or elsewhere).
  • If there's any prior art (e.g., in other linters), please add references here.
  • If this proposal corresponds to Effective Dart or Flutter Style Guide advice, please call it out. (If there isn't any corresponding advice, should there be?)
  • If this proposal is motivated by real-world examples, please provide as many details as you can. Demonstrating potential impact is especially valuable.
@srawlins
Copy link
Member Author

Oops, found the existing issue. #58753

@devoncarew devoncarew added devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. labels Nov 19, 2024
@devoncarew devoncarew transferred this issue from dart-archive/linter Nov 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
devexp-linter Issues with the analyzer's support for the linter package legacy-area-analyzer Use area-devexp instead. linter-lint-proposal linter-set-recommended linter-status-pending
Projects
None yet
Development

No branches or pull requests

2 participants