library_private_types_in_public_api
Avoid using private types in public APIs.
此规则自 Dart 2.14 版本起可用。
_规则集:recommended , flutter _
详情
#AVOID using library private types in public APIs.
For the purposes of this lint, a public API is considered to be any top-level or member declaration unless the declaration is library private or contained in a declaration that's library private. The following uses of types are checked:
- the return type of a function or method,
- the type of any parameter of a function or method,
- the bound of a type parameter to any function, method, class, mixin, extension's extended type, or type alias,
- the type of any top level variable or field,
- any type used in the declaration of a type alias (for example
typedef F = _Private Function();
), or - any type used in the
on
clause of an extension or a mixin
BAD:
dart
f(_Private p) { ... }
class _Private {}
GOOD:
dart
f(String s) { ... }
使用方法
#要启用 library_private_types_in_public_api
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 library_private_types_in_public_api
:
analysis_options.yaml
yaml
linter:
rules:
- library_private_types_in_public_api
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.