Skip to main content

prefer-getter-over-method

added in: 1.9.0
style

Suggests to convert a method that has no parameters and side-effects to a getter.

Example

❌ Bad:

extension StringExtension on String {
// LINT
String useCorrectEllipsis() {
return replaceAll('', '\u200B');
}

String removeSpaces() => replaceAll(' ', ''); // LINT

String removeHyphens() => replaceAll('-', ''); // LINT
}

✅ Good:

extension StringExtension on String {
String get useCorrectEllipsis => replaceAll('', '\u200B');

String get removeSpaces => replaceAll(' ', '');

String get removeHyphens => replaceAll('-', '');
}