Setting Up Custom Lint Rules
What you'll learn
- Generating a custom lint rules package for your project
- Understanding how the Dart analyzer plugin system works
- Enforcing architecture conventions automatically
- Adding project-specific lint rules
Prerequisites
- An existing Archipelago monorepo (see Monorepo Scaffolding)
- Familiarity with Dart analysis options
Step 1: Generate the Lint Package
bash
archipelago generate app_lintsYou will be prompted for:
- appName —
MyApp(must match your monorepo app name) - isForMonorepo —
true
Or use a config file:
json
{
"appName": "MyApp",
"isForMonorepo": true
}bash
archipelago generate app_lints --config lints_config.jsonStep 2: Understand the Generated Structure
The brick generates a Dart package with custom analysis rules:
packages/
└── my_app_lints/
├── lib/
│ ├── my_app_lints.dart # Package exports
│ └── src/
│ ├── analysis_options.yaml # Base analysis options
│ ├── rules/
│ │ ├── avoid_print_rule.dart # Example custom rule
│ │ └── feature_import_rule.dart # Architecture enforcement
│ └── all_rules.dart # Rule registry
├── pubspec.yaml
└── README.mdStep 3: Apply Lints to Your Packages
Include the lint package in each package's analysis_options.yaml:
yaml
# In any package's analysis_options.yaml
include: package:my_app_lints/analysis_options.yamlAdd it as a dev dependency:
yaml
# pubspec.yaml
dev_dependencies:
my_app_lints:
path: ../../packages/my_app_lintsStep 4: Add Custom Rules
Create rules that enforce your project's architecture conventions:
dart
// lib/src/rules/feature_import_rule.dart
// Prevents features from importing other feature implementations directly
// Features should only depend on _api packages, never _impl
class FeatureImportRule extends LintRule {
@override
void check(Source source) {
// Flag imports like: import 'package:auth_sdk_impl/...'
// from within another feature's code
}
}Key Customization Points
| Customization | Where to Change |
|---|---|
| Add new lint rules | lib/src/rules/ — create new rule classes |
| Adjust severity levels | analysis_options.yaml — set info, warning, error |
| Exclude files from rules | analysis_options.yaml — add to exclude list |
| Enforce naming conventions | Add a naming rule in rules/ |
Next Steps
- Set up coverage management to enforce test coverage alongside lint rules
- Generate the core infrastructure with lints pre-configured