public-member-api-docs

Same as public_member_api_docs in Dart lints

Group
Style
Path
lint/style/public-member-api-docs
Default
Off, opt in
Origin
Dart lints
Rule
427 of 512

Documents public declarations and members in package libraries.

Private declarations, top-level functions named main, and overriding members are exempt; like the analyzer, package:meta's @internal exempts a top-level declaration with its members, but not a member on its own. Ordinary constructors of enums and of sealed, abstract final and abstract interface classes are exempt. A doc comment before, between or after the metadata documents the declaration, including the analyzer's empty /**/ documentation. @override alone does not exempt a member. Fields and getters override inherited getters, methods and fields (not setters); setters override inherited setters and are checked only when their paired getter is reported. Extension-type representation fields are not field declarations visited by the upstream rule. A class primary constructor is checked separately from its type; header constructors are reported at their name without closed-type exemptions, and implementations at this. Header parameters are not field declarations. An override exemption requires a combined inherited member, not merely a same-named declaration among incompatible inherited interface signatures.

Invalid

lib/bad.dartdart
import 'package:meta/meta.dart';

class Api {
  Api();
  int field = 0;
  void method() {}
  int get value => 0;
  set value(int v) {}
}
void function() {}
int variable = 0;
typedef Alias = int;
enum Choice {
  one,
  two
}
mixin Features {
  void method() {}
}
extension Named on int {
  int get doubled => this * 2;
}
extension type Wrapper(int value) {
  static void utility() {}
}
int get setting => 0;
set setting(int value) {}
/// Members do not inherit their own `@internal`.
class Internals {
  @internal
  void hidden() {}
}
/// Declares only a setter.
abstract class SetterBase {
  /// Sink.
  set sink(int value);
}
/// A field does not override an inherited setter.
class SetterField extends SetterBase {
  int sink = 0;
}
/// A getter does not override an inherited setter.
class SetterGetter extends SetterBase {
  int get sink => 0;
  set sink(int value) {}
}

/// An annotation alone does not make a member an override.
class NonOverrides {
  @override
  void absent() {}
  @override
  int field = 0;
  @override
  int get value => 0;
  @override
  set value(int next) {}
  @override
  static void utility() {}
}

@override
void annotatedFunction() {}

/* Ordinary block comments are not documentation. */
class PlainComment {}

/// Setter diagnostics retain declaration order even when their getter comes later.
class SetterBeforeGetter {
  set later(int value) {}
  int get later => 0;
}

set laterTopLevel(int value) {}
int get laterTopLevel => 0;
lib/bad.dartAdd documentation for this public member.
2
3class Api {
lib/bad.dartAdd documentation for this public member.
3class Api {
4 Api();
lib/bad.dartAdd documentation for this public member.
4 Api();
5 int field = 0;
lib/bad.dartAdd documentation for this public member.
5 int field = 0;
6 void method() {}
lib/bad.dartAdd documentation for this public member.
6 void method() {}
7 int get value => 0;
lib/bad.dartAdd documentation for this public member.
7 int get value => 0;
8 set value(int v) {}
lib/bad.dartAdd documentation for this public member.
9}
10void function() {}
lib/bad.dartAdd documentation for this public member.
10void function() {}
11int variable = 0;
lib/bad.dartAdd documentation for this public member.
11int variable = 0;
12typedef Alias = int;
lib/bad.dartAdd documentation for this public member.
12typedef Alias = int;
13enum Choice {
lib/bad.dartAdd documentation for this public member.
13enum Choice {
14 one,
lib/bad.dartAdd documentation for this public member.
14 one,
15 two
lib/bad.dartAdd documentation for this public member.
16}
17mixin Features {
lib/bad.dartAdd documentation for this public member.
17mixin Features {
18 void method() {}
lib/bad.dartAdd documentation for this public member.
19}
20extension Named on int {
lib/bad.dartAdd documentation for this public member.
20extension Named on int {
21 int get doubled => this * 2;
lib/bad.dartAdd documentation for this public member.
22}
23extension type Wrapper(int value) {
lib/bad.dartAdd documentation for this public member.
23extension type Wrapper(int value) {
24 static void utility() {}
lib/bad.dartAdd documentation for this public member.
25}
26int get setting => 0;
lib/bad.dartAdd documentation for this public member.
26int get setting => 0;
27set setting(int value) {}
lib/bad.dartAdd documentation for this public member.
30 @internal
31 void hidden() {}
lib/bad.dartAdd documentation for this public member.
39class SetterField extends SetterBase {
40 int sink = 0;
lib/bad.dartAdd documentation for this public member.
43class SetterGetter extends SetterBase {
44 int get sink => 0;
lib/bad.dartAdd documentation for this public member.
50 @override
51 void absent() {}
lib/bad.dartAdd documentation for this public member.
52 @override
53 int field = 0;
lib/bad.dartAdd documentation for this public member.
54 @override
55 int get value => 0;
lib/bad.dartAdd documentation for this public member.
56 @override
57 set value(int next) {}
lib/bad.dartAdd documentation for this public member.
58 @override
59 static void utility() {}
lib/bad.dartAdd documentation for this public member.
62@override
63void annotatedFunction() {}
lib/bad.dartAdd documentation for this public member.
65/* Ordinary block comments are not documentation. */
66class PlainComment {}
lib/bad.dartAdd documentation for this public member.
69class SetterBeforeGetter {
70 set later(int value) {}
lib/bad.dartAdd documentation for this public member.
70 set later(int value) {}
71 int get later => 0;
lib/bad.dartAdd documentation for this public member.
73
74set laterTopLevel(int value) {}
lib/bad.dartAdd documentation for this public member.
74set laterTopLevel(int value) {}
75int get laterTopLevel => 0;

Valid

example.dartdart
// Documentation lints do not apply outside a package lib directory.
class Outside { void method() {} }

Configure public-member-api-docs

Set its severity in falcon.json. See the configuration guide.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "style": {
        "public-member-api-docs": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/style/public-member-api-docs: <reason>