avoid-nested-extension-types
Warns when the representation field of an extension type is also an extension type.
Since there are no restrictions on extension types that can be created from other extension types, this rule helps avoid deep nesting that can lead to reduced maintainability.
⚙️ Config
Set acceptable-level
(default is 2
) to configure the acceptable nesting level.
analysis_options.yaml
dart_code_metrics:
rules:
- avoid-nested-extension-types:
acceptable-level: 2
Example
❌ Bad:
extension type ET1(String s) {}
extension type ET2(ET1 inner) {}
// LINT: Avoid nested extension types. Try rewriting the code to reduce nesting.
extension type ET3(ET2 inner) {}
✅ Good:
extension type ET1(String s) {}
extension type ET2(ET1 inner) {}