library_private_types_in_public_api
Avoid using private types in public APIs.
This rule is available as of Dart 2.14.
Rule sets: recommended, flutter
Details
#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) { ... }
Usage
#To enable the library_private_types_in_public_api
rule,
add library_private_types_in_public_api
under linter > rules in your
analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- library_private_types_in_public_api
除非另有说明,文档之所提及适用于 Dart 3.5.4 版本,本页面最后更新时间: 2024-08-02。 查看文档源码 或者 报告页面问题。