dart-code-metrics
dart-code-metrics copied to clipboard
[New rule] Implement a class instead of extending it when it is semantically an interface
Please describe what the rule should do:
The rule should suggest swapping the extends
keyword to the implements
keyword if the class that is being extended follows two rules:
- Is abstract.
- Does not contain any implementations.
What category of rule is this? (place an "X" next to just one item)
[ ] Warns about a potential error (problem) [x] Suggests an alternate way of doing something (suggestion) [ ] Other (please specify:)
Provide 2-3 code examples that this rule will warn about (it will be better if you can provide both good and bad examples):
BAD:
abstract class A {}
class B extends A {}
BAD:
abstract class A {
int get a;
}
class B extends A {
// Implementation
}
BAD:
abstract class A {
int get a;
}
abstract class B extends A {
String get b;
}
class C extends B {
// Implementation
}
GOOD:
abstract class A {
int get a;
}
class B implements A {
// Implementation
}
GOOD:
abstract class A {
int get a;
}
abstract class B {
String get b;
}
abstract class C implements A, B {
@override
int get a => 1;
}
class D extends C {
// Implementation
}
Are you willing to submit a pull request to implement this rule?
Not sure at the moment.
@vlkonoshenko is this still in progress?
@vlkonoshenko is this still in progress?
It’s on pause for now. I can find extends of abstract classes. But I can`t check if there are implementation of any methods in these classes.
@vlkonoshenko what the problem with checking the implementation? You can collect class declarations and compare them to the base class to find the implemented methods, right?
Feels like this one is covered by new Dart 3.0 features.