avoid-banned-annotations
Warns against using banned annotations.
This rule requires configuration in order to highlight any issues.
⚙️ Config
Set entries
(default is empty) to configure the list of entries to ban.
Each entry is an object with 4 fields: paths
, annotations
, message
and severity
.
Set paths
(can be a regular expression) to configure the list of paths the entry will apply to.
Set annotations
(can be a regular expression) to configure the list of annotations to ban.
Set message
to configure a user-facing message for each issue created from this config entry.
Set severity
(optional) to override default severity for the given entry.
dart_code_metrics:
...
rules:
...
- avoid-banned-annotations:
entries:
- paths: ['some/folder/.*\.dart', 'another/folder/.*\.dart']
annotations: ['visibleForTesting']
message: 'Do not use visibleForTesting here.'
severity: error
By default, the 'visibleForTesting' RegExp will match any annotation name containing this string. For exact matches, use ^
and $
.
For Windows devices, ensure that the paths
config works with Windows path separators.
Example
❌ Bad:
// LINT
class Person {
Person({
required this.value,
this.another,
});
final int value;
final int? another;
// LINT
void method() {}
}
✅ Good:
class Person {
Person({
required this.value,
this.another,
});
final int value;
final int? another;
void method() {}
}