implicit_reopen
Don't implicitly reopen classes.
此规则目前处于 experimental 状态,自 Dart 3.0 版本起可用。
此规则提供 快速修复 。
详情
#Using an interface
, base
, final
, or sealed
modifier on a class, or a base
modifier on a mixin, authors can control whether classes and mixins allow being implemented, extended, and/or mixed in from outside of the library where they're defined. In some cases, it's possible for an author to inadvertently relax these controls and implicitly "reopen" a class. (A similar reopening cannot occur with a mixin.)
This lint guards against unintentionally reopening a class by requiring such cases to be made explicit with the @reopen
annotation in package:meta
.
BAD:
interface class I {}
class C extends I {} // LINT
GOOD:
interface class I {}
final class C extends I {}
import 'package:meta/meta.dart';
interface class I {}
@reopen
class C extends I {}
使用方法
#要启用 implicit_reopen
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 implicit_reopen
:
linter:
rules:
- implicit_reopen
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.