feature_envy
Warns if a method accesses fields or methods from a different class more often than from its own class (feature envy).
Example
BAD:
class A {
int field;
A(this.field);
}
class B {
int method(A a) => a.field * a.field; // LINT
}
GOOD:
class A {
int field;
A(this.field);
int method() => field * field;
}
class B {
int method(A a) => a.method();
}
Detection Algorithm
The rule detects feature envy using three metrics:
- ATFD (Access to Foreign Data): Accesses to members of a single external class. Triggers if ATFD >= threshold (default 4).
- LAA (Locality of Attribute Access): The ratio of internal accesses to total accesses. Triggers if LAA < threshold (default 0.33).
- FDP (Foreign Data Providers): The number of unique external classes accessed. Triggers if FDP <= threshold (default 2).
Accesses to other instances of the same class, non-project classes, closures, nested functions, and data classes are ignored.
Parameters
exclude (String | Map | List<String | Map>)
A list of methods that should be excluded from the lint.
atfd_threshold (int)
Access to Foreign Data (ATFD) threshold. Triggered if ATFD >= atfdThreshold.
laa_threshold (double)
Locality of Attribute Access (LAA) threshold. Triggered if LAA < laaThreshold.
fdp_threshold (int)
Foreign Data Providers (FDP) threshold. Triggered only if FDP <= fdpThreshold.