barrel_file_lints 1.0.4
barrel_file_lints: ^1.0.4 copied to clipboard
A Dart 3.10+ analyzer plugin that enforces barrel file import rules for feature-based Flutter architecture. Supports both feature_xxx/ and features/xxx/ naming conventions.
Example Usage #
1. Add to your project #
# pubspec.yaml
dev_dependencies:
barrel_file_lints: ^1.0.0
2. Configure analysis_options.yaml #
plugins:
barrel_file_lints:
diagnostics:
avoid_internal_feature_imports: true
avoid_core_importing_features: true
avoid_self_barrel_import: true
avoid_cross_feature_barrel_exports: true
avoid_barrel_cycle: true
3. Example violations #
Bad: Internal feature import #
// lib/feature_home/ui/home_page.dart
// ❌ This will trigger avoid_internal_feature_imports
import 'package:myapp/feature_auth/data/auth_service.dart';
class HomePage extends StatelessWidget {
// ...
}
Good: Barrel file import #
// lib/feature_home/ui/home_page.dart
// ✅ Import via barrel file
import 'package:myapp/feature_auth/auth.dart';
class HomePage extends StatelessWidget {
// ...
}
Bad: Core importing feature #
// lib/core/network/api_client.dart
// ❌ This will trigger avoid_core_importing_features
import 'package:myapp/feature_auth/auth.dart';
class ApiClient {
// ...
}
Bad: Importing own barrel #
// lib/feature_auth/data/auth_service.dart
// ❌ This will trigger avoid_self_barrel_import
import 'package:myapp/feature_auth/auth.dart';
class AuthService {
// ...
}
Bad: Cross-feature barrel export #
// lib/feature_auth/auth.dart (barrel file)
export 'data/auth_service.dart';
// ❌ This will trigger avoid_cross_feature_barrel_exports
export '../feature_profile/data/user.dart';
Bad: Barrel cycle #
// lib/feature_auth/auth.dart
// ❌ This will trigger avoid_barrel_cycle
export '../feature_profile/profile.dart';
// lib/feature_profile/profile.dart
// ❌ Creates a cycle back to auth
export '../feature_auth/auth.dart';
4. Run analysis #
dart analyze
# or
flutter analyze