prefer-getter-over-method
Suggests to convert a method that has no parameters and side-effects to a getter.
⚙️ Config
Set ignored-names
(default is none) to ignore specific names.
dart_code_metrics:
...
rules:
...
- prefer-getter-over-method:
ignored-names:
- methodName
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('-', '');
String toValue() => this;
}