目录

prefer_mixin

Prefer using mixins.

此规则自 Dart 2.1 版本起可用。

详情

#

Dart 2.1 introduced a new syntax for mixins that provides a safe way for a mixin to invoke inherited members using super. The new style of mixins should always be used for types that are to be mixed in. As a result, this lint will flag any uses of a class in a with clause.

BAD:

dart
class A {}
class B extends Object with A {}

OK:

dart
mixin M {}
class C with M {}

使用方法

#

要启用 prefer_mixin 规则,请在你的 analysis_options.yaml 文件中,在 linter > rules 下添加 prefer_mixin

analysis_options.yaml
yaml
linter:
  rules:
    - prefer_mixin