Skip to main content

avoid-banned-annotations

added in: 1.11.0
⚙️🛠

Configure annotations that you want to ban.

note

This rule requires configuration in order to highlight any issues.

⚙️ Config

Set entries (default is empty) to configure a 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 for entry to trigger on.

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 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
note

By default, the 'visibleForTesting' RegExp will match any annotation name containing this string. For exact matches, use ^ and $.

warning

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() {}
}