Why this matters
If a class only contains static members, it should be converted into a top-level utility function or extension. This reduces unnecessary class instantiation and improves efficiency.
Ensure that classes with only static members are converted to top-level functions or extensions. Avoid unnecessary class instantiation.
If a class only contains static members, it should be converted into a top-level utility function or extension. This reduces unnecessary class instantiation and improves efficiency.
Side-by-side examples engineers can pattern-match during review.
class DateUtils {
static DateTime mostRecent(List<DateTime> dates) {
return dates.reduce((a, b) => a.isAfter(b) ? a : b);
}
}
class _Favorites {
static const mammal = 'weasel';
}DateTime mostRecent(List<DateTime> dates) {
return dates.reduce((a, b) => a.isAfter(b) ? a : b);
}
const _favoriteMammal = 'weasel';class DateUtils {
static DateTime mostRecent(List<DateTime> dates) {
return dates.reduce((a, b) => a.isAfter(b) ? a : b);
}
}
class _Favorites {
static const mammal = 'weasel';
}DateTime mostRecent(List<DateTime> dates) {
return dates.reduce((a, b) => a.isAfter(b) ? a : b);
}
const _favoriteMammal = 'weasel';From the same buckets as this rule.