library-private-types-in-public-api
Same as library_private_types_in_public_api in Dart lints
- Group
- Correctness
- Path
lint/correctness/library-private-types-in-public-api- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 254 of 512
Avoid using library-private types in public APIs.
Checks the types a public declaration exposes: type-parameter bounds,
signatures, field and top-level variable types, extension on types, mixin
on constraints, extension-type representations and function-type
aliases. Like the analyzer, supertypes (extends, with, implements),
non-function type aliases and record type annotations are not checked, and
constructors of enums and of sealed, abstract final, abstract interface
or @internal classes are exempt. Untyped initializing and super formals
use their resolved semantic types, including declarations in part files.
Invalid
class _Private {}
_Private topLevel(_Private value) => value;
_Private publicVariable = _Private();
typedef PublicFunction = _Private Function(_Private);
class PublicClass<T extends _Private> {
_Private field;
PublicClass(this.field);
_Private method(_Private value) => value;
_Private get getter => field;
set setter(_Private value) => field = value;
}
mixin PublicMixin on _Private {
_Private operator +(covariant _Private other) => other;
}
extension PublicExtension on _Private {}
extension type PublicExtensionType(_Private value) {}
class PublicConstructors {
PublicConstructors(_Private value);
} _Private topLevel(_Private value) => value; _Private topLevel(_Private value) => value; _Private publicVariable = _Private(); typedef PublicFunction = _Private Function(_Private); typedef PublicFunction = _Private Function(_Private); class PublicClass<T extends _Private> {class PublicClass<T extends _Private> { _Private field; _Private field; PublicClass(this.field); PublicClass(this.field); _Private method(_Private value) => value; PublicClass(this.field); _Private method(_Private value) => value; _Private method(_Private value) => value; _Private get getter => field; _Private get getter => field; set setter(_Private value) => field = value; mixin PublicMixin on _Private {mixin PublicMixin on _Private { _Private operator +(covariant _Private other) => other;mixin PublicMixin on _Private { _Private operator +(covariant _Private other) => other; extension PublicExtension on _Private {} extension type PublicExtensionType(_Private value) {}class PublicConstructors { PublicConstructors(_Private value);Valid
class _Private {
_Private field;
_Private(this.field);
_Private method(_Private value) => value;
}
_Private _privateFunction(_Private value) => value;
_Private _privateVariable = _Private(_Private(_Private(null as dynamic)));
typedef _PrivateAlias = _Private Function(_Private);
class PublicClass {
String field;
PublicClass(this.field);
String method(String value) => value;
_Private _privateMethod(_Private value) => value;
}
typedef PublicAlias = ({String value, void Function(String) callback});
extension PublicExtension on String {}
extension on _Private {}
extension type PublicExtensionType._(_Private _value) {}
enum PublicEnum {
value._(null);
const PublicEnum._(_Private? value);
}
void publicNamedParameter({String? value}) {}
void _privateNamedParameter({_Private? value}) {}
// Supertypes are not public API to the analyzer.
class _Base {}
mixin _Mixin {}
abstract class _Marker {}
class PublicSubclass extends _Base with _Mixin implements _Marker {}
// Non-function aliases and record types are not checked.
typedef PublicRecordAlias = ({_Private value, void Function(_Private) callback});
typedef PublicClassAlias = _Private;
({_Private value}) publicRecord() => (value: _Private(null as dynamic));
// Constructors of effectively private classes are exempt.
sealed class PublicSealed {
PublicSealed(_Private value);
}
abstract final class PublicAbstractFinal {
PublicAbstractFinal(_Private value);
}
abstract interface class PublicAbstractInterface {
PublicAbstractInterface(_Private value);
}Configure library-private-types-in-public-api
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"library-private-types-in-public-api": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/library-private-types-in-public-api: <reason>More correctness rules
- list-all-equatable-fieldsrecommendedequatable
Flags declared instance fields omitted from a statically understood Equatable props list.
- literal-only-boolean-expressions
literal_only_boolean_expressionsrecommendedFlags conditions built only from literals, whose value never changes.
- match-getter-setter-field-names
Detect likely copy-paste errors in trivial accessors when a different field matching the accessor name is declared.
- missing-test-assertionrecommendedtest
Reports inline test callbacks that contain no recognized assertion calls.
- no-adjacent-strings-in-list
no_adjacent_strings_in_listrecommendedFlags adjacent string literals used as an element of a list or set literal.
- no-import-cyclescross-file
Report mutually dependent components of imported or exported library files.
- no-logic-in-create-state
no_logic_in_create_staterecommendedflutterRequire
StatefulWidget.createStateto return only a fresh zero-argument FlutterStateconstruction. - no-self-assignments
no_self_assignmentsrecommendedFlags assignments of a variable to itself, such as
x = x;.