avoid-banned-imports
added in: 4.16.0
warning
Configure some imports that you want to ban.
Example
With the configuration in the example below, here are some bad/good examples.
❌ Bad:
import "package:flutter/material.dart";
import "package:flutter_bloc/flutter_bloc.dart";
✅ Good:
// No restricted imports in listed folders.
⚙️ Config example
The paths
and deny
both support regular expressions.
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!"
- paths: ["core/.*\.dart"]
deny: ["package:flutter_bloc/flutter_bloc.dart"]
message: 'State management should be not used inside "core" folder.'