Skip to main content

avoid-banned-types

added in: 1.4.0
warning
⚙️

Configure types that you want to ban.

⚙️ Config

Set entries (default is empty) to configure a list of entries for types to ban.

Each entry is an object with 3 fields: paths, types and message.

Set paths (can be a regular expression) to configure the list of paths for entry to trigger on.

Set types (can be a regular expression) to configure the list of types to ban.

Set message to configure a user-facing message for each issue created from this config entry.

dart_code_metrics:
...
rules:
...
- avoid-banned-types:
entries:
- paths: ['some/folder/.*\.dart', 'another/folder/.*\.dart']
types: ['SomeType']
message: 'Do not use SomeType here.'
- paths: ['core/.*\.dart']
types: ['CounterBloc']
message: 'State management should be not used inside "core" folder.'
note

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

note

This rule requires configuration in order to highlight any issues.

Example

❌ Bad:

void function(SomeType someParam) { // LINT
// ...
}

if (value case SomeType(: final field)) { // LINT
// ..
}

✅ Good:

void function(SomeOtherType someParam) {
// ...
}

if (value case SomeOtherType(: final field)) {
// ..
}