Skip to content

ryota-kishimoto/import_guard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 

Repository files navigation

import_guard

CI License: MIT

Import restriction analyzer for Dart/Flutter projects

Enforce clean architecture layer dependencies with configurable deny/allow rules per folder.

Packages

Package Description Version
import_guard Analyzer plugin (Dart 3.10+) pub package
import_guard_custom_lint custom_lint integration (Dart 3.6+) pub package

Which package should I use?

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

Quick Start

1. Install

For Dart 3.10+:

# pubspec.yaml
dev_dependencies:
  import_guard: ^0.0.6
# analysis_options.yaml
analyzer:
  plugins:
    - import_guard

For 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_lint

2. Configure

Create import_guard.yaml in any directory:

# lib/domain/import_guard.yaml
deny:
  - package:my_app/presentation/**
  - package:my_app/data/**

3. Run

# import_guard
dart analyze

# import_guard_custom_lint
dart run custom_lint

Example: Clean Architecture

my_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)

Architecture

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.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages