avoid-banned-imports
Configure some imports that you want to ban.
This rule requires configuration in order to highlight any issues.
⚙️ Config
Set entries
(default is empty) to configure a list of entries for imports to ban.
Each entry is an object with 4 fields: paths
, deny
, message
and severity
.
Set paths
(can be a regular expression) to configure the list of paths for entry to trigger on.
Set deny
(can be a regular expression) to configure the list of imports 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-imports:
entries:
- paths: ['some/folder/.*\.dart', 'another/folder/.*\.dart']
deny: ['package:flutter/material.dart']
message: 'Do not import Flutter Material Design library, we should not depend on it!'
severity: error
- paths: ['core/.*\.dart']
deny: ['package:flutter_bloc/flutter_bloc.dart']
message: 'State management should be not used inside "core" folder.'
For Windows devices, ensure that the paths
config works with Windows path separators.
Example
With the configuration in the example above, here are some bad/good examples.
❌ Bad:
import "package:flutter/material.dart"; // LINT
import "package:flutter_bloc/flutter_bloc.dart"; // LINT
✅ Good:
// No restricted imports in listed folders.