Skip to content

proposal: <remove_unused_mixin> #59360

Open
@FMorschel

Description

@FMorschel

remove_unused_mixin

Description

This lint suggests removing mixins or implementations with only private declarations in Dart code.

Details

This lint aims to identify mixins or implementations that consist solely of private members without any external usage. The suggestion is to remove such elements to maintain a cleaner and more maintainable codebase.

Kind

This lint falls under the category of enforcing style advice to improve code quality and maintainability.

Bad Examples

mixin M {
  void _fn(); // The declaration '_fn' isn't referenced.
}

class C with M { // New lint: remove_unused_mixin
  void _fn() {} // The declaration '_fn' isn't referenced.
}

Good Examples

mixin M {
  @override
  void _fn(); // The declaration '_fn' isn't referenced.
  void a() {}
}

class C with M {
  void _fn() {} // The declaration '_fn' isn't referenced.
}

Discussion

The remove_unused_mixin lint is designed to encourage developers to remove mixins or implementations that do not contribute to the public API of a class and only contain private members. This enhances code clarity and reduces unnecessary complexity.

More context at #54374

I'd like to discuss about: I'm not sure if there is any use case where implementations (I am more convinced extended types would probably not fall into this category but could also be discussed) could maybe be included in this lint (which would require renaming).

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P3A lower priority bug or feature requestarea-devexpFor issues related to the analysis server, IDE support, linter, `dart fix`, and diagnostic messages.devexp-linterIssues with the analyzer's support for the linter packagelinter-lint-proposallinter-status-pendingtype-enhancementA request for a change that isn't a bug

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions