LeanCode Lint
An opinionated set of high-quality, robust, and up-to-date lint rules used at LeanCode. This package provides custom lint rules, assists, and a comprehensive analyzer configuration for Flutter and Dart projects.Installation
Configure analysis_options.yaml
Include the package in your
analysis_options.yaml and enable the analyzer plugin:analysis_options.yaml
For library packages (rather than applications), use
package:leancode_lint/analysis_options_package.yaml instead to expose public API documentation requirements.Configuration
Default Configuration
By default,leancode_lint uses LeanCodeLintConfig() with sensible defaults. Simply enable the plugin in analysis_options.yaml to use it as-is.
Custom Configuration
To customize rule behavior, create your own analyzer plugin package that depends onleancode_lint:
Custom Lint Rules
leancode_lint includes 16 custom lint rules to enforce best practices:
add_cubit_suffix_for_your_cubits
add_cubit_suffix_for_your_cubits
DO add a ‘Cubit’ suffix to your cubit names.Bad:Good:Configuration: None.
avoid_conditional_hooks
avoid_conditional_hooks
AVOID using hooks conditionally. Hooks must be called in the same order on every build.Bad:Good:Configuration: None.
bloc_related_class_naming
bloc_related_class_naming
catch_parameter_names
catch_parameter_names
DO name catch clause parameters consistently.Good:Configuration:
- For catch-all: exception should be named
errand stacktracest - For typed catch: stacktrace must be named
st
hook_widget_does_not_use_hooks
hook_widget_does_not_use_hooks
AVOID extending Good:Configuration: None.
HookWidget if no hooks are used.Bad:prefix_widgets_returning_slivers
prefix_widgets_returning_slivers
DO prefix widget names with ‘Sliver’ if the widget returns slivers.Bad:Good:Configuration:This allows
LncdSliverMyWidget as a valid name.start_comments_with_space
start_comments_with_space
DO start comments/docs with an empty space.Bad:Good:Configuration: None.
use_design_system_item
use_design_system_item
AVOID using items disallowed by the design system.This rule highlights forbidden usages and suggests alternatives preferred by the design system.Configuration:
avoid_single_child_in_multi_child_widgets
avoid_single_child_in_multi_child_widgets
AVOID using Good:Configuration: None.
Column, Row, Flex, Wrap, SliverList, MultiSliver, etc. with a single child.Bad:use_dedicated_media_query_methods
use_dedicated_media_query_methods
AVOID using Good:Configuration: None.
MediaQuery.of or MediaQuery.maybeOf to access only one property.Dedicated methods offer better performance by minimizing unnecessary widget rebuilds.Bad:use_align
use_align
DO use the Align widget instead of the Container widget with only the alignment parameter.Bad:Good:Configuration: None.
use_padding
use_padding
DO use Padding widget instead of the Container widget with only the margin parameter.Bad:Good:Configuration: None.
prefer_center_over_align
prefer_center_over_align
DO use the Center widget instead of the Align widget with alignment set to Alignment.center.Bad:Good:Configuration: None.
prefer_equatable_mixin
prefer_equatable_mixin
DO mix in Good:Configuration: None.
EquatableMixin instead of extending Equatable.Bad:Assists
Assists are IDE refactorings that can be triggered by placing your cursor over relevant code and opening the code actions dialog (e.g.,Ctrl+. or ⌘+. in VS Code).
Convert positional to named formal
Convert positional to named formal
Converts required positional parameters to named ones.Before:After applying to
pos0:Convert record into nominal type
Convert record into nominal type
Converts Dart records into named classes for better type safety and maintainability.
Convert iterable map to collection-for
Convert iterable map to collection-for
Converts
iterable.map(...).toList() patterns into more readable collection-for syntax.Disabling Rules
To disable a particular custom lint rule, set it tofalse in analysis_options.yaml:
Additional Features
Comprehensive Linter Configuration
The package includes
analysis_options.yaml with 200+ carefully selected and configured lint rules covering:- Strict type checking (strict-casts, strict-inference, strict-raw-types)
- Flutter best practices
- Performance optimizations
- Code style consistency
Library Package Support
Use
analysis_options_package.yaml for library projects to enable public API documentation requirements and other library-specific rules.Package Information
- Latest Version: 21.0.0+1
- Minimum Dart SDK: 3.11.0
- Repository: GitHub
- Pub.dev: leancode_lint
