barrel_file_lints 1.0.5 copy "barrel_file_lints: ^1.0.5" to clipboard
barrel_file_lints: ^1.0.5 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/example.md

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

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';

Note: For detecting circular dependencies between barrel files, use the CLI tool:

dart run barrel_file_lints:check_cycles

This detects both immediate (A ↔ B) and transitive cycles (A → B → C → A).

Bad: Improper layer import #

// lib/feature_profile/data/profile_repository.dart

// ❌ This will trigger avoid_improper_layer_import
// (if feature_settings/settings.dart exports UI layer)
import 'package:myapp/feature_settings/settings.dart';

class ProfileRepository {
  // Data layer should not depend on UI layer
}

Good: Layer-specific barrel import #

// lib/feature_profile/data/profile_repository.dart

// ✅ Use layer-specific barrel
import 'package:myapp/feature_settings/settings_data.dart';

class ProfileRepository {
  // Only imports data layer
}

Bad: Flutter in domain layer #

// lib/feature_auth/domain/use_cases/login_use_case.dart

// ❌ This will trigger avoid_ui_framework_in_logic
import 'package:flutter/material.dart';

class LoginUseCase {
  // Domain layer should be framework-agnostic
}

Good: Framework-agnostic domain #

// lib/feature_auth/domain/use_cases/login_use_case.dart

import 'dart:async';
import '../repositories/auth_repository.dart';

// ✅ Pure Dart, no Flutter dependencies
class LoginUseCase {
  final AuthRepository _repository;
  
  LoginUseCase(this._repository);
  
  Future<void> execute(String email, String password) async {
    // Business logic only
  }
}

4. Run analysis #

dart analyze
# or
flutter analyze
0
likes
150
points
233
downloads

Publisher

verified publisherteklund.dev

Weekly Downloads

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.

Repository (GitHub)
View/report issues
Contributing

Topics

#linter #analyzer #flutter #architecture #clean-architecture

Documentation

API reference

License

MIT (license)

Dependencies

analysis_server_plugin, analyzer, analyzer_plugin, args, path

More

Packages that depend on barrel_file_lints