Skip to content

avoid_duplicate_mixins

v1.0.0 Warning Code Organization

This rule flags a with clause that lists the same mixin more than once, where every application after the first contributes nothing.

class A with M, M {} compiles, and the second M adds no members — they are already there. What it does add is a false signal: a reader counting the behaviours mixed into A sees one more than exists, and has to check whether the two entries differ before concluding they do not.

Duplicates arrive through merges, and through a rename that collapses two once-distinct names onto one.

The rule compares resolved types, not source text, so an aliased import (M and alias.M) still counts as one mixin. Type arguments are kept, so a genuinely different instantiation is not reported.

Re-applying a mixin that a superclass already has is a different question — it does change the linearization order — so it is not reported.

See also: Mixins

mixin Loggable {}
class Report with Loggable, Loggable {}
mixin Loggable {}
mixin Cacheable {}
class Report with Loggable, Cacheable {}

This rule is in the recommended preset, so it is on with preset: recommended or preset: opinionated.

To disable this rule:

many_lints.yaml
rules:
avoid_duplicate_mixins: false

To keep the rule on but skip certain paths, use per-rule exclude.