avoid-duplicate-mixins

Path
lint/correctness/avoid-duplicate-mixins
Default
Off, opt in
Origin
Falcon
Rule
52 of 512

Flags repeated mixins in a with clause or a same-library superclass chain. Implemented interfaces do not count. Unknown ancestry, super calls, and intervening member overrides are skipped: reapplication can change behavior.

Invalid

example.dartdart
mixin M {}
mixin N<T> {}
class A with M, M {}
class B with N<int>, N<int> {}
class C = Object with M, M;
class D with M, M {}
enum E with M, M { value }
mixin class MC {}
class Base with M {}
class Middle extends Base {}
class Inherited extends Middle with M {}
class AliasBase = Object with M;
class InheritedAlias extends AliasBase with M {}
class Direct extends MC with MC {}
class Forward extends Later with M {}
class Later with M {}
mixin Greeter { String greet() => 'hi'; }
mixin Spacer { String other() => 'other'; }
class NoConflict with Greeter, Spacer, Greeter {}
class GreeterBase with Greeter { String other() => 'other'; }
class NoConflictInherited extends GreeterBase with Greeter {}
This mixin is already applied without intervening overrides — remove it or replace it with the intended mixin.
2mixin N<T> {}
3class A with M, M {}
This mixin is already applied without intervening overrides — remove it or replace it with the intended mixin.
3class A with M, M {}
4class B with N<int>, N<int> {}
This mixin is already applied without intervening overrides — remove it or replace it with the intended mixin.
4class B with N<int>, N<int> {}
5class C = Object with M, M;
This mixin is already applied without intervening overrides — remove it or replace it with the intended mixin.
5class C = Object with M, M;
6class D with M, M {}
This mixin is already applied without intervening overrides — remove it or replace it with the intended mixin.
6class D with M, M {}
7enum E with M, M { value }
This mixin is already applied without intervening overrides — remove it or replace it with the intended mixin.
10class Middle extends Base {}
11class Inherited extends Middle with M {}
This mixin is already applied without intervening overrides — remove it or replace it with the intended mixin.
12class AliasBase = Object with M;
13class InheritedAlias extends AliasBase with M {}
This mixin is already applied without intervening overrides — remove it or replace it with the intended mixin.
13class InheritedAlias extends AliasBase with M {}
14class Direct extends MC with MC {}
This mixin is already applied without intervening overrides — remove it or replace it with the intended mixin.
14class Direct extends MC with MC {}
15class Forward extends Later with M {}
This mixin is already applied without intervening overrides — remove it or replace it with the intended mixin.
18mixin Spacer { String other() => 'other'; }
19class NoConflict with Greeter, Spacer, Greeter {}
This mixin is already applied without intervening overrides — remove it or replace it with the intended mixin.
20class GreeterBase with Greeter { String other() => 'other'; }
21class NoConflictInherited extends GreeterBase with Greeter {}

Valid

example.dartdart
import 'one.dart' as one;
import 'two.dart' as two;
mixin M {}
mixin N<T> {}
class A with M, N<int> {}
class B with N<int>, N<String> {}
class C with one.M, two.M {}
class D with M {}
class E with M {}
class F = Object with M, N<double>;
enum G with M { value }
class InterfaceOnly implements M {}
class Applied extends InterfaceOnly with M {}
class GenericBase<T> with N<T> {}
class DifferentArguments extends GenericBase<int> with N<String> {}
class UnknownBase extends missing.Base with M {}
class SeparateBase with M {}
class Separate extends SeparateBase with N<int> {}
mixin Greeter { String greet() => 'hi'; }
mixin OtherGreeter { String greet() => 'other'; }
class BaseGreeter with Greeter {}
class Polite extends BaseGreeter { String greet() => 'good day'; }
class Restored extends Polite with Greeter {}
class OwnOverride with Greeter { String greet() => 'good day'; }
class RestoredOwn extends OwnOverride with Greeter {}
class LaterOverride with Greeter, OtherGreeter {}
class RestoredLater extends LaterOverride with Greeter {}
class Reapplied with Greeter, OtherGreeter, Greeter {}
class UnknownBetween with Greeter, missing.Other, Greeter {}
mixin Delegating on Greeter { String greet() => super.greet(); }
class DelegatingBase extends BaseGreeter with Delegating {}
class DelegatingAgain extends DelegatingBase with Delegating {}
class Base { int f() => 0; }
mixin Increment on Base { int f() => super.f() + 1; }
class Twice extends Base with Increment, Increment {}
class TwiceAlias = Base with Increment, Increment;

Configure avoid-duplicate-mixins

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "avoid-duplicate-mixins": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/correctness/avoid-duplicate-mixins: <reason>