Import restriction analyzer for Dart/Flutter projects
Enforce clean architecture layer dependencies with configurable deny/allow rules per folder.
| Package | Description | Version |
|---|---|---|
| import_guard | Analyzer plugin (Dart 3.10+) | |
| import_guard_custom_lint | custom_lint integration (Dart 3.6+) |
| Your environment | Recommended |
|---|---|
| Dart 3.10+ | import_guard - Native analyzer plugin, better IDE integration |
| Dart 3.6 - 3.9 | import_guard_custom_lint - Works with older Dart versions |
| Using custom_lint ecosystem | import_guard_custom_lint |
For Dart 3.10+:
# pubspec.yaml
dev_dependencies:
import_guard: ^0.0.6# analysis_options.yaml
analyzer:
plugins:
- import_guardFor Dart 3.6+:
# pubspec.yaml
dev_dependencies:
import_guard_custom_lint: ^0.0.8
custom_lint: ^0.7.0# analysis_options.yaml
analyzer:
plugins:
- custom_lintCreate import_guard.yaml in any directory:
# lib/domain/import_guard.yaml
deny:
- package:my_app/presentation/**
- package:my_app/data/**# import_guard
dart analyze
# import_guard_custom_lint
dart run custom_lintmy_app/
├── lib/
│ ├── domain/
│ │ ├── import_guard.yaml # Deny presentation & data
│ │ └── user.dart
│ ├── presentation/
│ │ ├── import_guard.yaml # Deny data (can use domain)
│ │ └── user_page.dart
│ └── data/
│ ├── import_guard.yaml # Can use domain
│ └── user_repository.dart
# lib/domain/import_guard.yaml
deny:
- package:my_app/presentation/**
- package:my_app/data/**
# lib/presentation/import_guard.yaml
deny:
- package:my_app/data/**
# lib/data/import_guard.yaml
# (no restrictions - can import domain)packages/
├── import_guard/ # Analyzer plugin implementation
│ └── lib/src/core/ # Shared core logic
└── import_guard_custom_lint/ # custom_lint implementation
└── lib/src/core/ # Shared core logic (synced)
Both packages share the same core logic for config loading and pattern matching.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'feat: add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT