Skip to content

mixin_applied_again

Reports a mixin in a with clause that is already applied below it, where the second application changes nothing. Delete it.

Tier
advisory
Scope
Dart
Lowest preset
recommended
Fix
deletes the mixin, with the with where it is the only one

A mixin in a with clause that is already applied with the same type arguments, by a superclass at any depth or earlier in the same clause, where nothing between the two applications declares a member with the name of one of the mixin’s members. The violation is on the mixin in the clause.

It does not report:

  • a mixin applied again over a class or mixin that overrides one of its members, the class that applied it first included. There the second application puts the mixin’s members back on top, which changes what runs;
  • a mixin that declares an instance field with an initializer, which would run again for the second copy of the field;
  • a mixin that a superclass only implements.

The fix deletes the mixin, with the with where it is the only one. It is not offered for the only mixin of a class alias (class A = B with M; cannot lose its clause), or where a comment stands in what it would delete.

Applying a mixin a second time, over nothing that overrode it, adds the same members at the same place in the chain: the class behaves as it would without it. A reader still has to check the whole chain to see that.

Violating
mixin Logging {}
class Base with Logging {}
class Panel extends Base with Logging {}
Corrected
mixin Logging {}
class Base with Logging {}
class Panel extends Base {}

Set under the assay: key of the project’s root analysis_options.yaml.

Rule parameter Default Effect
enabled true false switches the rule off for the whole project.
exclude [] Path globs where the rule is silent.

Write why on the line directly above the suppression:

// Why it stays as written here.
// ignore: mixin_applied_again

// ignore_for_file: assay/mixin_applied_again silences it in a whole file, and the prefixed // ignore: assay/mixin_applied_again works too. See Suppressions.