目录

package_api_docs

Provide doc comments for all public APIs.

此规则目前处于 deprecated 状态,自 Dart 2.0 版本起可用。

详情

#

NOTE: This lint is deprecated because it is has not been fully functional since at least Dart 2.0. Remove all inclusions of this lint from your analysis options.

DO provide doc comments for all public APIs.

As described in the pub package layout doc, public APIs consist in everything in your package's lib folder, minus implementation files in lib/src, adding elements explicitly exported with an export directive.

For example, given lib/foo.dart:

dart
export 'src/bar.dart' show Bar;
export 'src/baz.dart';

class Foo { }

class _Foo { }

its API includes:

  • Foo (but not _Foo)
  • Bar (exported) and
  • all public elements in src/baz.dart

All public API members should be documented with /// doc-style comments.

BAD:

dart
class Bar {
  void bar();
}

GOOD:

dart
/// A Foo.
abstract class Foo {
  /// Start foo-ing.
  void start() => _start();

  _start();
}

Advice for writing good doc comments can be found in the Doc Writing Guidelines.

使用方法

#

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

analysis_options.yaml
yaml
linter:
  rules:
    - package_api_docs