Skip to main content

avoid-unnecessary-extends

added in: 1.22.0
🛠
Pro+
preset: recommended

Suggests removing unnecessary extends clauses that match default values for classes and type parameters.

In Dart, all classes by default extend Object and all type parameters extend Object?. Removing those extends clauses will not affect your code.

Example

❌ Bad:

class Subclass extends Object {} // LINT: This 'extends' clause is unnecessary. Try removing it.

// LINT: This 'extends' clause is unnecessary. Try removing it.
class WithTypeParam<T extends Object?, B extends Object> {}

✅ Good:

class Base {}

class Subclass extends Base {} // Correct, different class

class Another extends Base {}

// Correct, non-nullable
class WithTypeParam<T extends Object, B extends Object> {}

Additional Resources