Skip to content

[linter] unnecessary_implements #60624

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

Open
FMorschel opened this issue Apr 25, 2025 · 2 comments
Open

[linter] unnecessary_implements #60624

FMorschel opened this issue Apr 25, 2025 · 2 comments
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-warning Issues with the analyzer's Warning codes P3 A lower priority bug or feature request

Comments

@FMorschel
Copy link
Contributor

Consider the following code:

abstract class A {}

mixin class MixinClass implements A {}

class C with MixinClass implements MixinClass, A {}

abstract class C2 implements MixinClass, A {}

class D extends A implements A {}

With C using MixinClass as a mixin, there is no need for either implements. I'm less sure about the warning on A since it can be breaking if the author removes the mixin and still wants to implement A, but the same class showing up twice on the declaration is completely unnecessary.

For D, we already trigger implements_super_class (docs).

CC @lrhn, @bwilkerson

@FMorschel FMorschel added the area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. label Apr 25, 2025
@bwilkerson
Copy link
Member

I'll note that the implements_super_class diagnostic is a compile time error defined by the specification.

There's also a compile time error specified for repeating a type in the implements clause:

class A {}

class B implements A, A {} // The second `A` is flagged by the `implements_repeated` diagnostic

The suggested diagnostic certainly appears to be consistent with some of the compile time errors.

It isn't clear whether this should be a lint or a warning. I don't see any way to have false positives, and it does seem unlikely that anyone wants code that implements the same interface multiple times.

@lrhn
Copy link
Member

lrhn commented Apr 28, 2025

It really shouldn't be a spec error. I think the analyzer is perfectly capable of giving reasonable warnings for unnecessary code, without the spec getting in its way.

It is unnecessary code to implement something you would have as a superinterface anyway. A warning is in order for that.

(Writing the same interface twice on the same syntactic implements is just so obviously unnecessary, that there was no excuse.)

@bwilkerson bwilkerson added devexp-warning Issues with the analyzer's Warning codes P2 A bug or feature request we're likely to work on P3 A lower priority bug or feature request and removed P2 A bug or feature request we're likely to work on labels Apr 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-devexp For issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages. devexp-warning Issues with the analyzer's Warning codes P3 A lower priority bug or feature request
Projects
None yet
Development

No branches or pull requests

3 participants