A custom lint rules package for the Feature Sliced Design (FSD) architecture.
Purpose: Enforce the FSD layer hierarchy.
Rule:
- Upper layers can only import from lower layers.
- An error occurs if a lower layer attempts to import from an upper layer.
Layer Hierarchy (Top → Bottom):
app > pages > widgets > features > entities > shared
Examples:
// ✅ Allowed: 'pages' imports from 'entities' (lower layer)
// lib/pages/server_list/server_list.dart
import 'package:example/entities/server/server.dart';
// ❌ Error: 'entities' imports from 'pages' (upper layer)
// lib/entities/server/server.dart
import 'package:example/pages/server_list/server_list.dart';Purpose: Prevent direct dependencies between slices within the same layer.
Rule:
- Direct imports between different slices in the same layer are not allowed.
Example:
// ❌ Error: Direct import of another slice within the 'features' layer
// lib/features/server_add/server_add.dart
import 'package:example/features/server_list/server_list.dart';your_project/
├── lib/
│ ├── app/
│ ├── pages/
│ ├── widgets/
│ ├── features/
│ ├── entities/
│ └── shared/
├── analysis_options.yaml
└── pubspec.yaml
Add to your main project's pubspec.yaml:
dev_dependencies:
custom_lint: ^0.8.1
fsd_lint: ^0.1.0analyzer:
plugins:
- custom_lintflutter pub get# Run all lint rules
dart run custom_lint
# Run in watch mode (auto-refresh on file changes)
dart run custom_lint --watchMost IDEs (VS Code, Android Studio, etc.) will automatically recognize custom_lint configured in analysis_options.yaml and display lint warnings/errors in real-time.
- app: App-wide settings (routing, themes, etc.)
- pages: Full screens/pages
- widgets: Reusable UI components
- features: Business logic units
- entities: Business entities/models
- shared: Shared utilities, API clients, etc.
- Downward Dependencies Only: Upper layer → Lower layer
- Isolation within Layers: Slices within the same layer should not depend on each other directly.
- Create a new lint file in the
lib/src/lints/directory. - Write a class inheriting from
DartLintRule. - Add it to
getLintRulesinlib/fsd_lint.dart.
MIT