Skip to main content

avoid-extensions-on-records

added in: 1.10.0
Dart 3.0+
Pro+

Warns when an extension is declared on a record type.

Creating an extension on a record type will make that extension available for every record with the same form (e.g. (String, String)), which can lead to unexpected results. Also, since extensions are used to add additional behavior to external objects, and the primary purpose of records is to group data (not behavior), it's recommended to create a dedicated class instead.

Example

❌ Bad:

typedef Record = (String, String);

// LINT: Avoid declaring extensions on record types. Try declaring a class instead.
extension Extension on (String, String) {}

// LINT: Avoid declaring extensions on record types. Try declaring a class instead.
extension RecordX on Record {}

✅ Good:

class InsteadOfExtension {
// ...
}

Additional Resources