Skip to main content

avoid-getter-prefix

added in: 1.22.0
⚙️
Pro+

Warns when a getter name starts from a banned prefix.

note

This rule requires configuration in order to highlight any issues.

⚙️ Config

Set prefix (default is empty) to configure a regular expression for the not allowed prefix.

analysis_options.yaml
dart_code_metrics:
rules:
- avoid-getter-prefix:
prefix: '^get'

Example

❌ Bad:

abstract class ModalRoute {
// LINT: This name matches the configured prefix (^get) and is therefore not allowed. Try renaming this getter.
bool get getBarrierDismissible;
}

class Some implements ModalRoute {

bool get getBarrierDismissible => false;
}

✅ Good:

abstract class ModalRoute {
bool get isBarrierDismissible; // Correct, does not start with '^get'
}

class Some implements ModalRoute {

bool get isBarrierDismissible => false;
}