Skip to main content

prefer-private-extension-type-field

dart 3.3+
has auto-fix
pro+

Warns when an extension type has a public representation field.

Public representation fields can be accessed directly, which may lead to potential mistakes. Consider exposing only the required properties or methods.

Example

❌ Bad:

// LINT: Avoid exposing the representation field. Try making it private.
extension type ET(String value) {}

✅ Good:

extension type ET(String _value) {
bool get isCorrect => _value.isNotEmpty;
}