跳到主要内容

provide_deprecation_message

稳定版
核心

通过 @Deprecated("message") 提供弃用消息。

详情

#

务必Deprecated 构造函数中指定弃用消息(包含迁移说明和/或移除时间表)。

错误示例

dart
@deprecated
void oldFunction(arg1, arg2) {}

良好示例

dart
@Deprecated("""
[oldFunction] is being deprecated in favor of [newFunction] (with slightly
different parameters; see [newFunction] for more information). [oldFunction]
will be removed on or after the 4.0.0 release.
""")
void oldFunction(arg1, arg2) {}

启用

#

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

analysis_options.yaml
yaml
linter:
  rules:
    - provide_deprecation_message

如果您改为使用 YAML 映射语法配置 linter 规则,请在 linter > rules 下添加 provide_deprecation_message: true

analysis_options.yaml
yaml
linter:
  rules:
    provide_deprecation_message: true